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.     /**
  55.      * @ORM\OneToMany(targetEntity=AbscenceSheet::class, mappedBy="classRoom", orphanRemoval=true)
  56.      */
  57.     private $abscenceSheets;
  58.     public function __construct()
  59.     {
  60.         $this->modules = new ArrayCollection();
  61.         $this->subscriptions = new ArrayCollection();
  62.         $this->abscenceSheets = new ArrayCollection();
  63.         $this->mainTeachers = new ArrayCollection();
  64.     }
  65.     public function __toString()
  66.     {
  67.         $name = (is_null($this->getName())) ? "" $this->getName();
  68.         $level = (is_null($this->getLevel())) ? "" $this->getLevel();
  69.         return (string) ($level "/" $name);
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getName(): ?string
  76.     {
  77.         return $this->name;
  78.     }
  79.     public function setName(string $name): self
  80.     {
  81.         $this->name $name;
  82.         return $this;
  83.     }
  84.     public function getApc(): ?bool
  85.     {
  86.         return $this->apc;
  87.     }
  88.     public function setApc(bool $apc): self
  89.     {
  90.         $this->apc $apc;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection|Module[]
  95.      */
  96.     public function getModules(): Collection
  97.     {
  98.         return $this->modules;
  99.     }
  100.     public function addModule(Module $module): self
  101.     {
  102.         if (!$this->modules->contains($module)) {
  103.             $this->modules[] = $module;
  104.             $module->setRoom($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeModule(Module $module): self
  109.     {
  110.         if ($this->modules->removeElement($module)) {
  111.             // set the owning side to null (unless already changed)
  112.             if ($module->getRoom() === $this) {
  113.                 $module->setRoom(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118.     public function getLevel(): ?Level
  119.     {
  120.         return $this->level;
  121.     }
  122.     public function setLevel(?Level $level): self
  123.     {
  124.         $this->level $level;
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return Collection|Subscription[]
  129.      */
  130.     public function getSubscriptions(): Collection
  131.     {
  132.         return $this->subscriptions;
  133.     }
  134.     public function addSubscription(Subscription $subscription): self
  135.     {
  136.         if (!$this->subscriptions->contains($subscription)) {
  137.             $this->subscriptions[] = $subscription;
  138.             $subscription->setClassRoom($this);
  139.         }
  140.         return $this;
  141.     }
  142.     public function removeSubscription(Subscription $subscription): self
  143.     {
  144.         if ($this->subscriptions->removeElement($subscription)) {
  145.             // set the owning side to null (unless already changed)
  146.             if ($subscription->getClassRoom() === $this) {
  147.                 $subscription->setClassRoom(null);
  148.             }
  149.         }
  150.         return $this;
  151.     }
  152.     public function isApc(): ?bool
  153.     {
  154.         return $this->apc;
  155.     }
  156.     /**
  157.      * @return Collection<int, AbscenceSheet>
  158.      */
  159.     public function getAbscenceSheets(): Collection
  160.     {
  161.         return $this->abscenceSheets;
  162.     }
  163.     public function addAbscenceSheet(AbscenceSheet $abscenceSheet): static
  164.     {
  165.         if (!$this->abscenceSheets->contains($abscenceSheet)) {
  166.             $this->abscenceSheets->add($abscenceSheet);
  167.             $abscenceSheet->setClassRoom($this);
  168.         }
  169.         return $this;
  170.     }
  171.     public function removeAbscenceSheet(AbscenceSheet $abscenceSheet): static
  172.     {
  173.         if ($this->abscenceSheets->removeElement($abscenceSheet)) {
  174.             // set the owning side to null (unless already changed)
  175.             if ($abscenceSheet->getClassRoom() === $this) {
  176.                 $abscenceSheet->setClassRoom(null);
  177.             }
  178.         }
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return User
  183.      */
  184.     public function getMainTeacher(SchoolYear $year): User
  185.     {
  186.         foreach($this->mainTeachers as $teacher){
  187.             if($teacher->getSchoolYear()->getId() == $year->getId()){
  188.                 return $teacher;
  189.             }
  190.         }
  191.         return null;
  192.     }
  193.     /**
  194.      * @return Collection<int, MainTeacher>
  195.      */
  196.     public function getMainTeachers(): Collection
  197.     {
  198.         return $this->mainTeachers;
  199.     }
  200.     public function addMainTeacher(MainTeacher $mainTeacher): static
  201.     {
  202.         if (!$this->mainTeachers->contains($mainTeacher)) {
  203.             $this->mainTeachers->add($mainTeacher);
  204.             $mainTeacher->setClassRoom($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeMainTeacher(MainTeacher $mainTeacher): static
  209.     {
  210.         if ($this->mainTeachers->removeElement($mainTeacher)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($mainTeacher->getClassRoom() === $this) {
  213.                 $mainTeacher->setClassRoom(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeMainTeacherOfYear(SchoolYear $year): static
  219.     {
  220.         foreach($this->mainTeachers as $teacher){
  221.             if($teacher->getSchoolYear()->getId() == $year->getId()){
  222.                 return $this->removeMainTeacher($teacher);
  223.             }
  224.         }
  225.         return $this;
  226.     }
  227.     public function updateMainTeacherOfYear(SchoolYear $yearUser $user): static
  228.     {
  229.         foreach($this->mainTeachers as $mainTeacher){
  230.             if($mainTeacher->getSchoolYear()->getId() == $year->getId()){
  231.                 $mainTeacher->setTeacher($user);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236. }