<?php
namespace App\Entity;
use App\Repository\QuizRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=QuizRepository::class)
*
* @Serializer\ExclusionPolicy("ALL")
*/
class Quiz
{
const STATUS_CLOSED = 0; // Quiz is not viewable by user
const STATUS_OPENED = 1; // Quiz is answerable ( = writable)
const STATUS_FINISHED = 2; // Quiz is viewable ( = read only)
const STATUS = [
'fermé' => Quiz::STATUS_CLOSED,
'ouvert' => Quiz::STATUS_OPENED,
'terminé' => Quiz::STATUS_FINISHED,
];
const RANDOM = [
'non' => FALSE,
'oui' => TRUE,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose()
* @Groups({ "quiz" })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose()
* @Groups({ "quiz" })
*/
private ?string $name;
/**
* @ORM\Column(type="text", nullable=true)
*
* @Expose()
* @Groups({ "quiz" })
*/
private ?string $description;
/**
* @ORM\Column(type="boolean", nullable=true)
*
* @Expose()
* @Groups({ "quiz" })
*/
private ?bool $isRandom;
/**
* @ORM\Column(type="integer", options={"default":0})
*
* @Expose()
* @Groups({ "quiz" })
*/
private int $status = 0;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @Expose()
* @Groups({ "quiz" })
*/
private ?DateTimeInterface $dateStart;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @Expose()
* @Groups({ "quiz" })
*/
private ?DateTimeInterface $dateEnd;
/**
* @ORM\OneToMany(targetEntity=QuizQuestion::class, mappedBy="quiz", cascade={"remove", "persist"})
* @ORM\OrderBy({"orderIndex" = "ASC"})
*/
private $quizQuestions;
public function __construct()
{
$this->quizQuestions = new ArrayCollection();
}
/**
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("questions_nbr")
*
* @Expose
* @Groups({ "quiz" })
*/
public function getQuestionNumber(): int
{
return count($this->getQuizQuestions());
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName( string $name ): Quiz
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription( ?string $description ): Quiz
{
$this->description = $description;
return $this;
}
public function getIsRandom(): ?bool
{
return $this->isRandom;
}
public function setIsRandom( ?bool $isRandom ): Quiz
{
$this->isRandom = $isRandom;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus( int $status ): Quiz
{
$this->status = $status;
return $this;
}
public function getDateStart(): ?DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart( ?DateTimeInterface $dateStart ): Quiz
{
$this->dateStart = $dateStart;
return $this;
}
public function getDateEnd(): ?DateTimeInterface
{
return $this->dateEnd;
}
public function setDateEnd( ?DateTimeInterface $dateEnd ): Quiz
{
$this->dateEnd = $dateEnd;
return $this;
}
public function getQuizQuestions(): Collection
{
return $this->quizQuestions;
}
public function addQuizQuestion( QuizQuestion $quizQuestion ): Quiz
{
if ( !$this->quizQuestions->contains( $quizQuestion ) ) {
$this->quizQuestions[] = $quizQuestion;
$quizQuestion->setQuiz( $this );
}
return $this;
}
public function removeQuizQuestion( QuizQuestion $quizQuestion ): Quiz
{
if ( $this->quizQuestions->removeElement( $quizQuestion ) ) {
// set the owning side to null (unless already changed)
if ( $quizQuestion->getQuiz() === $this ) {
$quizQuestion->setQuiz( NULL );
}
}
return $this;
}
}