src/Entity/Role.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RoleRepository;
  4. use App\Trait\ArrayableTrait;
  5. use App\Trait\DeletableTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClassRoleRepository::class)]
  10. class Role
  11. {
  12.     use DeletableTrait;
  13.     use ArrayableTrait;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $name null;
  20.     #[ORM\ManyToOne(inversedBy'roleWorkers')]
  21.     private ?Establishment $establishment null;
  22.     #[ORM\OneToMany(mappedBy'function'targetEntityEmployee::class)]
  23.     private Collection $employees;
  24.     public function __construct()
  25.     {
  26.         $this->employees = new ArrayCollection();
  27.     }
  28.     public function __toString(): string
  29.     {
  30.         return $this->name;
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getName(): ?string
  37.     {
  38.         return $this->name;
  39.     }
  40.     public function setName(string $name): static
  41.     {
  42.         $this->name $name;
  43.         return $this;
  44.     }
  45.     public function getEstablishment(): ?Establishment
  46.     {
  47.         return $this->establishment;
  48.     }
  49.     public function setEstablishment(?Establishment $establishment): static
  50.     {
  51.         $this->establishment $establishment;
  52.         return $this;
  53.     }
  54.     /**
  55.      * @return Collection<int, Employee>
  56.      */
  57.     public function getEmployees(): Collection
  58.     {
  59.         return $this->employees;
  60.     }
  61.     public function addEmployee(Employee $employee): static
  62.     {
  63.         if (!$this->employees->contains($employee)) {
  64.             $this->employees->add($employee);
  65.             $employee->setFunction($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeEmployee(Employee $employee): static
  70.     {
  71.         if ($this->employees->removeElement($employee)) {
  72.             // set the owning side to null (unless already changed)
  73.             if ($employee->getFunction() === $this) {
  74.                 $employee->setFunction(null);
  75.             }
  76.         }
  77.         return $this;
  78.     }
  79. }