src/Entity/Diet.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\DietRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Ksante\CoreBundle\Entity\Channel;
  9. use Ksante\CoreBundle\Entity\Traits\TimestampableTrait;
  10. use Ksante\SsoBundle\Entity\User;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ORM\Entity(repositoryClass=DietRepository::class)
  14.  *
  15.  * @ORM\Table(name="ksante_diet")
  16.  *
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. class Diet
  20. {
  21.     use TimestampableTrait;
  22.     public const MAX_SCORE 20;
  23.     /**
  24.      * @ORM\Id
  25.      *
  26.      * @ORM\GeneratedValue
  27.      *
  28.      * @ORM\Column(type="integer")
  29.      *
  30.      * @Groups("customer:read", "CustomerGroup", "read")
  31.      */
  32.     protected ?int $id null;
  33.     /**
  34.      * @ORM\Column(type="string")
  35.      *
  36.      * @Groups({"customer:read", "CustomerGroup","read"})
  37.      */
  38.     private string $firstname;
  39.     /**
  40.      * @ORM\Column(type="string")
  41.      *
  42.      * @Groups({"customer:read", "CustomerGroup","read"})
  43.      */
  44.     private string $lastname;
  45.     /**
  46.      * @ORM\Column(type="text", nullable=true)
  47.      *
  48.      * @Groups({"customer:read", "CustomerGroup","read"})
  49.      */
  50.     private ?string $description;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=Customer::class, mappedBy="diet")
  53.      */
  54.     private Collection $customers;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Appointment::class, mappedBy="diet")
  57.      */
  58.     private Collection $appointments;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=AppointmentResume::class, mappedBy="diet")
  61.      */
  62.     private Collection $appointmentsResume;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=Slot::class, mappedBy="diet")
  65.      */
  66.     private Collection $slots;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=ExceptionalSlot::class, mappedBy="diet")
  69.      */
  70.     private Collection $exceptionalSlots;
  71.     /**
  72.      * @ORM\ManyToMany(targetEntity=Channel::class)
  73.      *
  74.      * @ORM\JoinColumn(nullable=true)
  75.      */
  76.     private Collection $channels;
  77.     /**
  78.      * @ORM\Column(type="string", nullable=true)
  79.      *
  80.      * @Groups({"customer:read", "CustomerGroup","read"})
  81.      */
  82.     private ?string $picture null;
  83.     /**
  84.      * @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"})
  85.      */
  86.     private User $user;
  87.     /**
  88.      * @ORM\Column(type="integer", nullable=true)
  89.      */
  90.     private int $score;
  91.     private ?string $plainPassword;
  92.     public function __construct()
  93.     {
  94.         $this->customers = new ArrayCollection();
  95.         $this->slots = new ArrayCollection();
  96.         $this->exceptionalSlots = new ArrayCollection();
  97.         $this->channels = new ArrayCollection();
  98.         $this->user = new User();
  99.         $this->appointments = new ArrayCollection();
  100.         $this->appointmentsResume = new ArrayCollection();
  101.     }
  102.     public function __toString()
  103.     {
  104.         return $this->firstname ' ' $this->lastname;
  105.     }
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     /**
  111.      * @return Channel[]|Collection
  112.      */
  113.     public function getChannels(): Collection
  114.     {
  115.         return $this->channels;
  116.     }
  117.     public function addChannel(Channel $channel): self
  118.     {
  119.         if (!$this->channels->contains($channel)) {
  120.             $this->channels[] = $channel;
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeChannel(Channel $channel): self
  125.     {
  126.         $this->channels->removeElement($channel);
  127.         return $this;
  128.     }
  129.     public function getFirstname(): ?string
  130.     {
  131.         return $this->firstname;
  132.     }
  133.     public function setFirstname(string $firstname): self
  134.     {
  135.         $this->firstname $firstname;
  136.         return $this;
  137.     }
  138.     public function getLastname(): ?string
  139.     {
  140.         return $this->lastname;
  141.     }
  142.     public function setLastname(string $lastname): self
  143.     {
  144.         $this->lastname $lastname;
  145.         return $this;
  146.     }
  147.     public function getDescription(): ?string
  148.     {
  149.         return $this->description;
  150.     }
  151.     public function setDescription(?string $description): self
  152.     {
  153.         $this->description $description;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return Collection|Customer[]
  158.      */
  159.     public function getCustomers(): Collection
  160.     {
  161.         return $this->customers;
  162.     }
  163.     public function addCustomer(Customer $customer): self
  164.     {
  165.         if (!$this->customers->contains($customer)) {
  166.             $this->customers[] = $customer;
  167.             $customer->setDiet($this);
  168.         }
  169.         return $this;
  170.     }
  171.     public function removeCustomer(Customer $customer): self
  172.     {
  173.         if ($this->customers->removeElement($customer)) {
  174.             // set the owning side to null (unless already changed)
  175.             if ($customer->getDiet() === $this) {
  176.                 $customer->setDiet(null);
  177.             }
  178.         }
  179.         return $this;
  180.     }
  181.     public function emptyCustomerList(): self
  182.     {
  183.         /** @var Customer $customer */
  184.         foreach ($this->customers as $customer) {
  185.             $customer->setDiet(null);
  186.         }
  187.         $this->customers = new ArrayCollection();
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection|Slot[]
  192.      */
  193.     public function getSlots(): Collection
  194.     {
  195.         return $this->slots;
  196.     }
  197.     public function addSlot(Slot $slot): self
  198.     {
  199.         if (!$this->slots->contains($slot)) {
  200.             $this->slots[] = $slot;
  201.             $slot->setDiet($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeSlot(Slot $slot): self
  206.     {
  207.         if ($this->slots->removeElement($slot)) {
  208.             // set the owning side to null (unless already changed)
  209.             if ($slot->getDiet() === $this) {
  210.                 $slot->setDiet(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return Appointment[]|Collection
  217.      */
  218.     public function getAppointments(): Collection
  219.     {
  220.         return $this->appointments;
  221.     }
  222.     public function addAppointment(Appointment $appointment): self
  223.     {
  224.         if ($this->appointments->contains($appointment)) {
  225.             return $this;
  226.         }
  227.         $this->appointments[] = $appointment;
  228.         $appointment->setDiet($this);
  229.         return $this;
  230.     }
  231.     public function removeAppointment(Appointment $appointment): self
  232.     {
  233.         if ($this->appointments->removeElement($appointment)) {
  234.             // set the owning side to null (unless already changed)
  235.             if ($appointment->getDiet() === $this) {
  236.                 $appointment->setDiet(null);
  237.             }
  238.         }
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return AppointmentResume[]|Collection
  243.      */
  244.     public function getAppointmentsResume(): Collection
  245.     {
  246.         return $this->appointments;
  247.     }
  248.     public function addAppointmentResume(AppointmentResume $appointmentResume): self
  249.     {
  250.         if ($this->appointmentsResume->contains($appointmentResume)) {
  251.             return $this;
  252.         }
  253.         $this->appointmentsResume[] = $appointmentResume;
  254.         $appointmentResume->setDiet($this);
  255.         return $this;
  256.     }
  257.     public function removeAppointmentResume(AppointmentResume $appointmentResume): self
  258.     {
  259.         if ($this->appointmentsResume->removeElement($appointmentResume)) {
  260.             // set the owning side to null (unless already changed)
  261.             if ($appointmentResume->getDiet() === $this) {
  262.                 $appointmentResume->setDiet(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection|ExceptionalSlot[]
  269.      */
  270.     public function getExceptionalSlots(): Collection
  271.     {
  272.         return $this->exceptionalSlots;
  273.     }
  274.     public function addExceptionalSlot(ExceptionalSlot $exceptionalSlot): self
  275.     {
  276.         if (!$this->exceptionalSlots->contains($exceptionalSlot)) {
  277.             $this->exceptionalSlots[] = $exceptionalSlot;
  278.             $exceptionalSlot->setDiet($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeExceptionalSlot(ExceptionalSlot $exceptionalSlot): self
  283.     {
  284.         if ($this->exceptionalSlots->removeElement($exceptionalSlot)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($exceptionalSlot->getDiet() === $this) {
  287.                 $exceptionalSlot->setDiet(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292.     public function getPicture(): ?string
  293.     {
  294.         return $this->picture;
  295.     }
  296.     public function setPicture(?string $picture): self
  297.     {
  298.         $this->picture $picture;
  299.         return $this;
  300.     }
  301.     public function getUser(): User
  302.     {
  303.         return $this->user;
  304.     }
  305.     public function setUser(User $user): self
  306.     {
  307.         $this->user $user;
  308.         return $this;
  309.     }
  310.     public function getScore(): ?int
  311.     {
  312.         return $this->score;
  313.     }
  314.     public function setScore(?int $score): self
  315.     {
  316.         $this->score $score;
  317.         return $this;
  318.     }
  319.     public function getPlainPassword(): ?string
  320.     {
  321.         return $this->plainPassword;
  322.     }
  323.     public function setPlainPassword(?string $plainPassword): self
  324.     {
  325.         $this->plainPassword $plainPassword;
  326.         return $this;
  327.     }
  328.     public function getFullName(): string
  329.     {
  330.         return trim(\sprintf('%s %s'$this->firstname$this->lastname));
  331.     }
  332. }