src/Entity/SurveyCompanySurveyFormQuestion.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity(repositoryClass="App\Repository\SurveyCompanySurveyFormQuestionRepository")
  15.  */
  16. #[HasLifecycleCallbacks()]
  17. #[ApiResource(
  18.     attributes: ['security' => "is_granted('ROLE_USER')"],
  19.     normalizationContext: ['groups' => ['scsfq:read']],
  20.     denormalizationContext: ['groups' => ['scsfq:write']],
  21.     collectionOperations: [
  22.         'get',
  23.         'post' => [
  24.             'security' => "is_granted('ROLE_ADMIN')",
  25.         ],
  26.     ],
  27.     itemOperations: [
  28.         'get',
  29.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  30.     ],
  31.     order: ['parentSurveyFormQuestion' => 'ASC''rank' => 'ASC']
  32. )]
  33. #[ApiFilter(SearchFilter::class, properties: ['id''surveyCompany' => 'exact''surveyFormQuestion' => 'exact''parentSurveyFormQuestion' => 'exact'])]
  34. #[ApiFilter(PropertyFilter::class)]
  35. #[ApiFilter(OrderFilter::class, properties: ['id''surveyCompany.title''surveyFormQuestion.label''parentSurveyFormQuestion.label''rank''info''level'], arguments: ['orderParameterName' => 'order'])]
  36. class SurveyCompanySurveyFormQuestion
  37. {
  38.     /**
  39.      * @ORM\Id()
  40.      * @ORM\GeneratedValue()
  41.      * @ORM\Column(type="integer")
  42.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item","pinpointCampaign:list","surveyContribution:read"})
  43.      */
  44.     public $id;
  45.     /**
  46.      * @var SurveyCompany
  47.      *
  48.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyCompany", inversedBy="surveyCompanyQuestions")
  49.      * @ORM\JoinColumn(name="survey_company_id", referencedColumnName="id", nullable=false)
  50.      * @Groups({"scsfq:read","scsfq:write"})
  51.      */
  52.     public $surveyCompany;
  53.     /**
  54.      * @var SurveyFormQuestion
  55.      *
  56.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormQuestion", inversedBy="surveyCompanies")
  57.      * @ORM\JoinColumn(name="survey_form_question_id", referencedColumnName="id", nullable=false)
  58.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item","pinpointCampaign:list"})
  59.      */
  60.     public $surveyFormQuestion;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\SurveyFormQuestion", inversedBy="surveyCompanies")
  63.      * @ORM\JoinColumn(name="parent_survey_form_question_id", referencedColumnName="id", nullable=false)
  64.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item","pinpointCampaign:list"})
  65.      */
  66.     public ?SurveyFormQuestion $parentSurveyFormQuestion;
  67.     /**
  68.      * @var int
  69.      *
  70.      * @ORM\Column(name="`rank`",type="integer")
  71.      * @Assert\Type(type="integer")
  72.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  73.      */
  74.     #[ApiProperty(iri'https://schema.org/rank')]
  75.     public $rank 0;
  76.     /**
  77.      * @var string
  78.      *
  79.      * @ORM\Column(type="string", length=2000, nullable=true)
  80.      * @Assert\Length(max="2000")
  81.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  82.      */
  83.     private $info;
  84.     /**
  85.      * @var int
  86.      *
  87.      * @ORM\Column(type="integer")
  88.      * @Assert\Type(type="integer")
  89.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  90.      */
  91.     private $level;
  92.     /**
  93.      * @ORM\Column(type="boolean")
  94.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  95.      */
  96.     private $isRequired;
  97.     /**
  98.      * @var int
  99.      *
  100.      * @ORM\Column(type="integer")
  101.      * @Assert\Type(type="integer")
  102.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  103.      */
  104.     private $maxAnswerSelection;
  105.     /**
  106.      * @var string
  107.      *
  108.      * @ORM\Column(type="string", length=10, nullable=false, columnDefinition="enum('text', 'number', 'percentage')", options={"default": "text"})
  109.      * @Assert\Length(max="15")
  110.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  111.      */
  112.     private $typeRestriction 'text';
  113.     /**
  114.      * @ORM\Column(type="boolean")
  115.      * @Groups({"scsfq:read","scsfq:write","surveyComapany:item", "surveyComapany:write","pinpointCampaign:list"})
  116.      */
  117.     private $isVisible;
  118.     public function __construct()
  119.     {
  120.         $this->rank 0;
  121.         $this->isRequired false;
  122.         $this->isVisible false;
  123.     }
  124.     public function __toString(): string
  125.     {
  126.         return ($this->getSurveyFormQuestion()) ? $this->getSurveyFormQuestion()->getLabel() : '';
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getRank(): ?int
  133.     {
  134.         return $this->rank;
  135.     }
  136.     public function setRank(?int $rank): self
  137.     {
  138.         $this->rank $rank;
  139.         return $this;
  140.     }
  141.     public function getIsRequired(): ?bool
  142.     {
  143.         return $this->isRequired;
  144.     }
  145.     public function setIsRequired(?bool $isRequired): self
  146.     {
  147.         $this->isRequired $isRequired;
  148.         return $this;
  149.     }
  150.     public function getIsVisible(): ?bool
  151.     {
  152.         return $this->isVisible;
  153.     }
  154.     public function setIsVisible(?bool $isVisible): self
  155.     {
  156.         $this->isVisible $isVisible;
  157.         return $this;
  158.     }
  159.     public function getInfo(): ?string
  160.     {
  161.         return $this->info;
  162.     }
  163.     public function setInfo(?string $info): self
  164.     {
  165.         $this->info $info;
  166.         return $this;
  167.     }
  168.     // ##############################################################
  169.     public function getLevel(): ?int
  170.     {
  171.         return $this->level;
  172.     }
  173.     public function setLevel(?int $level): self
  174.     {
  175.         $this->level $level;
  176.         return $this;
  177.     }
  178.     public function getMaxAnswerSelection(): ?int
  179.     {
  180.         return $this->maxAnswerSelection;
  181.     }
  182.     public function setMaxAnswerSelection(?int $maxAnswerSelection): self
  183.     {
  184.         $this->maxAnswerSelection $maxAnswerSelection;
  185.         return $this;
  186.     }
  187.     // ####################################################################################
  188.     public function getTypeRestriction(): ?string
  189.     {
  190.         return $this->typeRestriction;
  191.     }
  192.     public function setTypeRestriction(?string $typeRestriction): self
  193.     {
  194.         $this->typeRestriction $typeRestriction;
  195.         return $this;
  196.     }
  197.     // ##############################################################maxAnswerSelection
  198.     public function getSurveyFormQuestion(): ?SurveyFormQuestion
  199.     {
  200.         return $this->surveyFormQuestion;
  201.     }
  202.     public function setSurveyFormQuestion(?SurveyFormQuestion $surveyFormQuestion): self
  203.     {
  204.         $this->surveyFormQuestion $surveyFormQuestion;
  205.         return $this;
  206.     }
  207.     public function getParentSurveyFormQuestion(): ?SurveyFormQuestion
  208.     {
  209.         return $this->parentSurveyFormQuestion;
  210.     }
  211.     public function setParentSurveyFormQuestion(?SurveyFormQuestion $parentSurveyFormQuestion): self
  212.     {
  213.         $this->parentSurveyFormQuestion $parentSurveyFormQuestion;
  214.         return $this;
  215.     }
  216.     public function getSurveyCompany(): ?SurveyCompany
  217.     {
  218.         return $this->surveyCompany;
  219.     }
  220.     public function setSurveyCompany(?SurveyCompany $surveyCompany): self
  221.     {
  222.         $this->surveyCompany $surveyCompany;
  223.         return $this;
  224.     }
  225.     #[Groups(['scsfq:read''surveyComapany:item'])]
  226.     public function getQuestionType(): string
  227.     {
  228.         return $this->surveyFormQuestion->getType();
  229.     }
  230.     #[Groups(['scsfq:read''surveyComapany:item'])]
  231.     public function getTotalAns(): int
  232.     {
  233.         return $this->surveyFormQuestion->getFormAnswers()->count();
  234.     }
  235. }