src/Entity/AwardConfig.php line 47

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\SearchFilter;
  6. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  7. use App\Repository\AwardConfigRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity(repositoryClass=AwardConfigRepository::class)
  15.  * @ApiResource(
  16.  *     normalizationContext={
  17.  *         "groups"={"award_config:read"}
  18.  *     },
  19.  *     denormalizationContext={
  20.  *          "groups"={"award_config:write"}
  21.  *     },
  22.  *     collectionOperations={
  23.  *          "get"={"security"="is_granted('ROLE_USER')"}
  24.  *     },
  25.  *     itemOperations={
  26.  *          "get"={"security"="is_granted('ROLE_USER')"},
  27.  *          "patch"={"security"="is_granted('ROLE_ADMIN')"}
  28.  *     }
  29.  * )
  30.  * @ApiFilter(SearchFilter::class, 
  31.  *      properties={
  32.  *          "id": "exact", "type": "exact", "company.id": "exact", 
  33.  *          "award.id": "exact", "operation.id": "exact", 
  34.  *          "active": "exact"
  35.  *      }
  36.  * )
  37.  * @ApiFilter(PropertyFilter::class, 
  38.  *      arguments={
  39.  *          "parameterName"="fields", 
  40.  *          "overrideDefaultProperties"=true
  41.  *     }
  42.  * )
  43.  */
  44. class AwardConfig
  45. {
  46.     const DOTATION_TYPE "dotation";
  47.     const OPERATION_TYPE "operation";
  48.     const TYPES = [
  49.         self::DOTATION_TYPE,
  50.         self::OPERATION_TYPE
  51.     ];
  52.     /**
  53.      * @ORM\Id
  54.      * @ORM\GeneratedValue
  55.      * @ORM\Column(type="integer")
  56.      * @Groups({"award_config:read"})
  57.      */
  58.     private $id;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      * @Assert\Choice(choices=self::TYPES)
  62.      * @Groups({"award_config:read", "award_config:write"})
  63.      */
  64.     private $type;
  65.     /**
  66.      * @ORM\Column(type="integer", nullable=true)
  67.      * @Groups({"award_config:read", "award_config:write"})
  68.      */
  69.     private $points;
  70.     /**
  71.      * @ORM\Column(type="integer", nullable=true)
  72.      * @Groups({"award_config:read", "award_config:write"})
  73.      */
  74.     private $maxPoints;
  75.     /**
  76.      * @ORM\Column(type="integer", nullable=true)
  77.      * @Groups({"award_config:read", "award_config:write"})
  78.      */
  79.     private $minPoints;
  80.     /**
  81.      * @ORM\Column(type="string", length=255, nullable=true)
  82.      * @Groups({"award_config:read", "award_config:write"})
  83.      */
  84.     private $name;
  85.     /**
  86.      * @ORM\Column(type="text", nullable=true)
  87.      * @Groups({"award_config:read", "award_config:write"})
  88.      */
  89.     private $content;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  92.      * @Groups({"award_config:read", "award_config:write"})
  93.      */
  94.     private $preview;
  95.     /**
  96.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  97.      * @Groups({"award_config:read", "award_config:write"})
  98.      */
  99.     private $picture;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  102.      * @Groups({"award_config:read", "award_config:write"})
  103.      */
  104.     private $illustration;
  105.     /**
  106.      * @ORM\Column(name="`rank`", type="integer", nullable=true)
  107.      * @Groups({"award_config:read", "award_config:write"})
  108.      */
  109.     private $rank;
  110.     /**
  111.      * @ORM\ManyToOne(targetEntity=Award::class, inversedBy="awardConfigs")
  112.      * @ORM\JoinColumn(nullable=false)
  113.      * @Groups({"award_config:read", "award_config:write"})
  114.      */
  115.     private $award;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity=AwardOperation::class, inversedBy="configs")
  118.      * @Groups({"award_config:read", "award_config:write"})
  119.      */
  120.     private $operation;
  121.     /**
  122.      * @ORM\ManyToOne(targetEntity=TvCompany::class, inversedBy="awardConfigs")
  123.      * @Groups({"award_config:read", "award_config:write"})
  124.      */
  125.     private $tvCompany;
  126.     /**
  127.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="awardConfigs")
  128.      * @Groups({"award_config:read", "award_config:write"})
  129.      */
  130.     private $company;
  131.     
  132.     /**
  133.      * @ORM\Column(type="boolean", options={"default": "1"})
  134.      * @Groups({"award_config:read", "award_config:write"})
  135.      */
  136.     private $active true;
  137.     /**
  138.      * @ORM\Column(type="datetime")
  139.      * @Gedmo\Timestampable(on="update")
  140.      */
  141.     private $updatedAt;
  142.     /**
  143.      * @ORM\Column(type="datetime")
  144.      * @Gedmo\Timestampable(on="create")
  145.      */
  146.     private $createdAt;
  147.     public function __construct()
  148.     {
  149.         $this->active true;
  150.     }
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     public function getPoints(): ?int
  156.     {
  157.         return $this->points;
  158.     }
  159.     public function setPoints(?int $points): self
  160.     {
  161.         $this->points $points;
  162.         return $this;
  163.     }
  164.     public function getMaxPoints(): ?int
  165.     {
  166.         return $this->maxPoints;
  167.     }
  168.     public function setMaxPoints(?int $maxPoints): self
  169.     {
  170.         $this->maxPoints $maxPoints;
  171.         return $this;
  172.     }
  173.     public function getMinPoints(): ?int
  174.     {
  175.         return $this->minPoints;
  176.     }
  177.     public function setMinPoints(?int $minPoints): self
  178.     {
  179.         $this->minPoints $minPoints;
  180.         return $this;
  181.     }
  182.     public function getOperation(): ?AwardOperation
  183.     {
  184.         return $this->operation;
  185.     }
  186.     public function setOperation(?AwardOperation $operation): self
  187.     {
  188.         $this->operation $operation;
  189.         return $this;
  190.     }
  191.     public function getAward(): ?Award
  192.     {
  193.         return $this->award;
  194.     }
  195.     public function setAward(?Award $award): self
  196.     {
  197.         $this->award $award;
  198.         return $this;
  199.     }
  200.     public function getTvCompany(): ?TvCompany
  201.     {
  202.         return $this->tvCompany;
  203.     }
  204.     public function setTvCompany(?TvCompany $tvCompany): self
  205.     {
  206.         $this->tvCompany $tvCompany;
  207.         return $this;
  208.     }
  209.     public function getCompany(): ?Company
  210.     {
  211.         return $this->company;
  212.     }
  213.     public function setCompany(?Company $company): self
  214.     {
  215.         $this->company $company;
  216.         return $this;
  217.     }
  218.     public function getActive(): ?bool
  219.     {
  220.         return $this->active;
  221.     }
  222.     public function setActive(bool $active): self
  223.     {
  224.         $this->active $active;
  225.         return $this;
  226.     }
  227.     public function getCreatedAt(): ?\DateTimeInterface
  228.     {
  229.         return $this->createdAt;
  230.     }
  231.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  232.     {
  233.         $this->createdAt $createdAt;
  234.         return $this;
  235.     }
  236.     public function getUpdatedAt(): ?\DateTimeInterface
  237.     {
  238.         return $this->updatedAt;
  239.     }
  240.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  241.     {
  242.         $this->updatedAt $updatedAt;
  243.         return $this;
  244.     }
  245.     public function getType(): ?string
  246.     {
  247.         return $this->type;
  248.     }
  249.     public function setType(?string $type): self
  250.     {
  251.         $this->type $type;
  252.         return $this;
  253.     }
  254.     public function getRank(): ?int
  255.     {
  256.         return $this->rank;
  257.     }
  258.     public function setRank(?int $rank): self
  259.     {
  260.         $this->rank $rank;
  261.         return $this;
  262.     }
  263.     public function getName(): ?string
  264.     {
  265.         return $this->name;
  266.     }
  267.     public function setName(?string $name): self
  268.     {
  269.         $this->name $name;
  270.         return $this;
  271.     }
  272.     public function getContent(): ?string
  273.     {
  274.         return $this->content;
  275.     }
  276.     public function setContent(?string $content): self
  277.     {
  278.         $this->content $content;
  279.         return $this;
  280.     }
  281.     public function getPreview(): ?MediaObject
  282.     {
  283.         return $this->preview;
  284.     }
  285.     public function setPreview(?MediaObject $preview): self
  286.     {
  287.         $this->preview $preview;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @Groups({"award_config:write"})
  292.      */
  293.     public function setPreviewFile($file null): self
  294.     {
  295.         if($file instanceof UploadedFile) {
  296.             $preview = empty($this->preview) ? new MediaObject $this->preview;
  297.             $preview->setFile($file);
  298.             $this->setPreview($preview);
  299.         }
  300.         return $this;
  301.     }
  302.     public function getPicture(): ?MediaObject
  303.     {
  304.         return $this->picture;
  305.     }
  306.     public function setPicture(?MediaObject $picture): self
  307.     {
  308.         $this->picture $picture;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @Groups({"award_config:write"})
  313.      */
  314.     public function setPictureFile($file null): self
  315.     {
  316.         if($file instanceof UploadedFile) {
  317.             $picture = empty($this->picture) ? new MediaObject $this->picture;
  318.             $picture->setFile($file);
  319.             $this->setPicture($picture);
  320.         }
  321.         return $this;
  322.     }
  323.     public function getIllustration(): ?MediaObject
  324.     {
  325.         return $this->illustration;
  326.     }
  327.     public function setIllustration(?MediaObject $illustration): self
  328.     {
  329.         $this->illustration $illustration;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @Groups({"award_config:write"})
  334.      */
  335.     public function setIllustrationFile($file null): self
  336.     {
  337.         if($file instanceof UploadedFile) {
  338.             $illustration = empty($this->illustration) ? new MediaObject $this->illustration;
  339.             $illustration->setFile($file);
  340.             $this->setIllustration($illustration);
  341.         }
  342.         return $this;
  343.     }
  344. }