src/Entity/UserRole.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRoleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassUserRoleRepository::class)]
  8. class UserRole
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\Column(type'string'length255)]
  15.     private $name;
  16.     #[ORM\Column(type'float'nullabletrue)]
  17.     private $cost;
  18.     #[ORM\ManyToOne(targetEntityDepartment::class, inversedBy'userRoles')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private $department;
  21.     #[ORM\OneToMany(targetEntityPersonalInfo::class, mappedBy'userRole')]
  22.     private $personalInfo;
  23.     #[ORM\OneToMany(targetEntityProjectAllocatedHours::class, mappedBy'userRole')]
  24.     private $projectAllocatedHours;
  25.     #[ORM\OneToMany(targetEntityDepartmentCost::class, mappedBy'userRole'cascade: ['persist'], orphanRemovaltrue)]
  26.     private $departmentCosts;
  27.     public function __construct()
  28.     {
  29.         $this->personalInfo = new ArrayCollection();
  30.         $this->projectAllocatedHours = new ArrayCollection();
  31.         $this->departmentCosts = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     public function getCost(): ?float
  47.     {
  48.         return $this->cost;
  49.     }
  50.     public function setCost(float $cost): self
  51.     {
  52.         $this->cost $cost;
  53.         return $this;
  54.     }
  55.     public function getDepartment(): ?Department
  56.     {
  57.         return $this->department;
  58.     }
  59.     public function setDepartment(?Department $department): self
  60.     {
  61.         $this->department $department;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection|PersonalInfo[]
  66.      */
  67.     public function getPersonalInfo(): Collection
  68.     {
  69.         return $this->personalInfo;
  70.     }
  71.     public function addPersonalInfo(PersonalInfo $personalInfo): self
  72.     {
  73.         if (!$this->personalInfo->contains($personalInfo)) {
  74.             $this->personalInfo[] = $personalInfo;
  75.             $personalInfo->setUserRole($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removePersonalInfo(PersonalInfo $personalInfo): self
  80.     {
  81.         if ($this->personalInfo->removeElement($personalInfo)) {
  82.             // set the owning side to null (unless already changed)
  83.             if ($personalInfo->getUserRole() === $this) {
  84.                 $personalInfo->setUserRole(null);
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection|ProjectAllocatedHours[]
  91.      */
  92.     public function getProjectAllocatedHours(): Collection
  93.     {
  94.         return $this->projectAllocatedHours;
  95.     }
  96.     public function addProjectAllocatedHour(ProjectAllocatedHours $projectAllocatedHour): self
  97.     {
  98.         if (!$this->projectAllocatedHours->contains($projectAllocatedHour)) {
  99.             $this->projectAllocatedHours[] = $projectAllocatedHour;
  100.             $projectAllocatedHour->setUserRole($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeProjectAllocatedHour(ProjectAllocatedHours $projectAllocatedHour): self
  105.     {
  106.         if ($this->projectAllocatedHours->removeElement($projectAllocatedHour)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($projectAllocatedHour->getUserRole() === $this) {
  109.                 $projectAllocatedHour->setUserRole(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection|DepartmentCost[]
  116.      */
  117.     public function getDepartmentCosts(): Collection
  118.     {
  119.         return $this->departmentCosts;
  120.     }
  121.     public function addDepartmentCost(DepartmentCost $departmentCost): self
  122.     {
  123.         if (!$this->departmentCosts->contains($departmentCost)) {
  124.             $this->departmentCosts[] = $departmentCost;
  125.             $departmentCost->setUserRole($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeDepartmentCost(DepartmentCost $departmentCost): self
  130.     {
  131.         if ($this->departmentCosts->removeElement($departmentCost)) {
  132.             // set the owning side to null (unless already changed)
  133.             if ($departmentCost->getUserRole() === $this) {
  134.                 $departmentCost->setUserRole(null);
  135.             }
  136.         }
  137.         return $this;
  138.     }
  139.     public function getLatestDepartmentRate()
  140.     {
  141.         $departmentCosts $this->getDepartmentCosts();
  142.         $latestDepartmentCost null;
  143.         foreach ($departmentCosts as $departmentCost) {
  144.             if ($latestDepartmentCost == null) {
  145.                 $latestDepartmentCost $departmentCost;
  146.             } else {
  147.                 if ($departmentCost->getValidAt() > $latestDepartmentCost->getValidAt() && $departmentCost->getValidAt() < new \DateTime) {
  148.                     $latestDepartmentCost $departmentCost;
  149.                 }
  150.             }
  151.         }
  152.         return $latestDepartmentCost;
  153.     }
  154. }