118 lines
2.8 KiB
PHP
118 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
|
/**
|
|
* Teacher
|
|
*
|
|
* @ORM\Entity(repositoryClass="App\Repository\TeacherRepository")
|
|
* @ORM\Table(name="teacher",uniqueConstraints={@ORM\UniqueConstraint(name="unique01", columns={"year_id","user_id"})})
|
|
* @UniqueEntity(fields={"year","user"}, message="Cet utilisateur est déjà professeur")
|
|
*/
|
|
class Teacher
|
|
{
|
|
/**
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="teachers")
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Year", inversedBy="teachers")
|
|
*/
|
|
private $year;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Assignmentteacher", mappedBy="tearcher", mappedBy="teacher", cascade={"persist"}, orphanRemoval=false))
|
|
*/
|
|
private $assignmentteachers;
|
|
|
|
// == CALCUL ============================
|
|
|
|
private $displayname;
|
|
public function getDisplayname()
|
|
{
|
|
return $this->user->getDisplayname();
|
|
}
|
|
|
|
// ======================================
|
|
|
|
public function __construct()
|
|
{
|
|
$this->assignmentteachers = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUser(): ?User
|
|
{
|
|
return $this->user;
|
|
}
|
|
|
|
public function setUser(?User $user): self
|
|
{
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getYear(): ?Year
|
|
{
|
|
return $this->year;
|
|
}
|
|
|
|
public function setYear(?Year $year): self
|
|
{
|
|
$this->year = $year;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection|Assignmentteacher[]
|
|
*/
|
|
public function getAssignmentteachers(): Collection
|
|
{
|
|
return $this->assignmentteachers;
|
|
}
|
|
|
|
public function addAssignmentteacher(Assignmentteacher $assignmentteacher): self
|
|
{
|
|
if (!$this->assignmentteachers->contains($assignmentteacher)) {
|
|
$this->assignmentteachers[] = $assignmentteacher;
|
|
$assignmentteacher->setTeacher($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeAssignmentteacher(Assignmentteacher $assignmentteacher): self
|
|
{
|
|
if ($this->assignmentteachers->contains($assignmentteacher)) {
|
|
$this->assignmentteachers->removeElement($assignmentteacher);
|
|
// set the owning side to null (unless already changed)
|
|
if ($assignmentteacher->getTeacher() === $this) {
|
|
$assignmentteacher->setTeacher(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
} |