<?php
namespace App\Entity;
use App\Repository\IdeaBoxRepository;
use App\Traits\DateTrait;
use DateTime;
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;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=IdeaBoxRepository::class)
*
* @Vich\Uploadable
* @Serializer\ExclusionPolicy("ALL")
*/
class IdeaBox
{
use DateTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups({
* "idea_box:id",
* "idea_box_stats","idea_box_list", "export_idea_box_datatable"
* })
*/
private ?int $id;
/**
* @ORM\OneToMany(targetEntity=IdeaBoxQuestion::class, mappedBy="ideaBox", cascade={"persist", "remove"})
*
* @Expose
* @Groups({
* "idea_box:questions",
* "idea_box_list", "export_idea_box_datatable"
* })
*/
private Collection $questions;
/**
* @ORM\Column(type="boolean")
*
* @Expose
* @Groups({
* "idea_box:enabled",
* "idea_box_list"})
*/
private bool $enabled;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $image;
// Vich Uploader
/**
* @Vich\UploadableField(mapping="idea_box_image", fileNameProperty="image")
* @var File
*/
private $imageFile; // Type non spécifié, veuillez spécifier le type du fichier
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $textBlock;
/**
* @ORM\OneToMany(targetEntity=IdeaBoxRating::class, mappedBy="ideaBox", cascade={"remove"})
*
* @Expose
* @Groups({
* "idea_box:idea_box_rating",
* "export_idea_box_datatable"
* })
*/
private Collection $ideaBoxRatings;
/**
* @ORM\Column(type="string", length=255)
*
* @Expose
* @Groups({
* "idea_box:name",
* "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
* })
*/
private ?string $name;
/**
* @ORM\Column(type="boolean")
*
* @Expose
* @Groups({
* "idea_box:enabled_rating",
* "idea_box_list"
* })
*/
private bool $enabledRating;
/**
* @ORM\Column(type="boolean")
*
* @Expose
* @Groups({
* "idea_box:enabled_questions",
* "idea_box_list"})
*/
private bool $enabledQuestions;
/**
* @ORM\Column(type="integer")
*/
private ?int $minRate;
/**
* @ORM\OneToMany(targetEntity=IdeaBoxRecipient::class, mappedBy="ideaBox", cascade={"remove"})
*
* @Expose
* @Groups({
* "idea_box:idea_box_recipients",
* "export_idea_box_datatable"
* })
*/
private Collection $ideaBoxRecipients;
public function __construct()
{
$this->questions = new ArrayCollection();
$this->ideaBoxRatings = new ArrayCollection();
$this->ideaBoxRecipients = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getQuestions()
{
return $this->questions;
}
public function addQuestion(IdeaBoxQuestion $question): IdeaBox
{
if (!$this->questions->contains($question)) {
$this->questions[] = $question;
$question->setIdeaBox($this);
}
return $this;
}
public function removeQuestion(IdeaBoxQuestion $question): IdeaBox
{
if ($this->questions->removeElement($question)) {
// set the owning side to null (unless already changed)
if ($question->getIdeaBox() === $this) {
$question->setIdeaBox(NULL);
}
}
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): IdeaBox
{
$this->enabled = $enabled;
return $this;
}
public function getImage(): ?string
{
return $this->image ?? NULL;
}
public function setImage(?string $image): IdeaBox
{
$this->image = $image;
return $this;
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File $imageFile
*
* @return void
*/
public function setImageFile(File $imageFile): void
{
$this->imageFile = $imageFile;
if (NULL !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTime();
}
}
public function getTextBlock(): ?string
{
return $this->textBlock;
}
public function setTextBlock(?string $textBlock): IdeaBox
{
$this->textBlock = $textBlock;
return $this;
}
public function getIdeaBoxRatings()
{
return $this->ideaBoxRatings;
}
public function addIdeaBoxRating(IdeaBoxRating $ideaBoxRating): IdeaBox
{
if (!$this->ideaBoxRatings->contains($ideaBoxRating)) {
$this->ideaBoxRatings[] = $ideaBoxRating;
$ideaBoxRating->setIdeaBox($this);
}
return $this;
}
public function removeIdeaBoxRating(IdeaBoxRating $ideaBoxRating): IdeaBox
{
if ($this->ideaBoxRatings->removeElement($ideaBoxRating)) {
// set the owning side to null (unless already changed)
if ($ideaBoxRating->getIdeaBox() === $this) {
$ideaBoxRating->setIdeaBox(NULL);
}
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): IdeaBox
{
$this->name = $name;
return $this;
}
public function isEnabledRating(): ?bool
{
return $this->enabledRating;
}
public function setEnabledRating(bool $enabledRating): IdeaBox
{
$this->enabledRating = $enabledRating;
return $this;
}
public function isEnabledQuestions(): ?bool
{
return $this->enabledQuestions;
}
public function setEnabledQuestions(bool $enabledQuestions): IdeaBox
{
$this->enabledQuestions = $enabledQuestions;
return $this;
}
public function getMinRate(): ?int
{
return $this->minRate;
}
public function setMinRate(?int $minRate): IdeaBox
{
$this->minRate = $minRate ?? 0;
return $this;
}
public function getIdeaBoxRecipients()
{
return $this->ideaBoxRecipients;
}
public function addIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): IdeaBox
{
if (!$this->ideaBoxRecipients->contains($ideaBoxRecipient)) {
$this->ideaBoxRecipients[] = $ideaBoxRecipient;
$ideaBoxRecipient->setIdeaBox($this);
}
return $this;
}
public function removeIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): IdeaBox
{
if ($this->ideaBoxRecipients->removeElement($ideaBoxRecipient)) {
// set the owning side to null (unless already changed)
if ($ideaBoxRecipient->getIdeaBox() === $this) {
$ideaBoxRecipient->setIdeaBox(NULL);
}
}
return $this;
}
/**
* @return int
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("questions_nbr")
*
* @Expose()
* @Groups({"idea_box:questions_nbr", "idea_box_list"})
*/
public function getIdeaBoxQuestionNbr(): int
{
return count($this->questions);
}
}