src/Entity/Survey.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\SurveyRepository;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use App\Entity\Traits\TimestampableEntity;
  7. use Doctrine\Common\Collections\Collection;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use App\Entity\Interfaces\ContainerMappedInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  16. /**
  17.  * @ApiResource(
  18.  *      attributes={"security"="is_granted('ROLE_OPERATOR')"},
  19.  *      normalizationContext={"groups"={"Survey:Read", "TZ:Read"}, "skip_null_values"=false},
  20.  *      denormalizationContext={"groups"={"Survey:Write"}},
  21.  *      collectionOperations={
  22.  *          "get",
  23.  *          "get_active"={
  24.  *              "path"="/surveys/get-active",
  25.  *              "method"="GET",
  26.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')",
  27.  *              "pagination_enabled"=false
  28.  *          },
  29.  *          "post"
  30.  *      },
  31.  *      itemOperations={
  32.  *          "get",
  33.  *          "put",
  34.  *          "patch",
  35.  *          "delete"
  36.  *     }
  37.  * )
  38.  * @ApiFilter(SearchFilter::class, properties={"container.id": "exact", "name": "partial", "surveyTriggers.triggerType": "exact", "surveyTriggers.elTask.id": "exact", "surveyTriggers.elExam.id": "exact"})
  39.  * @ApiFilter(BooleanFilter::class, properties={"isActive", "isMandatory"})
  40.  * @ApiFilter(OrderFilter::class, properties={"id", "name", "createdAt"})
  41.  * @ORM\Entity(repositoryClass=SurveyRepository::class)
  42.  */
  43. class Survey implements ContainerMappedInterface
  44. {
  45.     /**
  46.      * Hook timestampable behavior
  47.      * updates createdAt, updatedAt fields
  48.      */
  49.     use TimestampableEntity;
  50.     /**
  51.      * @ORM\Id
  52.      * @ORM\GeneratedValue
  53.      * @ORM\Column(type="integer")
  54.      * @Groups({"Survey:Read"})
  55.      */
  56.     private $id;
  57.     /**
  58.      * @ORM\Column(type="string", length=255)
  59.      * @Assert\NotBlank(message="validation.Survey:name.notBlank")
  60.      * @Groups({"Survey:Read", "Survey:Write"})
  61.      */
  62.     private $name;
  63.     /**
  64.      * @ORM\Column(type="boolean", nullable=true)
  65.      * @Groups({"Survey:Read", "Survey:Write"})
  66.      */
  67.     private $isActive;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity=Container::class)
  70.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  71.      * @Groups({"Survey:Write"})
  72.      */
  73.     private $container;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=SurveyTrigger::class, mappedBy="survey", orphanRemoval=true, cascade={"persist"})
  76.      * @Assert\Valid()
  77.      * @Groups({"Survey:Read", "Survey:Write"})
  78.      */
  79.     private $surveyTriggers;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity=SurveyQuestion::class, mappedBy="survey", orphanRemoval=true)
  82.      */
  83.     private $surveyQuestions;
  84.     /**
  85.      * @ORM\ManyToMany(targetEntity=UserGroup::class, inversedBy="surveys")
  86.      * @Groups({"Survey:Read", "Survey:Write"})
  87.      */
  88.     private $userGroups;
  89.     /**
  90.      * @ORM\Column(type="boolean", nullable=true)
  91.      * @Groups({"Survey:Read", "Survey:Write"})
  92.      */
  93.     private $isShowCancel;
  94.     /**
  95.      * @ORM\Column(type="string", length=32)
  96.      * @Groups({"Survey:Read", "Survey:Write"})
  97.      */
  98.     private $visibility;
  99.     public const SURVEYTRIGGERVISIBILITY_ONE_TIME "ONE_TIME";
  100.     public const SURVEYTRIGGERVISIBILITY_ONE_TIME_PER_TRIGGER "ONE_TIME_PER_TRIGGER";
  101.     public const SURVEYTRIGGERVISIBILITY_ALWAYS "ALWAYS";
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=SurveyPage::class, mappedBy="survey")
  104.      */
  105.     private $surveyPages;
  106.     /**
  107.      * @ORM\Column(type="boolean", nullable=true)
  108.      * @Groups({"Survey:Read", "Survey:Write"})
  109.      */
  110.     private $isMandatory;
  111.     public function __construct()
  112.     {
  113.         $this->surveyTriggers = new ArrayCollection();
  114.         $this->surveyQuestions = new ArrayCollection();
  115.         $this->userGroups = new ArrayCollection();
  116.         $this->surveyPages = new ArrayCollection();
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getName(): ?string
  123.     {
  124.         return $this->name;
  125.     }
  126.     public function setName(string $name): self
  127.     {
  128.         $this->name $name;
  129.         return $this;
  130.     }
  131.     public function getIsActive(): ?bool
  132.     {
  133.         return $this->isActive;
  134.     }
  135.     public function setIsActive(?bool $isActive): self
  136.     {
  137.         $this->isActive $isActive;
  138.         return $this;
  139.     }
  140.     public function getContainer(): ?Container
  141.     {
  142.         return $this->container;
  143.     }
  144.     public function setContainer(?Container $container): self
  145.     {
  146.         $this->container $container;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection|SurveyTrigger[]
  151.      */
  152.     public function getSurveyTriggers(): Collection
  153.     {
  154.         return $this->surveyTriggers;
  155.     }
  156.     public function addSurveyTrigger(SurveyTrigger $surveyTrigger): self
  157.     {
  158.         if (!$this->surveyTriggers->contains($surveyTrigger)) {
  159.             $this->surveyTriggers[] = $surveyTrigger;
  160.             $surveyTrigger->setSurvey($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeSurveyTrigger(SurveyTrigger $surveyTrigger): self
  165.     {
  166.         if ($this->surveyTriggers->removeElement($surveyTrigger)) {
  167.             // set the owning side to null (unless already changed)
  168.             if ($surveyTrigger->getSurvey() === $this) {
  169.                 $surveyTrigger->setSurvey(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174.     public function removeAllSurveyTriggers(): self
  175.     {
  176.         foreach ($this->surveyTriggers as $surveyTrigger) {
  177.             $this->removeSurveyTrigger($surveyTrigger);
  178.         }
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return Collection|SurveyQuestion[]
  183.      */
  184.     public function getSurveyQuestions(): Collection
  185.     {
  186.         return $this->surveyQuestions;
  187.     }
  188.     public function addSurveyQuestion(SurveyQuestion $surveyQuestion): self
  189.     {
  190.         if (!$this->surveyQuestions->contains($surveyQuestion)) {
  191.             $this->surveyQuestions[] = $surveyQuestion;
  192.             $surveyQuestion->setSurvey($this);
  193.         }
  194.         return $this;
  195.     }
  196.     public function removeSurveyQuestion(SurveyQuestion $surveyQuestion): self
  197.     {
  198.         if ($this->surveyQuestions->removeElement($surveyQuestion)) {
  199.             // set the owning side to null (unless already changed)
  200.             if ($surveyQuestion->getSurvey() === $this) {
  201.                 $surveyQuestion->setSurvey(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection|UserGroup[]
  208.      */
  209.     public function getUserGroups(): Collection
  210.     {
  211.         return $this->userGroups;
  212.     }
  213.     public function addUserGroup(UserGroup $userGroup): self
  214.     {
  215.         if (!$this->userGroups->contains($userGroup)) {
  216.             $this->userGroups[] = $userGroup;
  217.         }
  218.         return $this;
  219.     }
  220.     public function removeUserGroup(UserGroup $userGroup): self
  221.     {
  222.         $this->userGroups->removeElement($userGroup);
  223.         return $this;
  224.     }
  225.     public function removeAllUserGroups(): self
  226.     {
  227.         foreach ($this->userGroups as $userGroup) {
  228.             $this->removeUserGroup($userGroup);
  229.         }
  230.         return $this;
  231.     }
  232.     public function getIsShowCancel(): ?bool
  233.     {
  234.         return $this->isShowCancel;
  235.     }
  236.     public function setIsShowCancel(?bool $isShowCancel): self
  237.     {
  238.         $this->isShowCancel $isShowCancel;
  239.         return $this;
  240.     }
  241.     public function getVisibility(): ?string
  242.     {
  243.         return $this->visibility;
  244.     }
  245.     public function setVisibility(string $visibility): self
  246.     {
  247.         $this->visibility $visibility;
  248.         return $this;
  249.     }
  250.     /**
  251.      * @return Collection|SurveyPage[]
  252.      */
  253.     public function getSurveyPages(): Collection
  254.     {
  255.         return $this->surveyPages;
  256.     }
  257.     public function addSurveyPage(SurveyPage $surveyPage): self
  258.     {
  259.         if (!$this->surveyPages->contains($surveyPage)) {
  260.             $this->surveyPages[] = $surveyPage;
  261.             $surveyPage->setSurvey($this);
  262.         }
  263.         return $this;
  264.     }
  265.     public function removeSurveyPage(SurveyPage $surveyPage): self
  266.     {
  267.         if ($this->surveyPages->removeElement($surveyPage)) {
  268.             // set the owning side to null (unless already changed)
  269.             if ($surveyPage->getSurvey() === $this) {
  270.                 $surveyPage->setSurvey(null);
  271.             }
  272.         }
  273.         return $this;
  274.     }
  275.     public function isIsMandatory(): ?bool
  276.     {
  277.         return $this->isMandatory;
  278.     }
  279.     public function setIsMandatory(?bool $isMandatory): self
  280.     {
  281.         $this->isMandatory $isMandatory;
  282.         return $this;
  283.     }
  284. }