src/Entity/ClassRoom.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\User;
  4. use App\Entity\SchoolYear;
  5. use App\Entity\Subscription;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\ClassRoomRepository;
  8. use Doctrine\Persistence\ObjectManager;
  9. use App\Repository\SubscriptionRepository;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\Persistence\Mapping\ClassMetadata;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. /**
  15.  * @ORM\Entity(repositoryClass=ClassRoomRepository::class)
  16.  * @UniqueEntity(fields={"name"}, message= "There is already a classroom  with this name")
  17.  */
  18. class ClassRoom
  19. {
  20.     public const NUM_ITEMS_PER_PAGE 3;
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $name;
  31.     /**
  32.      * Cette classe est-elle une classe d'examen?
  33.      * @ORM\Column(type="boolean", options={"default" = false})
  34.      */
  35.     private $apc;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity=Module::class, mappedBy="room", orphanRemoval=true)
  38.      */
  39.     private $modules;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity=Level::class, inversedBy="rooms")
  42.      * @ORM\JoinColumn(nullable=false)
  43.      */
  44.     private $level;
  45.      /**
  46.      * @ORM\OneToMany(targetEntity=MainTeacher::class, mappedBy="classRoom")
  47.      */
  48.     private $mainTeachers;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="classRoom")
  51.      */
  52.     private $subscriptions;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=AbscenceSheet::class, mappedBy="classRoom", orphanRemoval=true)
  55.      */
  56.     private $abscenceSheets;
  57.     public function __construct()
  58.     {
  59.         $this->modules = new ArrayCollection();
  60.         $this->subscriptions = new ArrayCollection();
  61.         $this->abscenceSheets = new ArrayCollection();
  62.         $this->mainTeachers = new ArrayCollection();
  63.     }
  64.     public function __toString()
  65.     {
  66.         $name = (is_null($this->getName())) ? "" $this->getName();
  67.         $level = (is_null($this->getLevel())) ? "" $this->getLevel();
  68.         return (string) ($level "/" $name);
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getName(): ?string
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function setName(string $name): self
  79.     {
  80.         $this->name $name;
  81.         return $this;
  82.     }
  83.     public function getApc(): ?bool
  84.     {
  85.         return $this->apc;
  86.     }
  87.     public function setApc(bool $apc): self
  88.     {
  89.         $this->apc $apc;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return Collection|Module[]
  94.      */
  95.     public function getModules(): Collection
  96.     {
  97.         return $this->modules;
  98.     }
  99.     public function addModule(Module $module): self
  100.     {
  101.         if (!$this->modules->contains($module)) {
  102.             $this->modules[] = $module;
  103.             $module->setRoom($this);
  104.         }
  105.         return $this;
  106.     }
  107.     public function removeModule(Module $module): self
  108.     {
  109.         if ($this->modules->removeElement($module)) {
  110.             // set the owning side to null (unless already changed)
  111.             if ($module->getRoom() === $this) {
  112.                 $module->setRoom(null);
  113.             }
  114.         }
  115.         return $this;
  116.     }
  117.     public function getLevel(): ?Level
  118.     {
  119.         return $this->level;
  120.     }
  121.     public function setLevel(?Level $level): self
  122.     {
  123.         $this->level $level;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection|Subscription[]
  128.      */
  129.     public function getSubscriptions(): Collection
  130.     {
  131.         return $this->subscriptions;
  132.     }
  133.     public function addSubscription(Subscription $subscription): self
  134.     {
  135.         if (!$this->subscriptions->contains($subscription)) {
  136.             $this->subscriptions[] = $subscription;
  137.             $subscription->setClassRoom($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeSubscription(Subscription $subscription): self
  142.     {
  143.         if ($this->subscriptions->removeElement($subscription)) {
  144.             // set the owning side to null (unless already changed)
  145.             if ($subscription->getClassRoom() === $this) {
  146.                 $subscription->setClassRoom(null);
  147.             }
  148.         }
  149.         return $this;
  150.     }
  151.     public function isApc(): ?bool
  152.     {
  153.         return $this->apc;
  154.     }
  155.     /**
  156.      * @return Collection<int, AbscenceSheet>
  157.      */
  158.     public function getAbscenceSheets(): Collection
  159.     {
  160.         return $this->abscenceSheets;
  161.     }
  162.     public function addAbscenceSheet(AbscenceSheet $abscenceSheet): static
  163.     {
  164.         if (!$this->abscenceSheets->contains($abscenceSheet)) {
  165.             $this->abscenceSheets->add($abscenceSheet);
  166.             $abscenceSheet->setClassRoom($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeAbscenceSheet(AbscenceSheet $abscenceSheet): static
  171.     {
  172.         if ($this->abscenceSheets->removeElement($abscenceSheet)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($abscenceSheet->getClassRoom() === $this) {
  175.                 $abscenceSheet->setClassRoom(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return User
  182.      */
  183.     public function getMainTeacher(SchoolYear $year): User
  184.     {
  185.         foreach($this->mainTeachers as $teacher){
  186.             if($teacher->getSchoolYear()->getId() == $year->getId()){
  187.                 return $teacher;
  188.             }
  189.         }
  190.         return null;
  191.     }
  192.     /**
  193.      * @return Collection<int, MainTeacher>
  194.      */
  195.     public function getMainTeachers(): Collection
  196.     {
  197.         return $this->mainTeachers;
  198.     }
  199.     public function addMainTeacher(MainTeacher $mainTeacher): static
  200.     {
  201.         if (!$this->mainTeachers->contains($mainTeacher)) {
  202.             $this->mainTeachers->add($mainTeacher);
  203.             $mainTeacher->setClassRoom($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removeMainTeacher(MainTeacher $mainTeacher): static
  208.     {
  209.         if ($this->mainTeachers->removeElement($mainTeacher)) {
  210.             // set the owning side to null (unless already changed)
  211.             if ($mainTeacher->getClassRoom() === $this) {
  212.                 $mainTeacher->setClassRoom(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     public function removeMainTeacherOfYear(SchoolYear $year): static
  218.     {
  219.         foreach($this->mainTeachers as $teacher){
  220.             if($teacher->getSchoolYear()->getId() == $year->getId()){
  221.                 return $this->removeMainTeacher($teacher);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226.     public function updateMainTeacherOfYear(SchoolYear $yearUser $user): static
  227.     {
  228.         foreach($this->mainTeachers as $mainTeacher){
  229.             if($mainTeacher->getSchoolYear()->getId() == $year->getId()){
  230.                 $mainTeacher->setTeacher($user);
  231.             }
  232.         }
  233.         return $this;
  234.     }
  235. }