예제 #1
0
 public function prepareQuestionsForUser($User, $UserQuizSet)
 {
     $Questions = $this->getQuestionsForSet($UserQuizSet->getIdSet());
     if (empty($Questions)) {
         return false;
     }
     $questionCount = count($Questions);
     $userQuestionsGenerated = $this->checkUsersQuestions($questionCount, $User->getId(), $UserQuizSet->getIdSet());
     if (!$userQuestionsGenerated) {
         $QuestionsToUserSet = QuestionToUserSet::createUserQuestions($User, $Questions, $UserQuizSet);
         $this->saveToDoctrine($QuestionsToUserSet);
         return true;
     }
     $QuestionsToAdd = array();
     foreach ($Questions as $question) {
         $idQuestion = $question->getId();
         $toAdd = true;
         foreach ($userQuestionsGenerated as $userQuestion) {
             if ($idQuestion == $userQuestion->getIdQuestion()) {
                 $toAdd = false;
                 break;
             }
         }
         if ($toAdd) {
             $QuestionsToAdd[] = $question;
         }
     }
     if (!empty($QuestionsToAdd)) {
         $QuestionsToUserSet = QuestionToUserSet::createUserQuestions($User, $QuestionsToAdd, $UserQuizSet);
         $this->saveToDoctrine($QuestionsToUserSet);
         return true;
     }
     return false;
 }