<?php
namespace App\Entity;
use App\Repository\CycleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=CycleRepository::class)
* @UniqueEntity(
* fields={"name"},
* message="Un cycle porte deja ce nom."
* )
*/
class Cycle
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Section::class, inversedBy="cycles")
* @ORM\JoinColumn(nullable=false)
*/
private $section;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Level::class, mappedBy="cycle")
*/
private $levels;
public function __construct()
{
$this->levels = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function __toString()
{
$name = (is_null($this->getName())) ? "" : $this->getName();
$section = (is_null($this->getSection())) ? "" : $this->getSection();
return (string) ($section . "/" . $name);
}
/**
* @return Collection|Level[]
*/
public function getLevels(): Collection
{
return $this->levels;
}
public function addLevel(Level $level): self
{
if (!$this->levels->contains($level)) {
$this->levels[] = $level;
$level->setCycle($this);
}
return $this;
}
public function removeLevel(Level $level): self
{
if ($this->levels->removeElement($level)) {
// set the owning side to null (unless already changed)
if ($level->getCycle() === $this) {
$level->setCycle(null);
}
}
return $this;
}
}