src/Entity/SatisfactionSurveys/SatisfactionSurvey.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Entity\SatisfactionSurveys;
  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\SearchFilter;
  7. use App\Annotation\SatisfactionSurveyAware;
  8. use App\Annotation\SiteAware;
  9. use App\Entity\AbstractBase;
  10. use App\Entity\Interfaces\SiteInterface;
  11. use App\Entity\Traits\ActiveTrait;
  12. use App\Entity\Traits\NameTrait;
  13. use App\Entity\Traits\SiteTrait;
  14. use App\Enum\SiteEnum;
  15. use App\Repository\SatisfactionSurveys\SatisfactionSurveyRepository;
  16. use DateTimeImmutable;
  17. use DateTimeInterface;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Doctrine\Common\Collections\Collection;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Gedmo\Mapping\Annotation as Gedmo;
  22. use Symfony\Component\Serializer\Annotation\Groups;
  23. use Symfony\Component\Serializer\Annotation\SerializedName;
  24. /**
  25.  * @ApiResource(
  26.  *     shortName="satisfaction-survey",
  27.  *     normalizationContext={"groups"={"api:read", "satisfaction_survey:read"}, "swagger_definition_name"="Read"},
  28.  *     denormalizationContext={"groups"={"satisfaction_survey:write"}, "swagger_definition_name"="Write"},
  29.  *     collectionOperations={"get"},
  30.  *     itemOperations={"get", "put"}
  31.  * )
  32.  * @ApiFilter(SearchFilter::class, properties={"name": "exact"})
  33.  * @ORM\Table(name="vulco_satisfaction_survey", indexes={@ORM\Index(name="satisfaction_survey_site_idx", columns={"site"})})
  34.  * @ORM\Entity(repositoryClass=SatisfactionSurveyRepository::class)
  35.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  36.  * @SatisfactionSurveyAware(satisfactionSurveyFieldName="id")
  37.  * @SiteAware(siteFieldName="site")
  38.  */
  39. class SatisfactionSurvey extends AbstractBase implements SiteInterface
  40. {
  41.     use ActiveTrait;
  42.     use NameTrait;
  43.     use SiteTrait;
  44.     public const DEFAULT_ES_NAME '0000-ES-default-satisfaction-survey-name';
  45.     public const DEFAULT_PT_NAME '0000-PT-default-satisfaction-survey-name';
  46.     /**
  47.      * @ApiProperty(identifier=false)
  48.      * @ORM\Id
  49.      * @ORM\GeneratedValue
  50.      * @ORM\Column(type="integer")
  51.      * @Groups({"api:read", "api:write"})
  52.      */
  53.     protected int $id;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity="SatisfactionSurveyQuestion", mappedBy="survey", cascade={"persist", "remove"})
  56.      */
  57.     private ?Collection $questions;
  58.     /**
  59.      * @ORM\Column(type="date", nullable=true)
  60.      */
  61.     private ?DateTimeInterface $begin;
  62.     /**
  63.      * @ApiProperty(identifier=true)
  64.      * @ORM\Column(type="string", length=255, nullable=false, unique=true)
  65.      * @Groups({"satisfaction_survey:read"})
  66.      */
  67.     private string $name '';
  68.     /**
  69.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  70.      * @Groups({"satisfaction_survey:read"})
  71.      */
  72.     private bool $hasCustomerCommentsEnabled true;
  73.     /**
  74.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  75.      * @Groups({"satisfaction_survey:read"})
  76.      */
  77.     private bool $hasHowDidYouFindUsQuestionEnabled true;
  78.     /**
  79.      * @ORM\Column(type="text", length=10000, nullable=false)
  80.      * @Groups({"satisfaction_survey:read"})
  81.      */
  82.     private string $customerCommentsTextHelper '';
  83.     /**
  84.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  85.      */
  86.     private bool $active true;
  87.     public function __construct()
  88.     {
  89.         $this->questions = new ArrayCollection();
  90.         $this->begin = new DateTimeImmutable();
  91.     }
  92.     public static function getNameByLocale(string $locale): string
  93.     {
  94.         $result self::DEFAULT_ES_NAME;
  95.         if (strtolower($locale) === strtolower(SiteEnum::SITE_STR_PT)) {
  96.             $result self::DEFAULT_PT_NAME;
  97.         }
  98.         return $result;
  99.     }
  100.     public function getQuestions(): ?Collection
  101.     {
  102.         return $this->questions;
  103.     }
  104.     /**
  105.      * @Groups({"satisfaction_survey:read"})
  106.      * @SerializedName("questions")
  107.      */
  108.     public function getActiveQuestionsSortedByPosition(): array
  109.     {
  110.         $result = [];
  111.         if (count($this->getQuestions()) > 0) {
  112.             /** @var SatisfactionSurveyQuestion $question */
  113.             foreach ($this->getQuestions() as $question) {
  114.                 if ($question->isActive()) {
  115.                     $result[] = $question;
  116.                 }
  117.             }
  118.             usort($result, static fn (SatisfactionSurveyQuestion $aSatisfactionSurveyQuestion $b) => strcmp($a->getPosition(), $b->getPosition()));
  119.         }
  120.         return $result;
  121.     }
  122.     public function setQuestions(?Collection $questions): self
  123.     {
  124.         $this->questions $questions;
  125.         return $this;
  126.     }
  127.     public function addQuestion(SatisfactionSurveyQuestion $question): self
  128.     {
  129.         if (!$this->questions->contains($question)) {
  130.             $question->setSurvey($this);
  131.             $this->questions->add($question);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeQuestion(SatisfactionSurveyQuestion $question): self
  136.     {
  137.         if ($this->questions->contains($question)) {
  138.             $this->questions->removeElement($question);
  139.         }
  140.         return $this;
  141.     }
  142.     public function getBegin(): ?DateTimeInterface
  143.     {
  144.         return $this->begin;
  145.     }
  146.     public function setBegin(?DateTimeInterface $begin): self
  147.     {
  148.         $this->begin $begin;
  149.         return $this;
  150.     }
  151.     public function isHasCustomerCommentsEnabled(): bool
  152.     {
  153.         return $this->hasCustomerCommentsEnabled;
  154.     }
  155.     public function getHasCustomerCommentsEnabled(): bool
  156.     {
  157.         return $this->isHasCustomerCommentsEnabled();
  158.     }
  159.     public function setHasCustomerCommentsEnabled(bool $hasCustomerCommentsEnabled): self
  160.     {
  161.         $this->hasCustomerCommentsEnabled $hasCustomerCommentsEnabled;
  162.         return $this;
  163.     }
  164.     public function isHasHowDidYouFindUsQuestionEnabled(): bool
  165.     {
  166.         return $this->hasHowDidYouFindUsQuestionEnabled;
  167.     }
  168.     public function getHasHowDidYouFindUsQuestionEnabled(): bool
  169.     {
  170.         return $this->isHasHowDidYouFindUsQuestionEnabled();
  171.     }
  172.     public function setHasHowDidYouFindUsQuestionEnabled(bool $hasHowDidYouFindUsQuestionEnabled): self
  173.     {
  174.         $this->hasHowDidYouFindUsQuestionEnabled $hasHowDidYouFindUsQuestionEnabled;
  175.         return $this;
  176.     }
  177.     public function getCustomerCommentsTextHelper(): string
  178.     {
  179.         return $this->customerCommentsTextHelper;
  180.     }
  181.     public function setCustomerCommentsTextHelper(string $customerCommentsTextHelper): self
  182.     {
  183.         $this->customerCommentsTextHelper $customerCommentsTextHelper;
  184.         return $this;
  185.     }
  186. }