protected function persistLink(Competency $competency, Ability $ability, Level $level)
 {
     $link = new CompetencyAbility();
     $link->setCompetency($competency);
     $link->setAbility($ability);
     $link->setLevel($level);
     $this->om->persist($link);
     return $link;
 }
 /**
  * Creates a link between a competency and an existing ability.
  *
  * @param Competency $parent
  * @param Ability $ability
  * @param Level $level
  * @return Ability
  * @throws \LogicException if a link already exists
  */
 public function linkAbilityToCompetency(Competency $parent, Ability $ability, Level $level)
 {
     $link = $this->competencyAbilityRepo->findOneBy(['competency' => $parent, 'ability' => $ability]);
     if ($link) {
         throw new \LogicException("Ability {$ability->getId()} is already linked to competency {$parent->getId()}");
     }
     $link = new CompetencyAbility();
     $link->setCompetency($parent);
     $link->setAbility($ability);
     $link->setLevel($level);
     $this->om->persist($link);
     $this->om->flush();
     return $ability;
 }
 public function testLoadAbility()
 {
     $ability = new Ability();
     $level = new Level();
     $parent = new Competency();
     $link = new CompetencyAbility();
     $link->setLevel($level);
     $this->competencyAbilityRepo->expects($this->once())->method('findOneByTerms')->with($parent, $ability)->willReturn($link);
     $this->manager->loadAbility($parent, $ability);
     $this->assertEquals($level, $ability->getLevel());
 }
示例#4
0
 private function walkJsonNodes(\stdClass $parentData, Competency $parentCompetency, Scale $scale)
 {
     if (isset($parentData->competencies)) {
         foreach ($parentData->competencies as $competency) {
             $newCompetency = new Competency();
             $newCompetency->setName($competency->name);
             $newCompetency->setParent($parentCompetency, true);
             $this->walkJsonNodes($competency, $newCompetency, $scale);
         }
     } else {
         foreach ($parentData->abilities as $ability) {
             $newAbility = new Ability();
             $newAbility->setName($ability->name);
             $level = null;
             foreach ($scale->getLevels() as $scaleLevel) {
                 if ($scaleLevel->getName() === $ability->level) {
                     $level = $scaleLevel;
                     break;
                 }
             }
             $link = new CompetencyAbility();
             $link->setCompetency($parentCompetency);
             $link->setAbility($newAbility);
             $link->setLevel($level);
         }
     }
     return $parentCompetency;
 }