protected function persistObjective($name, array $competenciesData) { $objective = new Objective(); $objective->setName($name); foreach ($competenciesData as $competencyData) { $link = new ObjectiveCompetency(); $link->setCompetency($competencyData[0]); $link->setFramework($competencyData[1]); $link->setLevel($competencyData[2]); $this->om->persist($link); $objective->addObjectiveCompetency($link); } $this->om->persist($objective); return $objective; }
/** * Creates an association between an objective and a competency, * with an expected level. Returns a full array representation of * the newly associated competency if the link doesn't already exist. * Otherwise, returns false. * * @param Objective $objective * @param Competency $competency * @param Level $level * * @return mixed array|bool * * @throws \LogicException if the level doesn't belong to the root competency scale */ public function linkCompetency(Objective $objective, Competency $competency, Level $level) { $link = $this->objectiveCompetencyRepo->findOneBy(['competency' => $competency, 'objective' => $objective]); if ($link) { return false; } $framework = $this->competencyRepo->findOneBy(['root' => $competency->getRoot()]); if ($level->getScale() !== $framework->getScale()) { throw new \LogicException('Objective level must belong to the root competency scale'); } $link = new ObjectiveCompetency(); $link->setObjective($objective); $link->setCompetency($competency); $link->setLevel($level); $link->setFramework($framework); $this->om->persist($link); $this->om->flush(); $this->progressManager->recomputeObjectiveProgress($objective); $competency = $this->competencyManager->loadCompetency($competency); $competency['id'] = $link->getId(); // link is treated as the competency itself on client-side $competency['framework'] = $framework->getName(); $competency['level'] = $level->getName(); return $competency; }