Ejemplo n.º 1
0
 /**
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Quiz $quiz
  */
 protected function preFillGrades($quiz)
 {
     $gradeOptions = $this->gradeRepository->findAll();
     // Sorted Highest to Lowest grade
     $maxScore = $quiz->getMaxScore();
     if ($maxScore >= count($gradeOptions)) {
         $increment = max(floor($maxScore / (count($gradeOptions) - 1)), 1);
         $lastMax = $maxScore;
         $lastMin = max($maxScore - $increment, 0) + 1;
         //Always end with 0 (also in the start)
         if ($lastMin - $increment < 1) {
             $lastMin = 0;
         }
         $iteration = 1;
         foreach ($gradeOptions as $grade) {
             if ($iteration == count($gradeOptions) - 1) {
                 //Second last always has a minimum of 1
                 $lastMin = 1;
             } elseif ($iteration == count($gradeOptions)) {
                 //Always end with 0/0 for the lowest grade
                 $lastMax = 0;
                 $lastMin = 0;
             }
             $quizGrade = new \_OurBrand_\Quiz\Domain\Model\QuizGrade();
             $quizGrade->setQuiz($quiz);
             $quizGrade->setGrade($grade);
             $quizGrade->setMaximumScore($lastMax);
             $lastMax = max($lastMax - $increment, 0);
             $quizGrade->setMinimumScore($lastMin);
             $lastMin = max($lastMax - $increment, 0) + 1;
             $this->quizGradeRepository->add($quizGrade);
             $iteration++;
         }
         $this->persistenceManager->persistAll();
     }
 }