<?php
namespace App\Entity;
use App\Repository\SchoolSectionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Entity\Traits\Timestampable;
#[ORM\HasLifecycleCallbacks]
#[ORM\Entity(repositoryClass: SchoolSectionRepository::class)]
#[UniqueEntity(fields: ['name'], message: 'There is already an section with this name')]
class SchoolSection
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'section', targetEntity: TheClass::class)]
private Collection $theClasses;
#[ORM\ManyToOne(inversedBy: 'schoolSections', cascade: ["persist"])]
#[ORM\JoinColumn(nullable: false)]
private ?User $author = null;
#[ORM\ManyToOne(inversedBy: 'schoolSectionsEdited', cascade: ["persist"])]
private ?User $editor = null;
#[ORM\ManyToOne(inversedBy: 'schoolSections', cascade: ["persist"])]
private ?School $school = null;
public function __toString():string
{
return $this->name;
}
public function __construct()
{
$this->theClasses = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, TheClass>
*/
public function getTheClasses(): Collection
{
return $this->theClasses;
}
public function addTheClass(TheClass $theClass): static
{
if (!$this->theClasses->contains($theClass)) {
$this->theClasses->add($theClass);
$theClass->setSection($this);
}
return $this;
}
public function removeTheClass(TheClass $theClass): static
{
if ($this->theClasses->removeElement($theClass)) {
// set the owning side to null (unless already changed)
if ($theClass->getSection() === $this) {
$theClass->setSection(null);
}
}
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function getEditor(): ?User
{
return $this->editor;
}
public function setEditor(?User $editor): static
{
$this->editor = $editor;
return $this;
}
public function getSchool(): ?School
{
return $this->school;
}
public function setSchool(?School $school): static
{
$this->school = $school;
return $this;
}
}