_askedQuestions; } public function setAskedQuestions(array $questions) { $this->_askedQuestions = $questions; } /** * Returns a not asked random question * @return Quiz_Question */ public function getRandomQuestion() { $askedIds = array(); foreach($this->_askedQuestions as $a) $askedIds[] = $a['id']; $dao = App_DaoFactory::getFactory()->getQuestionDao(); return $dao->fetchRandomQuestionNotIn($askedIds); } public function getBestAnswer() { if(count($this->_askedQuestions) === 0) throw new App_Questioner_Exception('No asked questions set, cant provide best answer'); $iterations = array(); $qaDao = App_DaoFactory::getFactory()->getQuestionAnswerDao(); foreach($this->_askedQuestions as $q) { $qa = new Quiz_QuestionAnswer(); $qa->setQuestionId($q['id']); $qa->setChoice($q['choice']); $prevIterAnswers = array(); if(count($iterations) > 0) $prevIterAnswers = $iterations[ count($iterations) - 1 ]; $possibleAnswers = array(); if(count($prevIterAnswers) > 0) { foreach($prevIterAnswers as $a) $possibleAnswers[] = $a['answer_id']; } $iterations[] = $qaDao->fetchAnswersTo($qa, $possibleAnswers); } $iterations = array_reverse($iterations); foreach($iterations as $i) { if(count($i) > 0) { $dao = App_DaoFactory::getFactory()->getAnswerDao(); return $dao->findAnswer($i[0]); } } return null; } }