private function result() { $this->showNav(); if (isset($_POST['send'])) { $course = new courseModel(); $course->id = $_POST['cid']; $oneCourse = $course->getOneCourse(); $this->smarty->assign("oneCourse", $oneCourse); $user = new userModel(); $user->id = $_SESSION['oneUserName']->id; $oneUser = $user->getOneUserByID(); $this->smarty->assign("oneUser", $oneUser); $user->updateCountdown(); $num = 0; $str .= ""; $resultNum = 0; //echo $_POST['choiceNum']; while ($i < $_POST['choiceNum']) { $i++; $num++; //echo $_POST['choice'.($i)] $this->model->id = $_POST['choice' . $i]; //echo $this->model->id."<br>"; $oneChoice = $this->model->getOneChoice(); //Tools::dump($_POST['choice'][$i]); //echo $_POST['choice'][$_POST['choice'.($i)]]."<br>"; if ($oneChoice->answer == $_POST['choice'][$_POST['choice' . $i]]) { $str .= "<div class='item'><dt>" . $num . "." . $oneChoice->question; $str .= "<span class='glyphicon glyphicon-ok right'></span>"; $str .= "</dt>"; $resultNum++; } else { $str .= "<div class='item'><dt>" . $num . "." . $oneChoice->question; $str .= "<span class='glyphicon glyphicon-remove wrong'></span>"; $str .= "</dt>"; if ($_POST['choice'][$_POST['choice' . $i]] != '') { $str .= "<dd class='failed'><b style='color:green;'>正确答案是:" . $oneChoice->answer . "</b>,"; $str .= "<span class='wrong'>您选择的是:" . $_POST['choice'][$_POST['choice' . $i]] . "。<span></dd>"; $str .= "<dd style='margin-bottom:3px;' class='alert alert-danger'><b style='color:red'>提示:</b>" . $oneChoice->tips . "</dd>"; } else { $str .= "<dd class='wrong'>您未答此题</dd>"; } } $str .= "<dd>A." . $oneChoice->a . "</dd>"; $str .= "<dd>B." . $oneChoice->b . "</dd>"; $str .= "<dd>C." . $oneChoice->c . "</dd>"; $str .= "<dd>D." . $oneChoice->d . "</dd></div>"; } ////////judge///////////////// $num2 = 0; $str2 .= ""; $resultNum2 = 0; //echo $_POST['choiceNum']; //echo $_POST['judgeNum']; while ($j < $_POST['judgeNum']) { $j++; $num2++; //echo $_POST['choice'.($i)] $this->model->id = $_POST['judge' . $j]; $oneJudge = $this->model->getOneJudge(); //Tools::dump($_POST['choice'][$i]); //echo $_POST['choice'][$_POST['choice'.($i)]]."<br>"; if ($oneJudge->answer == $_POST['judge'][$_POST['judge' . $j]]) { $str2 .= "<div class='item'><dt>" . $num2 . "." . $oneJudge->question; $str2 .= "<span class='glyphicon glyphicon-ok right'></span>"; $str2 .= "</dt></div>"; $resultNum2++; } else { $str2 .= "<div class='item'><dt>" . $num2 . "." . $oneJudge->question; $str2 .= "<span class='glyphicon glyphicon-remove wrong'></span>"; $str2 .= "</dt>"; if ($_POST['judge'][$_POST['judge' . $j]] != '') { switch ($oneJudge->answer) { case '1': $answer = "正确"; break; case "0": $answer = "错误"; } switch ($_POST['judge'][$_POST['judge' . $j]]) { case '1': $answer2 = "正确"; break; case "0": $answer2 = "错误"; } $str2 .= "<dd><span class='wrong'>正确答案是:" . $answer . "</span>,"; $str2 .= "<span class='wrong'>您选择的是:" . $answer2 . "。<span></dd>"; $str2 .= "<dd style='margin-bottom:3px;' class='alert alert-danger'><b style='color:red'>提示:</b>" . $oneJudge->tips . "</dd>"; } else { $str2 .= "<dd class='wrong'>您未答此题</dd>"; } $str2 .= "<dd>A.正确,"; $str2 .= "B.错误</dd></div>"; } } // $user = new userModel(); $examination = new examinationModel(); $userLeaderboard = $examination->getUserLeaderboard(); $allCourse = $course->getFrontCourse(); $arr = array(); foreach ($allCourse as $key => $value) { $examination->cid = $value->id; $hotExam = $examination->getExamByCID(); foreach ($hotExam as $k => $v) { $user->id = $v->uid; $oneUser = $user->getOneUserByID(); $v->uid = $oneUser->username; } $arr[$value->name] = $hotExam; } //Tools::dump($arr); $this->smarty->assign("arr", $arr); $this->model->uid = $_POST['uid']; $this->model->cid = $_POST['cid']; $this->model->total = $_POST['choiceNum'] + $_POST['judgeNum']; $this->model->ticked = count($_POST['judge']) + count($_POST['choice']); $this->model->rightNum = $resultNum + $resultNum2; //$this->model->score=$resultNum*10+$resultNum2*10; $this->model->score = number_format(($resultNum + $resultNum2) / ($_POST['choiceNum'] + $_POST['judgeNum']) * 100, 2); $this->model->createExam(); } $this->smarty->assign("total", $_POST['choiceNum'] + $_POST['judgeNum']); $this->smarty->assign("ticked", count($_POST['judge']) + count($_POST['choice'])); $this->smarty->assign("choiceOutput", $str); $this->smarty->assign("judgeOutput", $str2); $this->smarty->assign("resultNum", $resultNum); $this->smarty->assign("resultNum2", $resultNum2); $this->smarty->assign("score", number_format(($resultNum + $resultNum2) / ($_POST['choiceNum'] + $_POST['judgeNum']) * 100, 2)); $this->smarty->assign("result", true); }