src/Entity/Department.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Serializer\Annotation\Groups;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass'App\Repository\DepartmentRepository')]
  8. class Department
  9. {
  10.     #[Groups(['LogService'])]
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[Groups(['LogService''APIJob'])]
  16.     #[ORM\Column(type'string'length32)]
  17.     private $name;
  18.     #[ORM\ManyToOne(targetEntity'App\Entity\Company'inversedBy'departments')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private $company;
  21.     #[Groups(['LogService'])]
  22.     #[ORM\Column(type'string'length255nullabletrue)]
  23.     private $description;
  24.     #[ORM\OneToMany(targetEntity'App\Entity\Organization'mappedBy'department')]
  25.     private $organizations;
  26.     #[ORM\ManyToMany(targetEntityTraining::class, mappedBy'departments')]
  27.     private $trainings;
  28.     #[ORM\ManyToMany(targetEntityAnnouncement::class, mappedBy'departments')]
  29.     private $announcements;
  30.     #[ORM\OneToMany(targetEntityJob::class, mappedBy'department')]
  31.     private $jobs;
  32.     #[ORM\OneToMany(targetEntityAppraisalForm::class, mappedBy'department')]
  33.     private $appraisalForms;
  34.     #[ORM\OneToMany(targetEntityUser::class, mappedBy'department')]
  35.     private $users;
  36.     #[ORM\OneToMany(targetEntityTaskType::class, mappedBy'department')]
  37.     private $taskTypes;
  38.     #[ORM\OneToMany(targetEntityUserRole::class, mappedBy'department')]
  39.     private $userRoles;
  40.     #[ORM\ManyToMany(targetEntityCourse::class, mappedBy'departments')]
  41.     private $courses;
  42.     #[ORM\ManyToMany(targetEntityCourseAutoEnrollment::class, mappedBy'departments')]
  43.     private $courseAutoEnrollments;
  44.     #[ORM\OneToMany(targetEntityXeroLineItem::class, mappedBy'department')]
  45.     #[ORM\JoinColumn(name'invoice_line_item_id'referencedColumnName'id'nullablefalse)]
  46.     private $xeroLineItems;
  47.     #[ORM\OneToMany(mappedBy'department'targetEntityChecklist::class)]
  48.     private Collection $checklists;
  49.     #[ORM\OneToMany(mappedBy'Department'targetEntityChatbotSectionDepartment::class, orphanRemovaltrue)]
  50.     private Collection $chatbotSectionDepartments;
  51.     #[ORM\OneToMany(mappedBy'department'targetEntityChatbotDepartmentPrompt::class, orphanRemovaltrue)]
  52.     private Collection $chatbotDepartmentPrompts;
  53.     #[ORM\OneToMany(mappedBy'department'targetEntityDepartmentOverview::class, orphanRemovaltrue)]
  54.     private Collection $departmentOverviews;
  55.     #[ORM\ManyToMany(targetEntityVendor::class, mappedBy'departmentInCharge')]
  56.     private Collection $vendors;
  57.     #[ORM\ManyToOne]
  58.     #[ORM\JoinColumn(nullabletrue)]
  59.     private ?User $leader null;
  60.     public function __construct()
  61.     {
  62.         // $this->user = new ArrayCollection();
  63.         $this->organizations = new ArrayCollection();
  64.         $this->trainings = new ArrayCollection();
  65.         $this->announcements = new ArrayCollection();
  66.         $this->jobs = new ArrayCollection();
  67.         $this->appraisalForms = new ArrayCollection();
  68.         $this->users = new ArrayCollection();
  69.         $this->taskTypes = new ArrayCollection();
  70.         $this->userRoles = new ArrayCollection();
  71.         $this->courses = new ArrayCollection();
  72.         $this->courseAutoEnrollments = new ArrayCollection();
  73.         $this->xeroLineItems = new ArrayCollection();
  74.         $this->checklists = new ArrayCollection();
  75.         $this->chatbotSectionDepartments = new ArrayCollection();
  76.         $this->chatbotDepartmentPrompts = new ArrayCollection();
  77.         $this->departmentOverviews = new ArrayCollection();
  78.         $this->vendors = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getName(): ?string
  85.     {
  86.         return $this->name;
  87.     }
  88.     public function setName(string $name): self
  89.     {
  90.         $this->name $name;
  91.         return $this;
  92.     }
  93.     public function getCompany(): ?Company
  94.     {
  95.         return $this->company;
  96.     }
  97.     public function setCompany(?Company $company): self
  98.     {
  99.         $this->company $company;
  100.         return $this;
  101.     }
  102.     public function getDescription(): ?string
  103.     {
  104.         return $this->description;
  105.     }
  106.     public function setDescription(?string $description): self
  107.     {
  108.         $this->description $description;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return Collection|Organization[]
  113.      */
  114.     public function getOrganizations(): Collection
  115.     {
  116.         return $this->organizations;
  117.     }
  118.     public function addOrganization(Organization $organization): self
  119.     {
  120.         if (!$this->organizations->contains($organization)) {
  121.             $this->organizations[] = $organization;
  122.             $organization->setDepartment($this);
  123.         }
  124.         return $this;
  125.     }
  126.     public function removeOrganization(Organization $organization): self
  127.     {
  128.         if ($this->organizations->contains($organization)) {
  129.             $this->organizations->removeElement($organization);
  130.             // set the owning side to null (unless already changed)
  131.             if ($organization->getDepartment() === $this) {
  132.                 $organization->setDepartment(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getOrganizationMembers()
  138.     {
  139.         $users = [];
  140.         foreach ($this->getOrganizations() as $user) {
  141.             if ($user->getDepartment() == $thisarray_push($users$user);
  142.         };
  143.         return $users;
  144.     }
  145.     public function getOrganizationUsers($isActive true)
  146.     {
  147.         $users = [];
  148.         $registered_users = [];
  149.         foreach ($this->getOrganizations() as $user) {
  150.             $uid $user->getUser() ? $user->getUser()->getId() : false;
  151.             if ($uid != null && in_array($uid$registered_users) == false) {
  152.                 if ($user->getUser()->getIsActive() == $isActive) {
  153.                     array_push($users$user);
  154.                     array_push($registered_users$uid);
  155.                 };
  156.             }
  157.         };
  158.         return $users;
  159.     }
  160.     public function getTotalActiveUser()
  161.     {
  162.         $users $this->getUsers();
  163.         $total 0;
  164.         foreach ($users as $user) {
  165.             if ($user->getIsActive()) {
  166.                 $total++;
  167.             }
  168.         }
  169.         return $total;
  170.     }
  171.     /**
  172.      * @return Collection|Training[]
  173.      */
  174.     public function getTrainings(): Collection
  175.     {
  176.         return $this->trainings;
  177.     }
  178.     public function addTraining(Training $training): self
  179.     {
  180.         if (!$this->trainings->contains($training)) {
  181.             $this->trainings[] = $training;
  182.             $training->addDepartments($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removeTraining(Training $training): self
  187.     {
  188.         if ($this->trainings->contains($training)) {
  189.             $this->trainings->removeElement($training);
  190.             $training->removeDepartments($this);
  191.         }
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection|Announcement[]
  196.      */
  197.     public function getAnnouncements(): Collection
  198.     {
  199.         return $this->announcements;
  200.     }
  201.     public function addAnnouncement(Announcement $announcement): self
  202.     {
  203.         if (!$this->announcements->contains($announcement)) {
  204.             $this->announcements[] = $announcement;
  205.             $announcement->addDepartment($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeAnnouncement(Announcement $announcement): self
  210.     {
  211.         if ($this->announcements->contains($announcement)) {
  212.             $this->announcements->removeElement($announcement);
  213.             $announcement->removeDepartment($this);
  214.         }
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return Collection|Job[]
  219.      */
  220.     public function getJobs(): Collection
  221.     {
  222.         return $this->jobs;
  223.     }
  224.     public function addJob(Job $job): self
  225.     {
  226.         if (!$this->jobs->contains($job)) {
  227.             $this->jobs[] = $job;
  228.             $job->setDepartment($this);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeJob(Job $job): self
  233.     {
  234.         if ($this->jobs->removeElement($job)) {
  235.             // set the owning side to null (unless already changed)
  236.             if ($job->getDepartment() === $this) {
  237.                 $job->setDepartment(null);
  238.             }
  239.         }
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return Collection|AppraisalForm[]
  244.      */
  245.     public function getAppraisalForms(): Collection
  246.     {
  247.         return $this->appraisalForms;
  248.     }
  249.     public function addAppraisalForm(AppraisalForm $appraisalForm): self
  250.     {
  251.         if (!$this->appraisalForms->contains($appraisalForm)) {
  252.             $this->appraisalForms[] = $appraisalForm;
  253.             $appraisalForm->setDepartment($this);
  254.         }
  255.         return $this;
  256.     }
  257.     public function removeAppraisalForm(AppraisalForm $appraisalForm): self
  258.     {
  259.         if ($this->appraisalForms->removeElement($appraisalForm)) {
  260.             // set the owning side to null (unless already changed)
  261.             if ($appraisalForm->getDepartment() === $this) {
  262.                 $appraisalForm->setDepartment(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection<int, User>
  269.      */
  270.     public function getUsers(): Collection
  271.     {
  272.         return $this->users;
  273.     }
  274.     public function addUser(User $user): self
  275.     {
  276.         if (!$this->users->contains($user)) {
  277.             $this->users[] = $user;
  278.             $user->setDepartment($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeUser(User $user): self
  283.     {
  284.         if ($this->users->removeElement($user)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($user->getDepartment() === $this) {
  287.                 $user->setDepartment(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292.     /**
  293.      * @return Collection<int, TaskType>
  294.      */
  295.     public function getTaskTypes(): Collection
  296.     {
  297.         return $this->taskTypes;
  298.     }
  299.     public function addTaskType(TaskType $taskType): self
  300.     {
  301.         if (!$this->taskTypes->contains($taskType)) {
  302.             $this->taskTypes[] = $taskType;
  303.             $taskType->setDepartment($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeTaskType(TaskType $taskType): self
  308.     {
  309.         if ($this->taskTypes->removeElement($taskType)) {
  310.             // set the owning side to null (unless already changed)
  311.             if ($taskType->getDepartment() === $this) {
  312.                 $taskType->setDepartment(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|UserRole[]
  319.      */
  320.     public function getUserRoles(): Collection
  321.     {
  322.         return $this->userRoles;
  323.     }
  324.     public function addUserRole(UserRole $userRole): self
  325.     {
  326.         if (!$this->userRoles->contains($userRole)) {
  327.             $this->userRoles[] = $userRole;
  328.             $userRole->setDepartment($this);
  329.         }
  330.         return $this;
  331.     }
  332.     public function removeUserRole(UserRole $userRole): self
  333.     {
  334.         if ($this->userRoles->removeElement($userRole)) {
  335.             // set the owning side to null (unless already changed)
  336.             if ($userRole->getDepartment() === $this) {
  337.                 $userRole->setDepartment(null);
  338.             }
  339.         }
  340.         return $this;
  341.     }
  342.     /**
  343.      * @return Collection|Course[]
  344.      */
  345.     public function getCourses(): Collection
  346.     {
  347.         return $this->courses;
  348.     }
  349.     public function addCourse(Course $course): self
  350.     {
  351.         if (!$this->courses->contains($course)) {
  352.             $this->courses[] = $course;
  353.             $course->addDepartment($this);
  354.         }
  355.         return $this;
  356.     }
  357.     public function removeCourse(Course $course): self
  358.     {
  359.         if ($this->courses->removeElement($course)) {
  360.             $course->removeDepartment($this);
  361.         }
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection|CourseAutoEnrollment[]
  366.      */
  367.     public function getCourseAutoEnrollments(): Collection
  368.     {
  369.         return $this->courseAutoEnrollments;
  370.     }
  371.     public function addCourseAutoEnrollment(CourseAutoEnrollment $CourseAutoEnrollment): self
  372.     {
  373.         if (!$this->courseAutoEnrollments->contains($CourseAutoEnrollment)) {
  374.             $this->courseAutoEnrollments[] = $CourseAutoEnrollment;
  375.             $CourseAutoEnrollment->addDepartment($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeCourseAutoEnrollment(CourseAutoEnrollment $CourseAutoEnrollment): self
  380.     {
  381.         if ($this->courseAutoEnrollments->removeElement($CourseAutoEnrollment)) {
  382.             $CourseAutoEnrollment->removeDepartment($this);
  383.         }
  384.         return $this;
  385.     }
  386.     /**
  387.      * @return Collection|XeroLineItem[]
  388.      */
  389.     public function getXeroLineItems(): Collection
  390.     {
  391.         return $this->xeroLineItems;
  392.     }
  393.     public function addXeroLineItem(XeroLineItem $xeroLineItem): self
  394.     {
  395.         if (!$this->xeroLineItems->contains($xeroLineItem)) {
  396.             $this->xeroLineItems[] = $xeroLineItem;
  397.             $xeroLineItem->setDepartment($this);
  398.         }
  399.         return $this;
  400.     }
  401.     public function removeXeroLineItem(XeroLineItem $xeroLineItem): self
  402.     {
  403.         if ($this->xeroLineItems->removeElement($xeroLineItem)) {
  404.             // set the owning side to null (unless already changed)
  405.             if ($xeroLineItem->getDepartment() === $this) {
  406.                 $xeroLineItem->setDepartment(null);
  407.             }
  408.         }
  409.         return $this;
  410.     }
  411.     public function getAllManager($sort true$includeSub false)
  412.     {
  413.         $managers = [];
  414.         foreach ($this->getUsers() as $user) {
  415.             if ($user->getIsActive() == true && $user->getIsManager($includeSub)) array_push($managers$user);
  416.         };
  417.         if ($sort) {
  418.             usort($managers, function ($a$b) {
  419.                 return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
  420.             });
  421.         };
  422.         return $managers;
  423.     }
  424.     public function getAllSubManager($sort true)
  425.     {
  426.         $managers = [];
  427.         foreach ($this->getUsers() as $user) {
  428.             if ($user->getIsActive() && $subManagers $user->getAllManager($user->getManager())) {
  429.                 $managers array_merge($managers$subManagers);
  430.             }
  431.         }
  432.         if ($sort) {
  433.             usort($managers, function ($a$b) {
  434.                 return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
  435.             });
  436.         }
  437.         return $managers;
  438.     }
  439.     /**
  440.      * @return Collection<int, Checklist>
  441.      */
  442.     public function getChecklists(): Collection
  443.     {
  444.         return $this->checklists;
  445.     }
  446.     public function addChecklist(Checklist $checklist): self
  447.     {
  448.         if (!$this->checklists->contains($checklist)) {
  449.             $this->checklists->add($checklist);
  450.             $checklist->setDepartment($this);
  451.         }
  452.         return $this;
  453.     }
  454.     public function removeChecklist(Checklist $checklist): self
  455.     {
  456.         if ($this->checklists->removeElement($checklist)) {
  457.             // set the owning side to null (unless already changed)
  458.             if ($checklist->getDepartment() === $this) {
  459.                 $checklist->setDepartment(null);
  460.             }
  461.         }
  462.         return $this;
  463.     }
  464.     /**
  465.      * @return Collection<int, ChatbotSectionDepartment>
  466.      */
  467.     public function getChatbotSectionDepartments(): Collection
  468.     {
  469.         return $this->chatbotSectionDepartments;
  470.     }
  471.     public function addChatbotSectionDepartment(ChatbotSectionDepartment $chatbotSectionDepartment): self
  472.     {
  473.         if (!$this->chatbotSectionDepartments->contains($chatbotSectionDepartment)) {
  474.             $this->chatbotSectionDepartments->add($chatbotSectionDepartment);
  475.             $chatbotSectionDepartment->setDepartment($this);
  476.         }
  477.         return $this;
  478.     }
  479.     public function removeChatbotSectionDepartment(ChatbotSectionDepartment $chatbotSectionDepartment): self
  480.     {
  481.         if ($this->chatbotSectionDepartments->removeElement($chatbotSectionDepartment)) {
  482.             // set the owning side to null (unless already changed)
  483.             if ($chatbotSectionDepartment->getDepartment() === $this) {
  484.                 $chatbotSectionDepartment->setDepartment(null);
  485.             }
  486.         }
  487.         return $this;
  488.     }
  489.     /**
  490.      * @return Collection<int, ChatbotDepartmentPrompt>
  491.      */
  492.     public function getChatbotDepartmentPrompts(): Collection
  493.     {
  494.         return $this->chatbotDepartmentPrompts;
  495.     }
  496.     public function addChatbotDepartmentPrompt(ChatbotDepartmentPrompt $chatbotDepartmentPrompt): self
  497.     {
  498.         if (!$this->chatbotDepartmentPrompts->contains($chatbotDepartmentPrompt)) {
  499.             $this->chatbotDepartmentPrompts->add($chatbotDepartmentPrompt);
  500.             $chatbotDepartmentPrompt->setDepartment($this);
  501.         }
  502.         return $this;
  503.     }
  504.     public function removeChatbotDepartmentPrompt(ChatbotDepartmentPrompt $chatbotDepartmentPrompt): self
  505.     {
  506.         if ($this->chatbotDepartmentPrompts->removeElement($chatbotDepartmentPrompt)) {
  507.             // set the owning side to null (unless already changed)
  508.             if ($chatbotDepartmentPrompt->getDepartment() === $this) {
  509.                 $chatbotDepartmentPrompt->setDepartment(null);
  510.             }
  511.         }
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return Collection<int, DepartmentOverview>
  516.      */
  517.     public function getDepartmentOverviews(): Collection
  518.     {
  519.         return $this->departmentOverviews;
  520.     }
  521.     public function addDepartmentOverview(DepartmentOverview $departmentOverview): self
  522.     {
  523.         if (!$this->departmentOverviews->contains($departmentOverview)) {
  524.             $this->departmentOverviews->add($departmentOverview);
  525.             $departmentOverview->setDepartment($this);
  526.         }
  527.         return $this;
  528.     }
  529.     public function removeDepartmentOverview(DepartmentOverview $departmentOverview): self
  530.     {
  531.         if ($this->departmentOverviews->removeElement($departmentOverview)) {
  532.             // set the owning side to null (unless already changed)
  533.             if ($departmentOverview->getDepartment() === $this) {
  534.                 $departmentOverview->setDepartment(null);
  535.             }
  536.         }
  537.         return $this;
  538.     }
  539.     /**
  540.      * @return Collection<int, Vendor>
  541.      */
  542.     public function getVendors(): Collection
  543.     {
  544.         return $this->vendors;
  545.     }
  546.     public function addVendor(Vendor $vendor): self
  547.     {
  548.         if (!$this->vendors->contains($vendor)) {
  549.             $this->vendors->add($vendor);
  550.             $vendor->addDepartmentInCharge($this);
  551.         }
  552.         return $this;
  553.     }
  554.     public function removeVendor(Vendor $vendor): self
  555.     {
  556.         if ($this->vendors->removeElement($vendor)) {
  557.             $vendor->removeDepartmentInCharge($this);
  558.         }
  559.         return $this;
  560.     }
  561.     public function getLeader(): ?User
  562.     {
  563.         return $this->leader;
  564.     }
  565.     public function setLeader(?User $leader): self
  566.     {
  567.         $this->leader $leader;
  568.         return $this;
  569.     }
  570.     public function getPseudoLeader()
  571.     {
  572.         foreach ($this->users as $user) {
  573.             if ($user->getIsActive() == true && (in_array('ROLE_TEAM_LEADER'$user->getRoles()) || $user->getIsManager()) && (in_array('ROLE_OWNER'$user->getRoles()) || ($user->getManager() && in_array('ROLE_MANAGEMENT'$user->getManager()->getRoles())))) {
  574.                 return $user;
  575.             }
  576.         };
  577.         if ($this->getTotalActiveUser() == 1) {
  578.             foreach ($this->users as $user) {
  579.                 if ($user->getIsActive() == true) {
  580.                     return $user;
  581.                 }
  582.             };
  583.         }
  584.     }
  585. }