src/Entity/Award.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  9. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  10. use App\Repository\AwardRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Mapping\Annotation as Gedmo;
  15. use Symfony\Component\HttpFoundation\File\UploadedFile;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * @ORM\Entity(repositoryClass=AwardRepository::class)
  20.  * @ApiResource(
  21.  *     normalizationContext={
  22.  *         "groups"={"award:read"}
  23.  *     },
  24.  *     denormalizationContext={
  25.  *          "groups"={"award:write"}
  26.  *     },
  27.  *     collectionOperations={
  28.  *          "get"={"security"="is_granted('ROLE_USER')"},
  29.  *          "post"={"security"="is_granted('ROLE_ADMIN')"}
  30.  *     },
  31.  *     itemOperations={
  32.  *          "get"={"security"="is_granted('ROLE_USER')"},
  33.  *          "patch"={"security"="is_granted('ROLE_ADMIN')"},
  34.  *          "patch_award"={
  35.  *                  "method"="PATCH",
  36.  *                  "security"="is_granted('ROLE_ADMIN')",
  37.  *                  "path"="/custom/awards/{id}",
  38.  *                  "controller"="App\Controller\Api\AwardController::patchAward",
  39.  *                  "input_formats"={"json"={"application/merge-patch+json"}}
  40.  *          },
  41.  *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
  42.  *     }
  43.  * )
  44.  * @ApiFilter(OrderFilter::class)
  45.  * @ApiFilter(SearchFilter::class)
  46.  * @ApiFilter(BooleanFilter::class, properties={"active"})
  47.  * @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true, "whitelist": {
  48.  *      "homepage:read"
  49.  * }})
  50.  * @ApiFilter(PropertyFilter::class, 
  51.  *      arguments={
  52.  *          "parameterName"="fields", 
  53.  *          "overrideDefaultProperties"=true
  54.  *     }
  55.  * )
  56.  */
  57. class Award
  58. {
  59.     /**
  60.      * @ORM\Id
  61.      * @ORM\GeneratedValue
  62.      * @ORM\Column(type="integer")
  63.      * @Groups({"award:read"})
  64.      */
  65.     private $id;
  66.     /**
  67.      * @ORM\Column(type="string", length=255)
  68.      * @Groups({"award:read", "award:write"})
  69.      * @Assert\NotNull
  70.      */
  71.     private $name;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      * @Groups({"award:read", "award:write"})
  75.      */
  76.     private $description null;
  77.     /**
  78.      * @ORM\Column(type="datetime", nullable=true)
  79.      * @Groups({"award:read", "award:write"})
  80.      * @Assert\NotNull(message="award.date_start.blank")
  81.      * @Assert\LessThanOrEqual(propertyPath="dateEnd", message="award.date_start.constraint_date")
  82.      */
  83.     private $dateStart null;
  84.     /**
  85.      * @ORM\Column(type="datetime", nullable=true)
  86.      * @Groups({"award:read", "award:write"})
  87.      * @Assert\NotNull(message="award.date_end.blank")
  88.      * @Assert\GreaterThanOrEqual(propertyPath="dateStart", message="award.date_end.constraint_date")
  89.      */
  90.     private $dateEnd null;
  91.     /**
  92.      * @ORM\Column(type="boolean", options={"default": "0"})
  93.      * @Groups({"award:read", "award:write"})
  94.      */
  95.     private $active false;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity=TvCompany::class, inversedBy="awards")
  98.      * @Groups({"award:read", "award:write"})
  99.      */
  100.     private $tvCompanies;
  101.     /**
  102.      * @ORM\ManyToMany(targetEntity=Company::class, inversedBy="awards")
  103.      * @Groups({"award:read", "award:write"})
  104.      * @Assert\NotNull
  105.      */
  106.     private $companies;
  107.     /**
  108.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  109.      * @Groups({"award:read", "award:write"})
  110.      */
  111.     private $rules null;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity=AwardConfig::class, mappedBy="award", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  114.      */
  115.     private $awardConfigs;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity=AwardLog::class, mappedBy="award", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  118.      */
  119.     private $awardLogs;
  120.     /**
  121.      * @ORM\Column(type="datetime")
  122.      * @Gedmo\Timestampable(on="create")
  123.      */
  124.     private $createdAt;
  125.     /**
  126.      * @ORM\Column(type="datetime")
  127.      * @Gedmo\Timestampable(on="update")
  128.      */
  129.     private $updatedAt;
  130.     public function __construct()
  131.     {
  132.         $this->active false;
  133.         $this->tvCompanies = new ArrayCollection();
  134.         $this->companies = new ArrayCollection();
  135.         $this->awardConfigs = new ArrayCollection();
  136.         $this->awardLogs = new ArrayCollection();
  137.         $this->rules null;
  138.         $this->createdAt = new \DateTime("now");
  139.         $this->updatedAt = new \DateTime("now");
  140.     }
  141.     public function getId(): ?int
  142.     {
  143.         return $this->id;
  144.     }
  145.     public function getName(): ?string
  146.     {
  147.         return $this->name;
  148.     }
  149.     public function setName(string $name): self
  150.     {
  151.         $this->name $name;
  152.         return $this;
  153.     }
  154.     public function getDescription(): ?string
  155.     {
  156.         return $this->description;
  157.     }
  158.     public function setDescription(?string $description): self
  159.     {
  160.         $this->description $description;
  161.         return $this;
  162.     }
  163.     public function getDateStart(): ?\DateTimeInterface
  164.     {
  165.         return $this->dateStart;
  166.     }
  167.     public function setDateStart(?\DateTimeInterface $dateStart): self
  168.     {
  169.         $this->dateStart $dateStart;
  170.         if($this->dateStart instanceof \DateTime$this->dateStart->setTime(0,0,0);
  171.         return $this;
  172.     }
  173.     public function getDateEnd(): ?\DateTimeInterface
  174.     {
  175.         return $this->dateEnd;
  176.     }
  177.     public function setDateEnd(?\DateTimeInterface $dateEnd): self
  178.     {
  179.         $this->dateEnd $dateEnd;
  180.         if($this->dateEnd instanceof \DateTime$this->dateEnd->setTime(23,59,59);
  181.         return $this;
  182.     }
  183.     public function getActive(): ?bool
  184.     {
  185.         return $this->active;
  186.     }
  187.     public function setActive(bool $active): self
  188.     {
  189.         $this->active $active;
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection|TvCompany[]
  194.      */
  195.     public function getTvCompanies(): Collection
  196.     {
  197.         return $this->tvCompanies;
  198.     }
  199.     /**
  200.      * @var Collection|TvCompany[]
  201.      * @Groups({"award:write"})
  202.      */
  203.     public function setTvCompanies(array $tvCompanies): self
  204.     {
  205.         $this->tvCompanies = new ArrayCollection($tvCompanies);
  206.         return $this;
  207.     }
  208.     public function addTvCompany(TvCompany $tvCompany): self
  209.     {
  210.         if (!$this->tvCompanies->contains($tvCompany)) {
  211.             $this->tvCompanies[] = $tvCompany;
  212.         }
  213.         return $this;
  214.     }
  215.     public function removeTvCompany(TvCompany $tvCompany): self
  216.     {
  217.         $this->tvCompanies->removeElement($tvCompany);
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection|Company[]
  222.      */
  223.     public function getCompanies(): Collection
  224.     {
  225.         return $this->companies;
  226.     }
  227.     /**
  228.      * @var Collection|Company[]
  229.      * @Groups({"award:write"})
  230.      */
  231.     public function setCompanies(array $companies): self
  232.     {
  233.         $this->companies = new ArrayCollection($companies);
  234.         return $this;
  235.     }
  236.     public function addCompany(Company $company): self
  237.     {
  238.         if (!$this->companies->contains($company)) {
  239.             $this->companies[] = $company;
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeCompany(Company $company): self
  244.     {
  245.         $this->companies->removeElement($company);
  246.         return $this;
  247.     }
  248.     public function getRules(): ?MediaObject
  249.     {
  250.         return $this->rules;
  251.     }
  252.     public function setRules(?MediaObject $rules): self
  253.     {
  254.         $this->rules $rules;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @Groups({"award:write"})
  259.      */
  260.     public function setRulesFile($file null): self
  261.     {
  262.         if($file instanceof UploadedFile) {
  263.             $rules = empty($this->rules) ? new MediaObject $this->rules;
  264.             $rules->setFile($file);
  265.             $this->setRules($rules);
  266.         }
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection<int, AwardConfig>
  271.      */
  272.     public function getAwardConfigs(): Collection
  273.     {
  274.         return $this->awardConfigs;
  275.     }
  276.     public function addAwardConfig(AwardConfig $awardConfig): self
  277.     {
  278.         if (!$this->awardConfigs->contains($awardConfig)) {
  279.             $this->awardConfigs[] = $awardConfig;
  280.             $awardConfig->setAward($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removeAwardConfig(AwardConfig $awardConfig): self
  285.     {
  286.         if ($this->awardConfigs->removeElement($awardConfig)) {
  287.             // set the owning side to null (unless already changed)
  288.             if ($awardConfig->getAward() === $this) {
  289.                 $awardConfig->setAward(null);
  290.             }
  291.         }
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return Collection|AwardLog[]
  296.      */
  297.     public function getAwardLogs(): Collection
  298.     {
  299.         return $this->awardLogs;
  300.     }
  301.     public function addAwardLog(AwardLog $awardLog): self
  302.     {
  303.         if (!$this->awardLogs->contains($awardLog)) {
  304.             $this->awardLogs[] = $awardLog;
  305.             $awardLog->setAward($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeAwardLog(AwardLog $awardLog): self
  310.     {
  311.         if ($this->awardLogs->removeElement($awardLog)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($awardLog->getAward() === $this) {
  314.                 $awardLog->setAward(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     public function getCreatedAt(): ?\DateTimeInterface
  320.     {
  321.         return $this->createdAt;
  322.     }
  323.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  324.     {
  325.         $this->createdAt $createdAt;
  326.         return $this;
  327.     }
  328.     public function getUpdatedAt(): ?\DateTimeInterface
  329.     {
  330.         return $this->updatedAt;
  331.     }
  332.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  333.     {
  334.         $this->updatedAt $updatedAt;
  335.         return $this;
  336.     }
  337. }