/** * Define o cargo imediatamente superior e o papel herdado. * * Se já existe um cargo pai retira o papel correspondente ao cargo filho. Se não existe, adiciona o papel * correspondente ao cargo filho. A referência do pai anterior deve ser guardada para ser salva no banco. * * @param \AdministrativeStructure\Entity\Job $parent * @return Self */ public function setParent(Job $parent) { $this->initRole(); if (isset($this->parent) && $parent->getJobId() !== $this->parent->getJobId()) { $this->parentBuffer = $this->parent; $this->parentBuffer->removeChildren(new ArrayCollection([$this])); } $parent->addChildren(new ArrayCollection([$this])); $this->parent = $parent; return $this; }
/** * Define qual o trabalho do cargo. * * @param AdministrativeStructure\Entity\Job $job Trabalho ao qual o cargo estará associado * @return Self */ public function setJob(Job $job) { $job->addOffices(new ArrayCollection([$this])); $this->job = $job; return $this; }
/** * Busca em profundidade. * * Monta a árvore de cargos * * @param type $jobModel Cargo pai * @return array Árvore de cargos */ protected function depthFirstSearch(Job $jobModel) { $childrenArr = []; $jobArr = ['id' => $jobModel->getJobId(), 'name' => $jobModel->getJobName(), 'department' => $jobModel->getDepartment()->getDepartmentName(), 'children' => &$childrenArr]; $children = $jobModel->getChildren()->toArray(); foreach ($children as $child) { $childrenArr[] = $this->depthFirstSearch($child); } return $jobArr; }