Exemple #1
0
 public function answerEnd()
 {
     $app = \Slim\Slim::getInstance();
     $params = $app->request->params();
     $answer = new M_Answer();
     $answerId = $answer->answerEnd($params['answer_id'], $params['answer1'], $params['answer2'], $params['answer3'], $params['answer4'], $params['answer5'], $params['answer6'], $params['answer7'], $params['answer8'], $params['answer9'], $params['answer10']);
     $result = $answer->showResult($answerId);
     $app->render('Answer/answer_end.twig', ['result' => $result]);
 }
Exemple #2
0
 public function showResult($answerId)
 {
     //該当するanswerIdの解答結果を取得
     $answer = new Answer();
     $answerResult = $answer->find($answerId);
     //各問題の正解を取得
     $quiz = new M_Quiz();
     $quiz = $quiz->find($answerResult['quiz_id']);
     $questions = M_Quiz::find($quiz['id'])->questions;
     //解答結果と正解を比較
     $correctNumber = 0;
     if ($answerResult['answer1'] === $questions[0]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer2'] === $questions[1]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer3'] === $questions[2]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer4'] === $questions[3]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer5'] === $questions[4]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer6'] === $questions[5]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer7'] === $questions[6]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer8'] === $questions[7]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer9'] === $questions[8]['correct_answer']) {
         $correctNumber++;
     }
     if ($answerResult['answer10'] === $questions[9]['correct_answer']) {
         $correctNumber++;
     }
     //解答時間を計算
     $responseTime = strtotime($answerResult['end_time']) - strtotime($answerResult['start_time']);
     //正解数と解答時間を返却
     return array('nickname' => $answerResult['nickname'], 'correctNumber' => $correctNumber, 'responseTime' => $responseTime);
 }
Exemple #3
0
 public function testShowResult()
 {
     //解答情報を作成
     $answer = new M_Answer();
     //解答スタート
     $answerId = $answer->answerStart(1, 'land');
     //2秒待つ
     sleep(2);
     //解答終了
     $answer->answerEnd($answerId, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3);
     //結果確認
     $answerResult = $answer->find(1);
     //結果集計
     $answer = new M_Answer();
     $result = $answer->showResult($answerId);
     //結果比較
     $this->assertEquals(10, $result['correctNumber']);
     $this->assertEquals(2, $result['responseTime']);
 }