Example #1
0
 private function makeLevel($name, $value)
 {
     $level = new Level();
     $level->setName($name);
     $level->setValue($value);
     return $level;
 }
 public function testSubmitValidData()
 {
     $scale = new Scale();
     $scale->setName('Scale 1');
     $level = new Level();
     $level->setName('Level 1');
     $level->setValue(0);
     $level->setScale($scale);
     $parent = new Competency();
     $parent->setName('Competency 1');
     $parent->setScale($scale);
     $ability = new Ability();
     $ability->setName('Foo');
     $this->om->persist($scale);
     $this->om->persist($level);
     $this->om->persist($parent);
     $this->om->persist($ability);
     $this->om->flush();
     $formData = ['ability' => 'Foo', 'level' => $level->getId()];
     $form = $this->factory->create(new AbilityImportType($this->om), null, ['competency' => $parent]);
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($ability, $form->getData());
     $this->assertEquals($level, $ability->getLevel());
     $this->assertViewIsValid($form, $formData);
 }
 public function testSubmitValidData()
 {
     $scale = new Scale();
     $scale->setName('Scale 1');
     $level = new Level();
     $level->setName('Level 1');
     $level->setValue(0);
     $level->setScale($scale);
     $parent = new Competency();
     $parent->setName('Competency 1');
     $parent->setScale($scale);
     $om = $this->client->getContainer()->get('claroline.persistence.object_manager');
     $om->persist($scale);
     $om->persist($level);
     $om->persist($parent);
     $om->flush();
     $formData = ['name' => 'Foo', 'level' => $level->getId(), 'minActivityCount' => 2];
     $form = $this->factory->create(new AbilityType(), null, ['competency' => $parent]);
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $ability = $form->getData();
     $this->assertInstanceOf('HeVinci\\CompetencyBundle\\Entity\\Ability', $ability);
     $this->assertEquals('Foo', $ability->getName());
     $this->assertEquals($level, $ability->getLevel());
     $this->assertEquals(2, $ability->getMinActivityCount());
     $this->assertViewIsValid($form, $formData);
 }
 public function validValueProvider()
 {
     $levelOne = new Level();
     $levelOne->setName('A');
     $levelTwo = new Level();
     $levelTwo->setName('B');
     $levelConstraint = new NoDuplicate();
     $levelConstraint->property = 'name';
     return [[['foo', 'bar', 'baz'], new NoDuplicate()], [new ArrayCollection([$levelOne, $levelTwo]), $levelConstraint]];
 }
 protected function persistLevel($name, Scale $scale, $value = 0)
 {
     $level = new Level();
     $level->setName($name);
     $level->setValue($value);
     $level->setScale($scale);
     $scale->addLevel($level);
     $this->om->persist($level);
     return $level;
 }
 /**
  * Transforms a multi-line string of level names to an
  * ArrayCollection of Level entities.
  *
  * @param string $levels
  *
  * @return ArrayCollection
  */
 public function reverseTransform($levels)
 {
     $collection = new ArrayCollection();
     $names = explode("\n", $levels);
     $value = 0;
     foreach ($names as $name) {
         if ($trimmedName = trim($name)) {
             $level = new Level();
             $level->setName($trimmedName);
             $level->setValue($value);
             $collection->add($level);
             ++$value;
         }
     }
     return $collection;
 }
Example #7
0
 /**
  * Converts a JSON representation of a competency framework
  * into an entity graph (without persisting it).
  *
  * @param string $jsonFramework
  * @return Competency
  */
 public function convertToEntity($jsonFramework)
 {
     $frameworkData = json_decode($jsonFramework);
     $scaleRepo = $this->om->getRepository('HeVinciCompetencyBundle:Scale');
     if (!($scale = $scaleRepo->findOneBy(['name' => $frameworkData->scale->name]))) {
         $scale = new Scale();
         $scale->setName($frameworkData->scale->name);
         for ($i = 0, $levels = $frameworkData->scale->levels, $max = count($levels); $i < $max; ++$i) {
             $level = new Level();
             $level->setName($levels[$i]);
             $level->setValue($i);
             $level->setScale($scale);
             $scale->addLevel($level);
         }
     }
     $framework = new Competency();
     $framework->setName($frameworkData->name);
     $framework->setDescription($frameworkData->description);
     $framework->setScale($scale);
     return $this->walkJsonNodes($frameworkData, $framework, $scale);
 }
Example #8
0
 public function jsonSerialize()
 {
     return ['id' => $this->id, 'name' => $this->name, 'activityCount' => $this->activityCount, 'minActivityCount' => $this->minActivityCount, 'levelName' => $this->level ? $this->level->getName() : null, 'levelValue' => $this->level ? $this->level->getValue() : null];
 }
 /**
  * Creates a default scale if no scale exists yet.
  */
 public function ensureHasScale()
 {
     if (!$this->hasScales()) {
         $defaultScale = new Scale();
         $defaultScale->setName($this->translator->trans('scale.default_name', [], 'competency'));
         $defaultLevel = new Level();
         $defaultLevel->setValue(0);
         $defaultLevel->setName($this->translator->trans('scale.default_level_name', [], 'competency'));
         $defaultScale->setLevels(new ArrayCollection([$defaultLevel]));
         $this->om->persist($defaultScale);
         $this->om->flush();
     }
 }
 /**
  * @param Level $level
  */
 public function setLevel(Level $level)
 {
     $this->level = $level;
     $this->levelName = $level->getName();
 }
 /**
  * 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;
 }