src/Entity/Answer.php line 62

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\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  10. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  11. use App\Repository\AnswerRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. /**
  18.  * @ORM\Entity(repositoryClass=AnswerRepository::class)
  19.  * @ApiResource(
  20.  *      normalizationContext={
  21.  *          "groups"={"answer:read"}
  22.  *     },
  23.  *     denormalizationContext={
  24.  *          "groups"={"answer:write"}
  25.  *     },
  26.  *     collectionOperations={
  27.  *          "get"={
  28.  *              "security"="is_granted('ROLE_USER') or is_granted('ROLE_ADMIN')" 
  29.  *          },
  30.  *          "post"={
  31.  *              "security"="is_granted('ROLE_ADMIN')"
  32.  *          }
  33.  *     },
  34.  *     itemOperations={
  35.  *          "get"={
  36.  *              "security"="is_granted('ROLE_USER') or is_granted('ROLE_ADMIN')" 
  37.  *          },
  38.  *          "delete"={
  39.  *              "security"="is_granted('ROLE_ADMIN')"
  40.  *          },
  41.  *          "patch"={
  42.  *              "security"="is_granted('ROLE_ADMIN')"
  43.  *          }
  44.  *     }
  45.  * )
  46.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "name": "partial", "type": "exact", "question.id": "exact", "category.id": "exact", "status": "exact", "active"})
  47.  * @ApiFilter(OrderFilter::class, properties={"id", "name", "question.id", "tvTag.id", "tvTag.name", "active", "rank"})
  48.  * @ApiFilter(GroupFilter::class, arguments={
  49.  *      "parameterName": "groups", 
  50.  *      "overrideDefaultGroups": true
  51.  * })
  52.  * @ApiFilter(PropertyFilter::class, 
  53.  *      arguments={
  54.  *          "parameterName"="fields", 
  55.  *          "overrideDefaultProperties"=true
  56.  *     }
  57.  * )
  58.  */
  59. class Answer
  60. {
  61.     /**
  62.      * @ORM\Id
  63.      * @ORM\GeneratedValue
  64.      * @ORM\Column(type="integer")
  65.      * @Groups({"answer:read:id", "answer:read", "survey:read", "question:read", "answer_list", "teamplay_challenge:read"})
  66.      */
  67.     private $id;
  68.     /**
  69.      * @ORM\Column(type="string", length=255)
  70.      * @Groups({"answer:read:name", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
  71.      */
  72.     private $name;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      * @Gedmo\Timestampable(on="update")
  76.      */
  77.     private $updatedAt;
  78.     /**
  79.      * @ORM\Column(type="datetime")
  80.      * @Gedmo\Timestampable(on="create")
  81.      */
  82.     private $createdAt;
  83.     /**
  84.      * @ORM\ManyToOne(targetEntity=Question::class, inversedBy="answers", cascade={"persist", "refresh"})
  85.      * @ORM\JoinColumn(nullable=false)
  86.      * @Groups({"answer:read:question", "answer:read", "answer:write", "answer_recommended_objectives_edit"})
  87.      */
  88.     private $question;
  89.     /**
  90.      * @ORM\Column(type="integer", nullable=true)
  91.      * @Groups({"answer:read:value", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
  92.      */
  93.     private $value null;
  94.     /**
  95.      * @ORM\Column(name="`rank`", type="integer", options={"default": "999"})
  96.      * @Groups({"answer:read:rank", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
  97.      */
  98.     private $rank 999;
  99.     /**
  100.      * @ORM\Column(type="boolean", options={"default": "1"})
  101.      * @Groups({"answer:read:active", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
  102.      */
  103.     private $active 1;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity=Program::class)
  106.      * @Groups({"answer:read:program", "answer:write"})
  107.      */
  108.     private $program null;
  109.     /**
  110.      * @ORM\ManyToOne(targetEntity=Objective::class)
  111.      * @Groups({"answer:read:recommendedObjective"})
  112.      */
  113.     private $recommendedObjective null;
  114.     /**
  115.      * @ORM\Column(type="text", nullable=true)
  116.      * @Groups({"answer:read:description", "answer:read", "answer:write", "survey:read", "question:read", "teamplay_challenge:write", "teamplay_challenge:read"})
  117.      */
  118.     private $description;
  119.     /**
  120.      * Custom fields
  121.      * @var bool|null
  122.      * @Groups({"answer:read:selectedByUser", "answer:read", "answer:write", "survey:read", "question:read", "teamplay_challenge:write", "teamplay_challenge:read"})
  123.      */
  124.     private $selectedByUser null;
  125.     public function __clone()
  126.     {
  127.         $this->id null;
  128.         $this->rank 999;        
  129.         $this->active 1;
  130.         $this->program null;
  131.         $this->recommendedObjective null;
  132.         $this->createdAt = new \DateTime();
  133.         $this->updatedAt = new \DateTime();
  134.     }
  135.     public function getId(): ?int
  136.     {
  137.         return $this->id;
  138.     }
  139.     public function setId(?int $id): self
  140.     {
  141.         $this->id $id;
  142.         return $this;
  143.     }
  144.     public function getName(): ?string
  145.     {
  146.         return $this->name;
  147.     }
  148.     public function setName(string $name): self
  149.     {
  150.         $this->name $name;
  151.         return $this;
  152.     }
  153.     public function getCreatedAt(): ?\DateTimeInterface
  154.     {
  155.         return $this->createdAt;
  156.     }
  157.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  158.     {
  159.         $this->createdAt $createdAt;
  160.         return $this;
  161.     }
  162.     public function getUpdatedAt(): ?\DateTimeInterface
  163.     {
  164.         return $this->updatedAt;
  165.     }
  166.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  167.     {
  168.         $this->updatedAt $updatedAt;
  169.         return $this;
  170.     }
  171.     public function getQuestion(): ?Question
  172.     {
  173.         return $this->question;
  174.     }
  175.     public function setQuestion(?Question $question): self
  176.     {
  177.         $this->question $question;
  178.         return $this;
  179.     }
  180.     public function getValue(): ?int
  181.     {
  182.         return $this->value;
  183.     }
  184.     public function setValue(?int $value): self
  185.     {
  186.         $this->value $value;
  187.         return $this;
  188.     }
  189.     public function getRank(): ?int
  190.     {
  191.         return $this->rank;
  192.     }
  193.     public function setRank(int $rank): self
  194.     {
  195.         $this->rank $rank;
  196.         return $this;
  197.     }
  198.     public function getActive(): ?bool
  199.     {
  200.         return $this->active;
  201.     }
  202.     public function setActive(bool $active): self
  203.     {
  204.         $this->active $active;
  205.         return $this;
  206.     }
  207.     public function getProgram(): ?Program
  208.     {
  209.         return $this->program;
  210.     }
  211.     public function setProgram(?Program $program): self
  212.     {
  213.         $this->program $program;
  214.         return $this;
  215.     }
  216.     public function getRecommendedObjective(): ?Objective
  217.     {
  218.         return $this->recommendedObjective;
  219.     }
  220.     public function setRecommendedObjective(?Objective $recommendedObjective): self
  221.     {
  222.         $this->recommendedObjective $recommendedObjective;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection|Video[]
  227.      * @Groups({"answer:read:videos", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
  228.      */
  229.     public function getVideos(): ?Collection
  230.     {
  231.         if(!$this->recommendedObjective instanceof Objective) return null;
  232.         return $this->recommendedObjective->getVideos();
  233.     }
  234.     /**
  235.      * @return Collection|Program[]
  236.      * @Groups({"answer:read:programs", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
  237.      */
  238.     public function getPrograms(): ?Collection
  239.     {
  240.         if(!$this->recommendedObjective instanceof Objective) return null;
  241.         return $this->recommendedObjective->getPrograms();
  242.     }
  243.     /**
  244.      * @return Collection|Channel[]
  245.      * @Groups({"answer:read:channels", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
  246.      */
  247.     public function getChannels(): ?Collection
  248.     {
  249.         if(!$this->recommendedObjective instanceof Objective) return null;
  250.         return $this->recommendedObjective->getChannels();
  251.     }
  252.     public function getDescription(): ?string
  253.     {
  254.         return $this->description;
  255.     }
  256.     public function setDescription(?string $description): self
  257.     {
  258.         $this->description $description;
  259.         return $this;
  260.     }
  261.     public function getSelectedByUser(): ?bool
  262.     {
  263.         return $this->selectedByUser;
  264.     }
  265.     public function isSelectedByUser(): ?bool
  266.     {
  267.         return $this->selectedByUser;
  268.     }
  269.     public function setSelectedByUser(?bool $selectedByUser): self
  270.     {
  271.         $this->selectedByUser $selectedByUser;
  272.         return $this;
  273.     }
  274. }