<?php
namespace App\Entity\SatisfactionSurveys;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Annotation\SatisfactionSurveyAware;
use App\Annotation\SiteAware;
use App\Entity\AbstractBase;
use App\Entity\Interfaces\SiteInterface;
use App\Entity\Traits\ActiveTrait;
use App\Entity\Traits\PositionTrait;
use App\Entity\Traits\SiteTrait;
use App\Entity\User;
use App\Repository\SatisfactionSurveys\SatisfactionSurveyQuestionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* shortName="satisfaction-survey-question",
* normalizationContext={"groups"={"api:read", "satisfaction_survey_question:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"satisfaction_survey_question:write"}, "swagger_definition_name"="Write"},
* collectionOperations={"get"},
* itemOperations={"get", "put"}
* )
* @ORM\Table(name="vulco_satisfaction_survey_question", indexes={@ORM\Index(name="satisfaction_survey_question_site_idx", columns={"site"})})
* @ORM\Entity(repositoryClass=SatisfactionSurveyQuestionRepository::class)
* @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
* @SatisfactionSurveyAware(satisfactionSurveyFieldName="survey_id")
* @SiteAware(siteFieldName="site")
*/
class SatisfactionSurveyQuestion extends AbstractBase implements SiteInterface
{
use ActiveTrait;
use SiteTrait;
use PositionTrait;
/**
* @ORM\ManyToOne(targetEntity="SatisfactionSurvey", inversedBy="questions")
* @Groups({"satisfaction_survey_question:read"})
*/
private SatisfactionSurvey $survey;
/**
* @ORM\OneToMany(targetEntity="SatisfactionSurveyCustomerResponseAnswer", mappedBy="question")
*/
private ?Collection $answers;
/**
* @ORM\Column(type="string", length=1024, nullable=false)
* @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
*/
private string $question;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 1})
* @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
*/
private int $position = 1;
/**
* @ORM\Column(type="integer", nullable=false, options={"default": 0})
*/
private int $type = 0;
/**
* @ORM\Column(type="boolean", nullable=false, options={"default": 1})
* @Groups({"satisfaction_survey_question:read", "satisfaction_survey:read"})
*/
private bool $active = true;
public function __construct()
{
$this->answers = new ArrayCollection();
}
public function getSurvey(): SatisfactionSurvey
{
return $this->survey;
}
public function setSurvey(SatisfactionSurvey $survey): self
{
$this->survey = $survey;
return $this;
}
public function getAnswers(): ?Collection
{
return $this->answers;
}
public function getAnswersByGarageOwner(User $owner): ?array
{
$result = [];
/** @var SatisfactionSurveyCustomerResponseAnswer $answer */
foreach ($this->getAnswers() as $answer) {
if ($answer->getResponse()->getGarage() && $answer->getResponse()->getGarage()->getOwner()->getId() === $owner->getId()) {
$result[] = $answer;
}
}
return $result;
}
public function setAnswers(?Collection $answers): self
{
$this->answers = $answers;
return $this;
}
public function getQuestion(): string
{
return $this->question;
}
public function setQuestion(string $question): self
{
$this->question = $question;
return $this;
}
public function getType(): int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
}