src/Entity/SurveyConfig.php line 61

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use App\Repository\SurveyConfigRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17.  * @ORM\Entity(repositoryClass=SurveyConfigRepository::class)
  18.  * @ApiResource(
  19.  *     normalizationContext={
  20.  *         "groups"={"survey_config:read"}
  21.  *     },
  22.  *     denormalizationContext={
  23.  *          "groups"={"survey_config:write"}
  24.  *     },
  25.  *     collectionOperations={
  26.  *          "get",
  27.  *          "post"={
  28.  *              "security"="is_granted('ROLE_ADMIN')"
  29.  *          },
  30.  *     },
  31.  *     itemOperations={
  32.  *          "get"={
  33.  *              "security"="is_granted('ROLE_USER')"
  34.  *          },
  35.  *          "delete"={
  36.  *              "security"="is_granted('ROLE_ADMIN')"
  37.  *          },
  38.  *          "patch"={
  39.  *              "security"="is_granted('ROLE_ADMIN')"
  40.  *          },
  41.  *     }
  42.  * )
  43.  * @ApiFilter(SearchFilter::class)
  44.  * @ORM\HasLifecycleCallbacks
  45.  * @ApiFilter(GroupFilter::class, arguments={
  46.  *      "parameterName": "groups", 
  47.  *      "overrideDefaultGroups": true, 
  48.  *      "whitelist": {"survey_config_list"}
  49.  * })
  50.  * @ApiFilter(PropertyFilter::class, 
  51.  *      arguments={
  52.  *          "parameterName"="fields", 
  53.  *          "overrideDefaultProperties"=true
  54.  *     }
  55.  * )
  56.  */
  57. class SurveyConfig
  58. {
  59.     const GLOBAL_TYPE "global";
  60.     const RECOMMENDED_OBJECTIVES "recommended_objectives";
  61.     const TYPES = [
  62.         self::RECOMMENDED_OBJECTIVES,
  63.     ];
  64.     const INTERVALLE_1 "intervalle_1"// Tranche de [0% - 25%[ 
  65.     const INTERVALLE_2 "intervalle_2"// Tranche de [25% - 50%[
  66.     const INTERVALLE_3 "intervalle_3"// Tranche de [50% - 75%[
  67.     const INTERVALLE_4 "intervalle_4"// Tranche de [75% - 100%]
  68.     const SUBTYPES = [
  69.         self::INTERVALLE_1,
  70.         self::INTERVALLE_2,
  71.         self::INTERVALLE_3,
  72.         self::INTERVALLE_4,
  73.     ];
  74.     const INTERVALLES = [
  75.         self::INTERVALLE_1,
  76.         self::INTERVALLE_2,
  77.         self::INTERVALLE_3,
  78.         self::INTERVALLE_4,
  79.     ];
  80.     
  81.     /**
  82.      * @ORM\Id
  83.      * @ORM\GeneratedValue
  84.      * @ORM\Column(type="integer")
  85.      * @Groups({"survey:read", "survey_config:read", "question:read", "survey_config_list"})
  86.      */
  87.     private $id;
  88.     /**
  89.      * @ORM\ManyToOne(targetEntity=Survey::class, inversedBy="configs")
  90.      * @ORM\JoinColumn(nullable=false)
  91.      * @Groups({"survey_config:read", "question:read"})
  92.      */
  93.     private $survey;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      * @Groups({"survey:read", "survey_config:read", "question:read", "survey_config_list"})
  97.      * @Assert\Choice(choices=self::TYPES)
  98.      */
  99.     private $type self::GLOBAL_TYPE;
  100.     /**
  101.      * @ORM\Column(type="string", length=255, nullable=true)
  102.      * @Groups({"survey:read", "survey_config:read", "question:read", "survey_config_list"})
  103.      * @Assert\Choice(choices=self::SUBTYPES)
  104.      */
  105.     private $subType;
  106.     /**
  107.      * @ORM\ManyToOne(targetEntity=TvTag::class)
  108.      * @Groups({"survey_config:read", "question:read", "survey_config_list"})
  109.      */
  110.     private $tvTag null;
  111.     
  112.     /**
  113.      * @ORM\Column(type="string", length=255, nullable=true)
  114.      * @Groups({"survey_config:read", "survey_config:write", "question:read"})
  115.      */
  116.     private $value null;
  117.     /**
  118.      * @ORM\Column(type="boolean", nullable=true, options={"default": 1})
  119.      * @Groups({"survey:read", "survey_config:read", "question:read", "survey_config_list"})
  120.      */
  121.     private $active true;
  122.     /**
  123.      * @ORM\Column(type="datetime")
  124.      * @Gedmo\Timestampable(on="create")
  125.      */
  126.     private $createdAt;
  127.     /**
  128.      * @ORM\Column(type="datetime")
  129.      * @Gedmo\Timestampable(on="update")
  130.      */
  131.     private $updatedAt;
  132.     public function getId(): ?int
  133.     {
  134.         return $this->id;
  135.     }
  136.     public function getSurvey(): ?Survey
  137.     {
  138.         return $this->survey;
  139.     }
  140.     public function setSurvey(?Survey $survey): self
  141.     {
  142.         $this->survey $survey;
  143.         return $this;
  144.     }
  145.     public function getTvTag(): ?TvTag
  146.     {
  147.         return $this->tvTag;
  148.     }
  149.     public function setTvTag(?TvTag $tvTag): self
  150.     {
  151.         $this->tvTag $tvTag;
  152.         return $this;
  153.     }
  154.     public function getCreatedAt(): ?\DateTimeInterface
  155.     {
  156.         return $this->createdAt;
  157.     }
  158.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  159.     {
  160.         $this->createdAt $createdAt;
  161.         return $this;
  162.     }
  163.     public function getUpdatedAt(): ?\DateTimeInterface
  164.     {
  165.         return $this->updatedAt;
  166.     }
  167.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  168.     {
  169.         $this->updatedAt $updatedAt;
  170.         return $this;
  171.     }
  172.     public function getActive(): ?bool
  173.     {
  174.         return $this->active;
  175.     }
  176.     public function setActive(?bool $active): self
  177.     {
  178.         $this->active $active;
  179.         return $this;
  180.     }
  181.     public function getType(): ?string
  182.     {
  183.         return $this->type;
  184.     }
  185.     public function setType(?string $type): self
  186.     {
  187.         $this->type $type;
  188.         return $this;
  189.     }
  190.     public function getSubType(): ?string
  191.     {
  192.         return $this->subType;
  193.     }
  194.     public function setSubType(?string $subType): self
  195.     {
  196.         $this->subType $subType;
  197.         return $this;
  198.     }
  199.     public function getValue(): ?string
  200.     {
  201.         return $this->value;
  202.     }
  203.     public function setValue(?string $value): self
  204.     {
  205.         $this->value $value;
  206.         return $this;
  207.     }
  208. }