<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\DietRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ksante\CoreBundle\Entity\Channel;
use Ksante\CoreBundle\Entity\Traits\TimestampableTrait;
use Ksante\SsoBundle\Entity\User;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=DietRepository::class)
*
* @ORM\Table(name="ksante_diet")
*
* @ORM\HasLifecycleCallbacks()
*/
class Diet
{
use TimestampableTrait;
public const MAX_SCORE = 20;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups("customer:read", "CustomerGroup", "read")
*/
protected ?int $id = null;
/**
* @ORM\Column(type="string")
*
* @Groups({"customer:read", "CustomerGroup","read"})
*/
private string $firstname;
/**
* @ORM\Column(type="string")
*
* @Groups({"customer:read", "CustomerGroup","read"})
*/
private string $lastname;
/**
* @ORM\Column(type="text", nullable=true)
*
* @Groups({"customer:read", "CustomerGroup","read"})
*/
private ?string $description;
/**
* @ORM\OneToMany(targetEntity=Customer::class, mappedBy="diet")
*/
private Collection $customers;
/**
* @ORM\OneToMany(targetEntity=Appointment::class, mappedBy="diet")
*/
private Collection $appointments;
/**
* @ORM\OneToMany(targetEntity=AppointmentResume::class, mappedBy="diet")
*/
private Collection $appointmentsResume;
/**
* @ORM\OneToMany(targetEntity=Slot::class, mappedBy="diet")
*/
private Collection $slots;
/**
* @ORM\OneToMany(targetEntity=ExceptionalSlot::class, mappedBy="diet")
*/
private Collection $exceptionalSlots;
/**
* @ORM\ManyToMany(targetEntity=Channel::class)
*
* @ORM\JoinColumn(nullable=true)
*/
private Collection $channels;
/**
* @ORM\Column(type="string", nullable=true)
*
* @Groups({"customer:read", "CustomerGroup","read"})
*/
private ?string $picture = null;
/**
* @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
*/
private User $user;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private int $score;
private ?string $plainPassword;
public function __construct()
{
$this->customers = new ArrayCollection();
$this->slots = new ArrayCollection();
$this->exceptionalSlots = new ArrayCollection();
$this->channels = new ArrayCollection();
$this->user = new User();
$this->appointments = new ArrayCollection();
$this->appointmentsResume = new ArrayCollection();
}
public function __toString()
{
return $this->firstname . ' ' . $this->lastname;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Channel[]|Collection
*/
public function getChannels(): Collection
{
return $this->channels;
}
public function addChannel(Channel $channel): self
{
if (!$this->channels->contains($channel)) {
$this->channels[] = $channel;
}
return $this;
}
public function removeChannel(Channel $channel): self
{
$this->channels->removeElement($channel);
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection|Customer[]
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): self
{
if (!$this->customers->contains($customer)) {
$this->customers[] = $customer;
$customer->setDiet($this);
}
return $this;
}
public function removeCustomer(Customer $customer): self
{
if ($this->customers->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getDiet() === $this) {
$customer->setDiet(null);
}
}
return $this;
}
public function emptyCustomerList(): self
{
/** @var Customer $customer */
foreach ($this->customers as $customer) {
$customer->setDiet(null);
}
$this->customers = new ArrayCollection();
return $this;
}
/**
* @return Collection|Slot[]
*/
public function getSlots(): Collection
{
return $this->slots;
}
public function addSlot(Slot $slot): self
{
if (!$this->slots->contains($slot)) {
$this->slots[] = $slot;
$slot->setDiet($this);
}
return $this;
}
public function removeSlot(Slot $slot): self
{
if ($this->slots->removeElement($slot)) {
// set the owning side to null (unless already changed)
if ($slot->getDiet() === $this) {
$slot->setDiet(null);
}
}
return $this;
}
/**
* @return Appointment[]|Collection
*/
public function getAppointments(): Collection
{
return $this->appointments;
}
public function addAppointment(Appointment $appointment): self
{
if ($this->appointments->contains($appointment)) {
return $this;
}
$this->appointments[] = $appointment;
$appointment->setDiet($this);
return $this;
}
public function removeAppointment(Appointment $appointment): self
{
if ($this->appointments->removeElement($appointment)) {
// set the owning side to null (unless already changed)
if ($appointment->getDiet() === $this) {
$appointment->setDiet(null);
}
}
return $this;
}
/**
* @return AppointmentResume[]|Collection
*/
public function getAppointmentsResume(): Collection
{
return $this->appointments;
}
public function addAppointmentResume(AppointmentResume $appointmentResume): self
{
if ($this->appointmentsResume->contains($appointmentResume)) {
return $this;
}
$this->appointmentsResume[] = $appointmentResume;
$appointmentResume->setDiet($this);
return $this;
}
public function removeAppointmentResume(AppointmentResume $appointmentResume): self
{
if ($this->appointmentsResume->removeElement($appointmentResume)) {
// set the owning side to null (unless already changed)
if ($appointmentResume->getDiet() === $this) {
$appointmentResume->setDiet(null);
}
}
return $this;
}
/**
* @return Collection|ExceptionalSlot[]
*/
public function getExceptionalSlots(): Collection
{
return $this->exceptionalSlots;
}
public function addExceptionalSlot(ExceptionalSlot $exceptionalSlot): self
{
if (!$this->exceptionalSlots->contains($exceptionalSlot)) {
$this->exceptionalSlots[] = $exceptionalSlot;
$exceptionalSlot->setDiet($this);
}
return $this;
}
public function removeExceptionalSlot(ExceptionalSlot $exceptionalSlot): self
{
if ($this->exceptionalSlots->removeElement($exceptionalSlot)) {
// set the owning side to null (unless already changed)
if ($exceptionalSlot->getDiet() === $this) {
$exceptionalSlot->setDiet(null);
}
}
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getScore(): ?int
{
return $this->score;
}
public function setScore(?int $score): self
{
$this->score = $score;
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(?string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
public function getFullName(): string
{
return trim(\sprintf('%s %s', $this->firstname, $this->lastname));
}
}