コード例 #1
0
 protected function persistCompetencyProgress(User $user, Competency $competency)
 {
     $progress = new CompetencyProgress();
     $progress->setUser($user);
     $progress->setCompetency($competency);
     $this->om->persist($progress);
     return $progress;
 }
コード例 #2
0
 private function computeObjectives(CompetencyProgress $progress)
 {
     // only a fully acquired competency can make the objectives progress vary
     if ($progress->getPercentage() < 100) {
         return;
     }
     $competency = $progress->getCompetency();
     $user = $progress->getUser();
     // find linked objectives
     $objectives = $this->objectiveRepo->findByCompetencyAndUser($competency, $user);
     // remove objectives for which the acquired competency level is insufficient
     $objectives = array_filter($objectives, function ($objective) use($progress, $competency) {
         foreach ($objective->getObjectiveCompetencies() as $link) {
             if ($link->getCompetency() === $competency && $link->getLevel()->getValue() > $progress->getLevel()->getValue()) {
                 return false;
             }
         }
         return true;
     });
     // compute each objective percentage
     for ($i = 0, $objectiveCount = count($objectives); $i < $objectiveCount; ++$i) {
         $this->computeUserObjective($objectives[$i], $user);
     }
     if ($objectiveCount > 0) {
         $this->computeUserProgress($user);
     }
 }