Пример #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();
     }
 }
 /**
  * Generate a new Grade
  *
  * This command inserts a new Grade record into the database. Mostly used for development while management
  * tools for grades are not yet available
  *
  * @param string $value The value of the grade to generate
  * @param int $sorting The sorting of the grade
  * @return void
  */
 public function gradeCommand($value, $sorting)
 {
     $grade = new Grade($value, $sorting);
     $this->gradeRepository->add($grade);
     $this->outputLine('Grade with value "%s" added to the database.', array($value));
 }