107 lines
2.4 KiB
PHP
107 lines
2.4 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;
|
|
|
|
/**
|
|
* Responsible
|
|
*
|
|
* @ORM\Entity(repositoryClass="App\Repository\ResponsibleRepository")
|
|
* @ORM\Table(name="responsible",uniqueConstraints={@ORM\UniqueConstraint(name="unique01", columns={"year_id","user_id"})})
|
|
* @UniqueEntity(fields={"year","user"}, message="Cet utilisateur est déjà un responsable")
|
|
*/
|
|
class Responsible
|
|
{
|
|
/**
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="responsibles")
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Year", inversedBy="responsibles")
|
|
*/
|
|
private $year;
|
|
|
|
/**
|
|
* @ORM\ManyToMany(targetEntity="Student", inversedBy="responsibles", cascade={"persist"})
|
|
* @ORM\JoinTable(name="studentresponsible",
|
|
* joinColumns={@ORM\JoinColumn(name="responsible", referencedColumnName="id")},
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="student", referencedColumnName="id")}
|
|
* )
|
|
*/
|
|
private $students;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->students = 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|Student[]
|
|
*/
|
|
public function getStudents(): Collection
|
|
{
|
|
return $this->students;
|
|
}
|
|
|
|
public function addStudent(Student $student): self
|
|
{
|
|
if (!$this->students->contains($student)) {
|
|
$this->students[] = $student;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeStudent(Student $student): self
|
|
{
|
|
if ($this->students->contains($student)) {
|
|
$this->students->removeElement($student);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
} |