<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Enum\CompanyFormQuestionType;
use App\Validator as AppAssert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyInformationQuestionRepository")
* @AppAssert\CompanyInformationQuestionOther()
*/
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['companyInformationQuestion:read']],
denormalizationContext: ['groups' => ['companyInformationQuestion:write']],
collectionOperations: [
'get',
'post' => [
'security' => "is_granted('ROLE_ADMIN')",
],
],
itemOperations: [
'get',
'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
],
)]
class CompanyInformationQuestion
{
use TimestampableEntity;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var CompanyInformationGroup
*
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyInformationGroup", inversedBy="informationQuestions")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $informationGroup;
/**
* @var CompanyFormQuestion
*
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyFormQuestion")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $formQuestion;
/**
* @var string
*
* @ORM\Column(type="text", nullable=true)
* @Groups({"companyInformationQuestion:read", "companyInformationQuestion:write"})
*/
private $value;
/**
* @var CompanyFormAnswer
*
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyFormAnswer")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $formAnswer;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="App\Entity\CompanyFormAnswer")
*/
private $formAnswers;
/**
* @var string
*
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $daysOffType;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $affinityGroups;
/**
* @var bool
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $affinityGroupsChampion;
/**
* CompanyInformationQuestion constructor.
*/
public function __construct()
{
$this->formAnswers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getValue(): ?string
{
return $this->value;
}
public function setValue(?string $value): self
{
$this->value = $value;
return $this;
}
public function getInformationGroup(): ?CompanyInformationGroup
{
return $this->informationGroup;
}
public function setInformationGroup(?CompanyInformationGroup $informationGroup): self
{
$this->informationGroup = $informationGroup;
return $this;
}
public function addFormAnswer(CompanyFormAnswer $formAnswer): self
{
if (!$this->formAnswers->contains($formAnswer)) {
$this->formAnswers[] = $formAnswer;
}
return $this;
}
public function removeFormAnswer(CompanyFormAnswer $formAnswer): self
{
if ($this->formAnswers->contains($formAnswer)) {
$this->formAnswers->removeElement($formAnswer);
}
return $this;
}
public function isAnswered(): bool
{
$type = $this->getFormQuestion()->getType();
if (in_array($type, [CompanyFormQuestionType::TEXT, CompanyFormQuestionType::TEXTAREA, CompanyFormQuestionType::SLIDER, CompanyFormQuestionType::WEEKS, CompanyFormQuestionType::DAYS, CompanyFormQuestionType::DAYS_OFF])) {
return false === empty($this->value);
} elseif (in_array($type, [CompanyFormQuestionType::CHOICE_UNIQUE_EXPANDED, CompanyFormQuestionType::CHOICE_UNIQUE_COLLAPSED])) {
return null !== $this->getFormAnswer();
} elseif (in_array($type, [CompanyFormQuestionType::CHOICE_MULTIPLE_EXPANDED, CompanyFormQuestionType::CHOICE_MULTIPLE_COLLAPSED])) {
return false === $this->getFormAnswers()->isEmpty();
} elseif (in_array($type, [CompanyFormQuestionType::AFFINITY_GROUPS])) {
return true === $this->getAffinityGroups() || true === $this->getAffinityGroupsChampion();
}
return false;
}
public function getFormQuestion(): ?CompanyFormQuestion
{
return $this->formQuestion;
}
public function setFormQuestion(?CompanyFormQuestion $formQuestion): self
{
$this->formQuestion = $formQuestion;
return $this;
}
public function getFormAnswer(): ?CompanyFormAnswer
{
return $this->formAnswer;
}
public function setFormAnswer(?CompanyFormAnswer $formAnswer): self
{
$this->formAnswer = $formAnswer;
return $this;
}
/**
* @return Collection|CompanyFormAnswer[]
*/
public function getFormAnswers(): Collection
{
return $this->formAnswers;
}
public function getDaysOffType(): ?string
{
return $this->daysOffType;
}
public function setDaysOffType(?string $daysOffType): self
{
$this->daysOffType = $daysOffType;
return $this;
}
public function getAffinityGroups(): ?bool
{
return $this->affinityGroups;
}
public function setAffinityGroups(?bool $affinityGroups): self
{
$this->affinityGroups = $affinityGroups;
return $this;
}
public function getAffinityGroupsChampion(): ?bool
{
return $this->affinityGroupsChampion;
}
public function setAffinityGroupsChampion(?bool $affinityGroupsChampion): self
{
$this->affinityGroupsChampion = $affinityGroupsChampion;
return $this;
}
}