src/Entity/SatisfactionSurveys/SatisfactionSurveyQuestion.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity\SatisfactionSurveys;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Annotation\SatisfactionSurveyAware;
  5. use App\Annotation\SiteAware;
  6. use App\Entity\AbstractBase;
  7. use App\Entity\Interfaces\SiteInterface;
  8. use App\Entity\Traits\ActiveTrait;
  9. use App\Entity\Traits\PositionTrait;
  10. use App\Entity\Traits\SiteTrait;
  11. use App\Entity\User;
  12. use App\Repository\SatisfactionSurveys\SatisfactionSurveyQuestionRepository;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. /**
  19.  * @ApiResource(
  20.  *     shortName="satisfaction-survey-question",
  21.  *     normalizationContext={"groups"={"api:read", "satisfaction_survey_question:read"}, "swagger_definition_name"="Read"},
  22.  *     denormalizationContext={"groups"={"satisfaction_survey_question:write"}, "swagger_definition_name"="Write"},
  23.  *     collectionOperations={"get"},
  24.  *     itemOperations={"get", "put"}
  25.  * )
  26.  * @ORM\Table(name="vulco_satisfaction_survey_question", indexes={@ORM\Index(name="satisfaction_survey_question_site_idx", columns={"site"})})
  27.  * @ORM\Entity(repositoryClass=SatisfactionSurveyQuestionRepository::class)
  28.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  29.  * @SatisfactionSurveyAware(satisfactionSurveyFieldName="survey_id")
  30.  * @SiteAware(siteFieldName="site")
  31.  */
  32. class SatisfactionSurveyQuestion extends AbstractBase implements SiteInterface
  33. {
  34.     use ActiveTrait;
  35.     use SiteTrait;
  36.     use PositionTrait;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="SatisfactionSurvey", inversedBy="questions")
  39.      * @Groups({"satisfaction_survey_question:read"})
  40.      */
  41.     private SatisfactionSurvey $survey;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity="SatisfactionSurveyCustomerResponseAnswer", mappedBy="question")
  44.      */
  45.     private ?Collection $answers;
  46.     /**
  47.      * @ORM\Column(type="string", length=1024, nullable=false)
  48.      * @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
  49.      */
  50.     private string $question;
  51.     /**
  52.      * @ORM\Column(type="integer", nullable=false, options={"default": 1})
  53.      * @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
  54.      */
  55.     private int $position 1;
  56.     /**
  57.      * @ORM\Column(type="integer", nullable=false, options={"default": 0})
  58.      */
  59.     private int $type 0;
  60.     /**
  61.      * @ORM\Column(type="boolean", nullable=false, options={"default": 1})
  62.      * @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
  63.      */
  64.     private bool $active true;
  65.     public function __construct()
  66.     {
  67.         $this->answers = new ArrayCollection();
  68.     }
  69.     public function getSurvey(): SatisfactionSurvey
  70.     {
  71.         return $this->survey;
  72.     }
  73.     public function setSurvey(SatisfactionSurvey $survey): self
  74.     {
  75.         $this->survey $survey;
  76.         return $this;
  77.     }
  78.     public function getAnswers(): ?Collection
  79.     {
  80.         return $this->answers;
  81.     }
  82.     public function getAnswersByGarageOwner(User $owner): ?array
  83.     {
  84.         $result = [];
  85.         /** @var SatisfactionSurveyCustomerResponseAnswer $answer */
  86.         foreach ($this->getAnswers() as $answer) {
  87.             if ($answer->getResponse()->getGarage() && $answer->getResponse()->getGarage()->getOwner()->getId() === $owner->getId()) {
  88.                 $result[] = $answer;
  89.             }
  90.         }
  91.         return $result;
  92.     }
  93.     public function setAnswers(?Collection $answers): self
  94.     {
  95.         $this->answers $answers;
  96.         return $this;
  97.     }
  98.     public function getQuestion(): string
  99.     {
  100.         return $this->question;
  101.     }
  102.     public function setQuestion(string $question): self
  103.     {
  104.         $this->question $question;
  105.         return $this;
  106.     }
  107.     public function getType(): int
  108.     {
  109.         return $this->type;
  110.     }
  111.     public function setType(int $type): self
  112.     {
  113.         $this->type $type;
  114.         return $this;
  115.     }
  116. }