<?php
namespace App\Entity\Survey;
use App\Entity\PrimaryIdTrait;
use App\Entity\User\User;
use App\Repository\Survey\SurveyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: SurveyRepository::class)]
class Survey
{
public const ROUTE_NAME_CREATE = 'SURVEY_CREATE';
public const ROUTE_NAME_EDIT = 'SURVEY_EDIT';
public const ROUTE_NAME_DETAIL = 'SURVEY_DETAIL';
public const ROUTE_NAME_DELETE = 'SURVEY_DELETE';
public const OPEN = 1;
public const CLOSE = 0;
public const TYPE_PRIVATE = 0;
public const TYPE_PUBLIC = 1;
public const REFRESH_ENABLED = 1;
public const REFRESH_DISABLED = 0;
public const STATUS = [
self::OPEN => 'survey.status.open',
self::CLOSE => 'survey.status.close',
];
public const TYPES = [
self::TYPE_PUBLIC => 'survey.type.public',
self::TYPE_PRIVATE => 'survey.type.private'
];
public const REFRESHES = [
self::REFRESH_ENABLED => 'survey.refresh.enabled',
self::REFRESH_DISABLED => 'survey.refresh.disabled'
];
public const RESULT_MYSELF_YES = true;
public const RESULT_MYSELF_NO = false;
public const RESULT_MYSELF = [
self::RESULT_MYSELF_YES => 'survey.resultMyself.yes',
self::RESULT_MYSELF_NO => 'survey.resultMyself.no'
];
public const NOTIFICATION_DAY_MONDAY = 1;
public const NOTIFICATION_DAY_TUESDAY = 2;
public const NOTIFICATION_DAY_WEDNESDAY = 3;
public const NOTIFICATION_DAY_THURSDAY = 4;
public const NOTIFICATION_DAY_FRIDAY = 5;
public const NOTIFICATION_DAY_SATURDAY = 6;
public const NOTIFICATION_DAY_SUNDAY = 7;
public const NOTIFICATION_DAYS = [
self::NOTIFICATION_DAY_MONDAY => 'survey.notificationDays.monday',
self::NOTIFICATION_DAY_TUESDAY => 'survey.notificationDays.tuesday',
self::NOTIFICATION_DAY_WEDNESDAY => 'survey.notificationDays.wednesday',
self::NOTIFICATION_DAY_THURSDAY => 'survey.notificationDays.thursday',
self::NOTIFICATION_DAY_FRIDAY => 'survey.notificationDays.friday',
self::NOTIFICATION_DAY_SATURDAY => 'survey.notificationDays.saturday',
self::NOTIFICATION_DAY_SUNDAY => 'survey.notificationDays.sunday',
];
public const NOTIFICATION_AFTER_EACH_YES = true;
public const NOTIFICATION_AFTER_EACH_NO = false;
public const NOTIFICATION_AFTER_EACH = [
self::NOTIFICATION_AFTER_EACH_NO => 'survey.notificationAfterEach.no',
self::NOTIFICATION_AFTER_EACH_YES => 'survey.notificationAfterEach.yes'
];
public const NOTIFICATION_APPOINTED_TIME_YES = true;
public const NOTIFICATION_APPOINTED_TIME_NO = false;
public const NOTIFICATION_APPOINTED_TIME = [
self::NOTIFICATION_APPOINTED_TIME_NO => 'survey.notificationAppointedTime.no',
self::NOTIFICATION_APPOINTED_TIME_YES => 'survey.notificationAppointedTime.yes'
];
public const TIMER_NO = false;
public const TIMER_YES = true;
public const TIMER = [
self::TIMER_NO => 'survey.timer.no',
self::TIMER_YES => 'survey.timer.yes'
];
use PrimaryIdTrait;
use TimestampableEntity;
#[ORM\Column(type: 'string', unique: true)]
private string $uri;
#[ORM\Column(type: 'string')]
#[Groups(['survey'])]
private string $title;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['survey'])]
private ?string $description;
#[ORM\Column(type: 'integer')]
private int $status;
#[ORM\Column(type: 'integer')]
#[Groups(['survey', 'childrenQuestions'])]
private int $type;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $validStart;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $validEnd;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\SurveyQuestion', mappedBy: 'survey', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['sort' => 'ASC'])]
#[Groups(['survey'])]
public $surveyQuestion;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\SurveyResult', mappedBy: 'survey', cascade: ['remove'])]
#[ORM\OrderBy(['createdAt' => 'DESC'])]
public $surveyResult;
/**
* @var User
*/
#[ORM\ManyToOne(targetEntity: 'App\Entity\User\User', inversedBy: 'survey')]
private $author;
#[ORM\OneToMany(targetEntity: 'App\Entity\Survey\SurveyNotification', mappedBy: 'survey', cascade: ['persist', 'remove'], orphanRemoval: true)]
public $surveyNotification;
#[ORM\Column(type: 'integer')]
#[Groups(['survey'])]
private int $refresh;
#[ORM\Column(type: 'boolean')]
private bool $resultMyself;
#[ORM\Column(type: 'boolean')]
private bool $notificationAfterEach;
#[ORM\Column(type: 'boolean')]
private bool $notificationAppointedTime;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $notificationDate;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $systemDate;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $resultFilterStartInNotification;
#[ORM\Column(type: 'datetime', nullable: true)]
protected ?\DateTime $resultFilterEndInNotification;
#[ORM\Column(type: 'boolean')]
#[Groups(['survey', 'childrenQuestions'])]
private bool $timer;
#[ORM\Column(type: 'integer', nullable: true)]
#[Groups(['survey', 'childrenQuestions'])]
protected ?int $timerTime;
public function __construct()
{
$this->surveyQuestion = new ArrayCollection();
$this->surveyResult = new ArrayCollection();
$this->surveyNotification = new ArrayCollection();
}
public function getUri(): string
{
return $this->uri;
}
public function setUri(?string $uri): void
{
$this->uri = $uri;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getStatus(): int
{
return $this->status;
}
public function setStatus(int $status): void
{
$this->status = $status;
}
public function getValidStart(): ?\DateTime
{
return $this->validStart;
}
public function setValidStart(?\DateTime $validStart): void
{
$this->validStart = $validStart;
}
public function getValidEnd(): ?\DateTime
{
return $this->validEnd;
}
public function setValidEnd(?\DateTime $validEnd): void
{
$this->validEnd = $validEnd;
}
/**
* @return Collection|SurveyQuestion[]
*/
public function getSurveyQuestion(): Collection
{
return $this->surveyQuestion;
}
public function addSurveyQuestion(SurveyQuestion $surveyQuestion): void
{
$surveyQuestion->setSurvey($this);
$this->surveyQuestion->add($surveyQuestion);
}
public function removeSurveyQuestion(SurveyQuestion $surveyQuestion): void
{
if ($this->surveyQuestion->contains($surveyQuestion)) {
$this->surveyQuestion->removeElement($surveyQuestion);
}
}
/**
* @return Collection|SurveyResult[]
*/
public function getSurveyResult(): Collection
{
return $this->surveyResult;
}
/**
* @return User
*/
public function getAuthor(): ?User
{
return $this->author;
}
/**
* @param User $author
*/
public function setAuthor(User $author): void
{
$this->author = $author;
}
/**
* @return Collection|SurveyNotification[]
*/
public function getSurveyNotification(): Collection
{
return $this->surveyNotification;
}
public function addSurveyNotification(SurveyNotification $surveyNotification): void
{
$surveyNotification->setSurvey($this);
$this->surveyNotification->add($surveyNotification);
}
public function removeSurveyNotification(SurveyNotification $surveyNotification): void
{
if ($this->surveyNotification->contains($surveyNotification)) {
$this->surveyNotification->removeElement($surveyNotification);
}
}
public function getType(): int
{
return $this->type;
}
public function setType(int $type): void
{
$this->type = $type;
}
public function getRefresh(): int
{
return $this->refresh;
}
public function setRefresh(int $refresh): void
{
$this->refresh = $refresh;
}
public function getResultMyself(): bool
{
return $this->resultMyself;
}
public function setResultMyself(bool $resultMyself): void
{
$this->resultMyself = $resultMyself;
}
public function getNotificationAfterEach(): bool
{
return $this->notificationAfterEach;
}
public function setNotificationAfterEach(bool $notificationAfterEach): void
{
$this->notificationAfterEach = $notificationAfterEach;
}
public function getNotificationAppointedTime(): bool
{
return $this->notificationAppointedTime;
}
public function setNotificationAppointedTime(bool $notificationAppointedTime): void
{
$this->notificationAppointedTime = $notificationAppointedTime;
}
public function getNotificationDate(): ?\DateTime
{
return $this->notificationDate;
}
public function setNotificationDate(?\DateTime $notificationDate): void
{
$this->notificationDate = $notificationDate;
}
public function getSystemDate(): ?\DateTime
{
return $this->systemDate;
}
public function setSystemDate(?\DateTime $systemDate): void
{
$this->systemDate = $systemDate;
}
public function getResultFilterStartInNotification(): ?\DateTime
{
return $this->resultFilterStartInNotification;
}
public function setResultFilterStartInNotification(?\DateTime $resultFilterStartInNotification): void
{
$this->resultFilterStartInNotification = $resultFilterStartInNotification;
}
public function getResultFilterEndInNotification(): ?\DateTime
{
return $this->resultFilterEndInNotification;
}
public function setResultFilterEndInNotification(?\DateTime $resultFilterEndInNotification): void
{
$this->resultFilterEndInNotification = $resultFilterEndInNotification;
}
public function getTimer(): bool
{
return $this->timer;
}
public function setTimer(bool $timer): void
{
$this->timer = $timer;
}
public function getTimerTime(): ?int
{
return $this->timerTime;
}
public function setTimerTime(?int $timerTime): void
{
$this->timerTime = $timerTime;
}
}