src/Entity/AwardOperation.php line 42

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\AwardOperationRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass=AwardOperationRepository::class)
  16.  * @ApiResource(
  17.  *     normalizationContext={
  18.  *         "groups"={"award_operation:read"}
  19.  *     },
  20.  *     denormalizationContext={
  21.  *          "groups"={"award_operation:write"}
  22.  *     },
  23.  *     collectionOperations={
  24.  *          "get"={"security"="is_granted('ROLE_USER')"}
  25.  *     },
  26.  *     itemOperations={
  27.  *          "get"={"security"="is_granted('ROLE_USER')"},
  28.  *          "patch"={"security"="is_granted('ROLE_ADMIN')"}
  29.  *     }
  30.  * )
  31.  * @ApiFilter(SearchFilter::class)
  32.  * @ApiFilter(PropertyFilter::class, 
  33.  *      arguments={
  34.  *          "parameterName"="fields", 
  35.  *          "overrideDefaultProperties"=true
  36.  *     }
  37.  * )
  38.  */
  39. class AwardOperation
  40. {
  41.     const GLOBAL_TYPE "global";
  42.     const ACTION_TYPE "action";
  43.     const TEAMPLAY_ACTION_TYPE "teamplay_action";
  44.     // Global objectives
  45.     const MAIN_OBJECTIVE "main_objective";
  46.     // Actions disponibles
  47.     const THEMATIC_START "thematic_start";
  48.     const PROGRAM_START "program_start";
  49.     const PROGRAM_END "program_end";
  50.     const SURVEY_HOMEPAGE "survey_homepage";
  51.     const SURVEY_PROGRAM "survey_program";
  52.     const VIDEO_PLAY "video_play";
  53.     const VIDEO_PLAY_10_TIMES "video_play_10_times";
  54.     const MOOD_SUBMIT "mood_submit";
  55.     const MOOD_SUBMIT_7_DAYS "mood_submit_7_days";
  56.     const TYPES = [
  57.         self::GLOBAL_TYPE,
  58.         self::ACTION_TYPE,
  59.         self::TEAMPLAY_ACTION_TYPE,
  60.     ];
  61.     const SUB_TYPES = [
  62.         self::MAIN_OBJECTIVE,
  63.         self::THEMATIC_START,
  64.         self::PROGRAM_START,
  65.         self::PROGRAM_END,
  66.         self::SURVEY_HOMEPAGE,
  67.         self::SURVEY_PROGRAM,
  68.         self::VIDEO_PLAY,
  69.         self::VIDEO_PLAY_10_TIMES,
  70.         self::MOOD_SUBMIT,
  71.         self::MOOD_SUBMIT_7_DAYS,
  72.         TeamplayChallenge::TYPE_RECURRENT_RANKING_AWARD,
  73.     ];
  74.     /**
  75.      * @ORM\Id
  76.      * @ORM\GeneratedValue
  77.      * @ORM\Column(type="integer")
  78.      * @Groups({"award_operation:read", "award_config:read"})
  79.      */
  80.     private $id;
  81.     /**
  82.      * @ORM\Column(type="string", length=255)
  83.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  84.      */
  85.     private $name;
  86.     /**
  87.      * @ORM\Column(type="string", length=255, nullable=true)
  88.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  89.      */
  90.     private $description;
  91.     /**
  92.      * @ORM\Column(type="string", length=255, nullable=true)
  93.      * @Assert\Choice(choices=self::TYPES)
  94.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  95.      */
  96.     private $type self::GLOBAL_TYPE;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      * @Assert\Choice(choices=self::SUB_TYPES)
  100.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  101.      */
  102.     private $subType self::MAIN_OBJECTIVE;
  103.     
  104.     /**
  105.      * @ORM\Column(name="`rank`", type="integer", nullable=true)
  106.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  107.      */
  108.     private $rank;
  109.     
  110.     /**
  111.      * @ORM\OneToMany(targetEntity=AwardConfig::class, mappedBy="operation")
  112.      * @Groups({"award_operation:read", "award_operation:write"})
  113.      */
  114.     private $configs;
  115.     /**
  116.      * @ORM\Column(type="boolean", options={"default": "1"})
  117.      * @Groups({"award_operation:read", "award_operation:write", "award_config:read"})
  118.      */
  119.     private $active true;
  120.     
  121.     /**
  122.      * @ORM\Column(type="datetime")
  123.      * @Gedmo\Timestampable(on="update")
  124.      */
  125.     private $updatedAt;
  126.     /**
  127.      * @ORM\Column(type="datetime")
  128.      * @Gedmo\Timestampable(on="create")
  129.      */
  130.     private $createdAt;
  131.     public function __construct()
  132.     {
  133.         $this->configs = new ArrayCollection();
  134.         $this->createdAt = new \DateTime("now");
  135.         $this->updatedAt = new \DateTime("now");
  136.         $this->active true;
  137.     }
  138.     public function getId(): ?int
  139.     {
  140.         return $this->id;
  141.     }
  142.     public function getName(): ?string
  143.     {
  144.         return $this->name;
  145.     }
  146.     public function setName(string $name): self
  147.     {
  148.         $this->name $name;
  149.         return $this;
  150.     }
  151.     public function getDescription(): ?string
  152.     {
  153.         return $this->description;
  154.     }
  155.     public function setDescription(?string $description): self
  156.     {
  157.         $this->description $description;
  158.         return $this;
  159.     }
  160.     public function getActive(): ?bool
  161.     {
  162.         return $this->active;
  163.     }
  164.     public function setActive(bool $active): self
  165.     {
  166.         $this->active $active;
  167.         return $this;
  168.     }
  169.     public function getCreatedAt(): ?\DateTimeInterface
  170.     {
  171.         return $this->createdAt;
  172.     }
  173.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  174.     {
  175.         $this->createdAt $createdAt;
  176.         return $this;
  177.     }
  178.     public function getUpdatedAt(): ?\DateTimeInterface
  179.     {
  180.         return $this->updatedAt;
  181.     }
  182.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  183.     {
  184.         $this->updatedAt $updatedAt;
  185.         return $this;
  186.     }
  187.     public function getType(): ?string
  188.     {
  189.         return $this->type;
  190.     }
  191.     public function setType(?string $type): self
  192.     {
  193.         $this->type $type;
  194.         return $this;
  195.     }
  196.     public function getRank(): ?int
  197.     {
  198.         return $this->rank;
  199.     }
  200.     public function setRank(?int $rank): self
  201.     {
  202.         $this->rank $rank;
  203.         return $this;
  204.     }
  205.     /**
  206.      * @return Collection|AwardConfig[]
  207.      */
  208.     public function getConfigs(): Collection
  209.     {
  210.         return $this->configs;
  211.     }
  212.     public function addConfig(AwardConfig $config): self
  213.     {
  214.         if (!$this->configs->contains($config)) {
  215.             $this->configs[] = $config;
  216.             $config->setOperation($this);
  217.         }
  218.         return $this;
  219.     }
  220.     public function removeConfig(AwardConfig $config): self
  221.     {
  222.         if ($this->configs->removeElement($config)) {
  223.             // set the owning side to null (unless already changed)
  224.             if ($config->getOperation() === $this) {
  225.                 $config->setOperation(null);
  226.             }
  227.         }
  228.         return $this;
  229.     }
  230.     public function getSubType(): ?string
  231.     {
  232.         return $this->subType;
  233.     }
  234.     public function setSubType(?string $subType): self
  235.     {
  236.         $this->subType $subType;
  237.         return $this;
  238.     }
  239. }