<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\AnswerRepository;
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;
/**
* @ORM\Entity(repositoryClass=AnswerRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"answer:read"}
* },
* denormalizationContext={
* "groups"={"answer:write"}
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_USER') or is_granted('ROLE_ADMIN')"
* },
* "post"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* },
* itemOperations={
* "get"={
* "security"="is_granted('ROLE_USER') or is_granted('ROLE_ADMIN')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "patch"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "name": "partial", "type": "exact", "question.id": "exact", "category.id": "exact", "status": "exact", "active"})
* @ApiFilter(OrderFilter::class, properties={"id", "name", "question.id", "tvTag.id", "tvTag.name", "active", "rank"})
* @ApiFilter(GroupFilter::class, arguments={
* "parameterName": "groups",
* "overrideDefaultGroups": true
* })
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class Answer
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"answer:read:id", "answer:read", "survey:read", "question:read", "answer_list", "teamplay_challenge:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"answer:read:name", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $name;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=Question::class, inversedBy="answers", cascade={"persist", "refresh"})
* @ORM\JoinColumn(nullable=false)
* @Groups({"answer:read:question", "answer:read", "answer:write", "answer_recommended_objectives_edit"})
*/
private $question;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"answer:read:value", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $value = null;
/**
* @ORM\Column(name="`rank`", type="integer", options={"default": "999"})
* @Groups({"answer:read:rank", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $rank = 999;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"answer:read:active", "answer:read", "answer:write", "survey:read", "question:read", "answer_list", "survey_vitality_front", "answer_recommended_objectives_edit", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $active = 1;
/**
* @ORM\ManyToOne(targetEntity=Program::class)
* @Groups({"answer:read:program", "answer:write"})
*/
private $program = null;
/**
* @ORM\ManyToOne(targetEntity=Objective::class)
* @Groups({"answer:read:recommendedObjective"})
*/
private $recommendedObjective = null;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"answer:read:description", "answer:read", "answer:write", "survey:read", "question:read", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $description;
/**
* Custom fields
* @var bool|null
* @Groups({"answer:read:selectedByUser", "answer:read", "answer:write", "survey:read", "question:read", "teamplay_challenge:write", "teamplay_challenge:read"})
*/
private $selectedByUser = null;
public function __clone()
{
$this->id = null;
$this->rank = 999;
$this->active = 1;
$this->program = null;
$this->recommendedObjective = null;
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): self
{
$this->id = $id;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getQuestion(): ?Question
{
return $this->question;
}
public function setQuestion(?Question $question): self
{
$this->question = $question;
return $this;
}
public function getValue(): ?int
{
return $this->value;
}
public function setValue(?int $value): self
{
$this->value = $value;
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(int $rank): self
{
$this->rank = $rank;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getProgram(): ?Program
{
return $this->program;
}
public function setProgram(?Program $program): self
{
$this->program = $program;
return $this;
}
public function getRecommendedObjective(): ?Objective
{
return $this->recommendedObjective;
}
public function setRecommendedObjective(?Objective $recommendedObjective): self
{
$this->recommendedObjective = $recommendedObjective;
return $this;
}
/**
* @return Collection|Video[]
* @Groups({"answer:read:videos", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
*/
public function getVideos(): ?Collection
{
if(!$this->recommendedObjective instanceof Objective) return null;
return $this->recommendedObjective->getVideos();
}
/**
* @return Collection|Program[]
* @Groups({"answer:read:programs", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
*/
public function getPrograms(): ?Collection
{
if(!$this->recommendedObjective instanceof Objective) return null;
return $this->recommendedObjective->getPrograms();
}
/**
* @return Collection|Channel[]
* @Groups({"answer:read:channels", "answer_recommended_objectives", "answer_recommended_objectives_edit"})
*/
public function getChannels(): ?Collection
{
if(!$this->recommendedObjective instanceof Objective) return null;
return $this->recommendedObjective->getChannels();
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getSelectedByUser(): ?bool
{
return $this->selectedByUser;
}
public function isSelectedByUser(): ?bool
{
return $this->selectedByUser;
}
public function setSelectedByUser(?bool $selectedByUser): self
{
$this->selectedByUser = $selectedByUser;
return $this;
}
}