<?php
namespace App\Entity;
use App\Repository\ChildPreferenceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=ChildPreferenceRepository::class)
* @ORM\Table(name="child_preference", indexes={
* @ORM\Index(name="cp_assigned_from_status_created_at_idx", columns={"assigned_from", "status", "created_at"}),
* @ORM\Index(name="cp_assigned_at_idx", columns={"assigned_at"}),
* @ORM\Index(name="cp_todo_at_idx", columns={"todo_at"})
* })
*/
class ChildPreference
{
const STATUS_TO_ASSIGN = [
'value' => "TO_ASSIGN",
'text' => 'Priskirti',
'color' => '#f8d7da'
];
const STATUS_ASSIGNED = [
'value' => "ASSIGNED",
'text' => 'Priskirta',
'color' => '#d4edda'
];
const STATUS_ACCEPTED = [
'value' => "ACCEPTED",
'text' => 'Priimta',
'color' => '#0cb535'
];
const STATUS_CANCELLED = [
'value' => "CANCELLED",
'text' => 'Atmesta',
'color' => '#ffa600'
];
const STATUS_TERMINATING = [
'value' => "TERMINATING",
'text' => 'Nutraukia',
'color' => '#45C6F6'
];
const STATUS_NOT_FOUND = [
'value' => "NOT_FOUND",
'text' => 'Nerandama',
'color' => '#f8d7da'
];
const STATUS_AUTOMATIC_ASSIGNMENT = [
'value' => "AUTOMATIC_ASSIGNMENT",
'text' => 'Automatinis priskyrimas',
'color' => '#f8d7da'
];
const STATUSES = [self::STATUS_TO_ASSIGN, self::STATUS_ASSIGNED, self::STATUS_ACCEPTED, self::STATUS_CANCELLED, self::STATUS_TERMINATING, self::STATUS_NOT_FOUND, self::STATUS_AUTOMATIC_ASSIGNMENT];
const PENDING_ADMIN_STATUSES = [
self::STATUS_TO_ASSIGN['value'],
self::STATUS_NOT_FOUND['value'],
self::STATUS_CANCELLED['value'],
];
const LIST_ASSIGNMENT_SOURCES = ['Keitimas', 'Naujas', 'Anketa'];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Discipline::class, inversedBy="childPreferences")
* @ORM\JoinColumn(nullable=true)
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $discipline;
/**
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $amount;
/**
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $duration;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"ChildPreferenceList"})
*/
private $type = Lesson::TYPE_INDIVIDUAL;
/**
* @ORM\ManyToOne(targetEntity=Teacher::class, inversedBy="childPreferences")
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $teacher;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $comment;
/**
* @ORM\ManyToOne(targetEntity=Child::class, inversedBy="childPreferences")
* @Groups({"ChildPreferenceAssignmentList","ChildPreferenceList"})
*/
private $child;
/**
* @ORM\OneToMany(targetEntity=ChildPreferenceTime::class, mappedBy="childPreference", cascade={"all"})
* @Groups({"ChildPreferenceList", "ChildPreferenceAssignmentList"})
*/
private $childPreferenceTimes;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $fittingTimes;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $fittingTimesPriority;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $emailDuration = 120;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $singleEmailDuration = 60;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $startTime;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ChildPreferenceAssignmentList","ChildPreferenceList"})
*/
private $endTime;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $status = self::STATUS_TO_ASSIGN['value'];
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $assignedAt;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $declineReason;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $teacherChange;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $terminateReason;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $teacherAssignRemindCount = 0;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $acceptedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $todoAt;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $adminComment;
/**
* @ORM\ManyToOne(targetEntity=Admin::class, inversedBy="childPreferences")
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $adminUser;
private $ignoreNotifications;
private $regenerateLessonsFrom;
private $regenerateAllLessons;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"ChildPreferenceAssignmentList"})
*/
private $assignedFrom = "Senas";
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"ChildPreferenceList"})
*/
private $markedEndingByTeacher;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"ChildPreferenceList"})
*/
private $markedEndingByTeacherDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editedByTeacherAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tutorTerminateComment;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $action;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subAction;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $actionAt;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $keepPreviousTutor;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $assignedAutomaticly;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $flagManualAssignment;
public function __construct()
{
$this->childPreferenceTimes = new ArrayCollection();
$this->createdAt = new \Datetime();
}
public function getId(): ?int
{
return $this->id;
}
public function getDiscipline(): ?Discipline
{
return $this->discipline;
}
public function setDiscipline(?Discipline $discipline): self
{
$this->discipline = $discipline;
return $this;
}
public function getAmount(): ?int
{
return count($this->childPreferenceTimes);
// return $this->amount;
}
// public function setAmount(?int $amount): self
// {
// $this->amount = $amount;
//
// return $this;
// }
public function getDuration(): ?int
{
$duration = 0;
/**
* @var $childPreferenceTime ChildPreferenceTime
*/
foreach ($this->childPreferenceTimes as $childPreferenceTime)
{
$startTime = $childPreferenceTime->getStartTime();
$endTime = $childPreferenceTime->getEndTime();
$durationDiff = date_diff($startTime, $endTime);
$duration += (int)$durationDiff->i + (int)$durationDiff->h * 60;
}
return $duration;
}
// public function setDuration(?int $duration): self
// {
// $this->duration = $duration;
//
// return $this;
// }
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getTeacher(): ?Teacher
{
return $this->teacher;
}
public function setTeacher(?Teacher $teacher): self
{
$this->teacher = $teacher;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getChild(): ?Child
{
return $this->child;
}
public function setChild(?Child $child): self
{
$this->child = $child;
return $this;
}
/**
* @return Collection|ChildPreferenceTime[]
*/
public function getChildPreferenceTimes(): Collection
{
return $this->childPreferenceTimes;
}
public function addChildPreferenceTime(ChildPreferenceTime $childPreferenceTime): self
{
if (!$this->childPreferenceTimes->contains($childPreferenceTime)) {
$this->childPreferenceTimes[] = $childPreferenceTime;
$childPreferenceTime->setChildPreference($this);
}
return $this;
}
public function removeChildPreferenceTime(ChildPreferenceTime $childPreferenceTime): self
{
if ($this->childPreferenceTimes->removeElement($childPreferenceTime)) {
// set the owning side to null (unless already changed)
if ($childPreferenceTime->getChildPreference() === $this) {
$childPreferenceTime->setChildPreference(null);
}
}
return $this;
}
public function __toString()
{
return "{$this->child} {$this->id} {$this->discipline}";
}
public function getFittingTimes(): ?string
{
if($this->fittingTimes)
{
return $this->fittingTimes;
}
return $this->child->getFittingTimes();
}
public function setFittingTimes(?string $fittingTimes): self
{
$this->child->setFittingTimes($fittingTimes);
$this->fittingTimes = $fittingTimes;
return $this;
}
public function getEmailDuration(): ?int
{
return $this->emailDuration;
}
public function setEmailDuration(?int $emailDuration): self
{
$this->emailDuration = $emailDuration;
return $this;
}
public function getSingleEmailDuration(): ?int
{
return $this->singleEmailDuration;
}
public function setSingleEmailDuration(?int $singleEmailDuration): self
{
$this->singleEmailDuration = $singleEmailDuration;
return $this;
}
public function getStartTime(): ?\DateTimeInterface
{
return $this->startTime;
}
public function setStartTime(?\DateTimeInterface $startTime): self
{
$this->startTime = $startTime;
return $this;
}
public function getEndTime(): ?\DateTimeInterface
{
return $this->endTime;
}
public function setEndTime(?\DateTimeInterface $endTime): self
{
$this->endTime = $endTime;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function getStatusLabel(): ?string
{
foreach (self::STATUSES as $STATUS)
{
if($STATUS['value'] == $this->status)
{
return $STATUS['text'];
}
}
return '';
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getAssignedAt(): ?\DateTimeInterface
{
return $this->assignedAt;
}
public function setAssignedAt(?\DateTimeInterface $assignedAt): self
{
$this->assignedAt = $assignedAt;
return $this;
}
public function getDeclineReason(): ?string
{
return $this->declineReason;
}
public function setDeclineReason(?string $declineReason): self
{
$this->declineReason = $declineReason;
return $this;
}
public function getTeacherChange(): ?string
{
return $this->teacherChange;
}
public function setTeacherChange(?string $teacherChange): self
{
$this->teacherChange = $teacherChange;
return $this;
}
public function getTerminateReason(): ?string
{
return $this->terminateReason;
}
public function setTerminateReason(?string $terminateReason): self
{
$this->terminateReason = $terminateReason;
return $this;
}
public function getTeacherAssignRemindCount(): ?int
{
return $this->teacherAssignRemindCount;
}
public function setTeacherAssignRemindCount(?int $teacherAssignRemindCount): self
{
$this->teacherAssignRemindCount = $teacherAssignRemindCount;
return $this;
}
public function getAcceptedAt(): ?\DateTimeInterface
{
return $this->acceptedAt;
}
public function setAcceptedAt(?\DateTimeInterface $acceptedAt): self
{
$this->acceptedAt = $acceptedAt;
return $this;
}
public function getTodoAt(): ?\DateTimeInterface
{
return $this->todoAt;
}
public function setTodoAt(?\DateTimeInterface $todoAt): self
{
$this->todoAt = $todoAt;
return $this;
}
public function getAdminComment(): ?string
{
return $this->adminComment;
}
public function setAdminComment(?string $adminComment): self
{
$this->adminComment = $adminComment;
return $this;
}
public function getAdminUser(): ?Admin
{
return $this->adminUser;
}
public function setAdminUser(?Admin $adminUser): self
{
$this->adminUser = $adminUser;
return $this;
}
public function getIgnoreNotifications()
{
return $this->ignoreNotifications;
}
public function setIgnoreNotifications($ignoreNotifications): self
{
$this->ignoreNotifications = $ignoreNotifications;
return $this;
}
public function getRegenerateAllLessons()
{
return $this->regenerateAllLessons;
}
public function setRegenerateAllLessons($regenerateAllLessons): self
{
$this->regenerateAllLessons = $regenerateAllLessons;
return $this;
}
public function getRegenerateLessonsFrom()
{
return $this->regenerateLessonsFrom;
}
public function setRegenerateLessonsFrom($regenerateLessonsFrom): self
{
$this->regenerateLessonsFrom = $regenerateLessonsFrom;
return $this;
}
public function getAssignedFrom(): ?string
{
return $this->assignedFrom;
}
public function setAssignedFrom(?string $assignedFrom): self
{
$this->assignedFrom = $assignedFrom;
return $this;
}
public function isMarkedEndingByTeacher(): ?bool
{
return $this->markedEndingByTeacher;
}
public function setMarkedEndingByTeacher(?bool $markedEndingByTeacher): self
{
$this->markedEndingByTeacher = $markedEndingByTeacher;
return $this;
}
public function getMarkedEndingByTeacherDate(): ?\DateTimeInterface
{
return $this->markedEndingByTeacherDate;
}
public function setMarkedEndingByTeacherDate(?\DateTimeInterface $markedEndingByTeacherDate): self
{
$this->markedEndingByTeacherDate = $markedEndingByTeacherDate;
return $this;
}
public function getEditedByTeacherAt(): ?\DateTimeInterface
{
return $this->editedByTeacherAt;
}
public function setEditedByTeacherAt(?\DateTimeInterface $editedByTeacherAt): self
{
$this->editedByTeacherAt = $editedByTeacherAt;
return $this;
}
public function getTutorTerminateComment(): ?string
{
return $this->tutorTerminateComment;
}
public function setTutorTerminateComment(?string $tutorTerminateComment): self
{
$this->tutorTerminateComment = $tutorTerminateComment;
return $this;
}
public function getAction(): ?string
{
return $this->action;
}
public function setAction(?string $action): self
{
$this->action = $action;
return $this;
}
public function getSubAction(): ?string
{
return $this->subAction;
}
public function setSubAction(?string $subAction): self
{
$this->subAction = $subAction;
return $this;
}
public function getActionAt(): ?\DateTimeInterface
{
return $this->actionAt;
}
public function setActionAt(?\DateTimeInterface $actionAt): self
{
$this->actionAt = $actionAt;
return $this;
}
public function getFittingTimesPriority(): ?string
{
if ($this->fittingTimesPriority) {
return $this->fittingTimesPriority;
}
return $this->child->getFittingTimesPriority();
}
public function setFittingTimesPriority(?string $fittingTimesPriority): self
{
$this->child->setFittingTimesPriority($fittingTimesPriority);
$this->fittingTimesPriority = $fittingTimesPriority;
return $this;
}
public function isKeepPreviousTutor(): ?bool
{
return $this->keepPreviousTutor;
}
public function setKeepPreviousTutor(?bool $keepPreviousTutor): self
{
$this->keepPreviousTutor = $keepPreviousTutor;
return $this;
}
public function getAssignedAutomaticly(): ?\DateTimeInterface
{
return $this->assignedAutomaticly;
}
public function setAssignedAutomaticly(?\DateTimeInterface $assignedAutomaticly): self
{
$this->assignedAutomaticly = $assignedAutomaticly;
return $this;
}
public function isFlagManualAssignment(): ?bool
{
return $this->flagManualAssignment;
}
public function setFlagManualAssignment(?bool $flagManualAssignment): self
{
$this->flagManualAssignment = $flagManualAssignment;
return $this;
}
}