Пример #1
0
        $json = $q->getTestDetails($testName);
        echo $json;
    }
}
if ($action == 'TestDetails') {
    $testName = $_GET["courseName"];
    $testType = $_GET["testType"];
    $q = new Questions();
    $json = $q->getAllTestDetails($testName, $testType);
    echo $json;
}
if ($action == 'GetQuestions') {
    $testDetailsId = $_GET["TestDetailsID"];
    $qtotal = $_GET["qtotal"];
    $q = new Questions();
    $json = $q->getQuestions($testDetailsId, '1', $qtotal);
    $dejson = json_decode($json);
    // Decode and Build JSON
    $jsonbuilder = "[";
    for ($ind = 0; $ind < count($dejson); $ind++) {
        $testId = str_replace("%0A", "", $dejson[$ind]->{'idTestQuestions'});
        $question = str_replace("%0A", "", $dejson[$ind]->{'question'});
        $option1 = str_replace("%0A", "", $dejson[$ind]->{'option1'});
        $option2 = str_replace("%0A", "", $dejson[$ind]->{'option2'});
        $option3 = str_replace("%0A", "", $dejson[$ind]->{'option3'});
        $option4 = str_replace("%0A", "", $dejson[$ind]->{'option4'});
        $jsonbuilder .= "{";
        $jsonbuilder .= "\"idTestQuestions\":" . "\"" . chop(urldecode($testId), " ") . "\",";
        $jsonbuilder .= "\"question\":" . "\"" . chop(urldecode($question), " ") . "\",";
        $jsonbuilder .= "\"option1\":" . "\"" . chop(urldecode($option1), " ") . "\",";
        $jsonbuilder .= "\"option2\":" . "\"" . chop(urldecode($option2), " ") . "\",";
Пример #2
-1
 /**
  * Пересчитывает результат теста (вместо процентов - баллы)
  * @return void
  */
 public function recalcAction()
 {
     if ($this->_authorize('test', 'edit')) {
         $link = $this->getRequest()->getParam('link');
         $objApplicantTests = new ApplicantTests();
         $applicantTest = $objApplicantTests->getTest($link);
         if (empty($applicantTest)) {
             exit;
         }
         $applicantId = $applicantTest->applicant_id;
         $testId = $applicantTest->test_id;
         $applicantTestId = $applicantTest->id;
         $objQuestion = new Questions();
         $questions = $objQuestion->getQuestions($testId);
         $questions = $this->convertArr($questions, 'tq_id');
         $objTestAnswers = new Answers();
         $answers = $objTestAnswers->getAnswers(array_keys($questions));
         // ключем $answers будет id вопроса
         $answers = $this->convertArr($answers, 'tq_id', true);
         $objApplicantAnswers = new ApplicantAnswers();
         $applicantAnswers = $objApplicantAnswers->getAnswers($applicantTestId);
         $applicantAnswers = $this->convertArr($applicantAnswers, 'answer_id');
         $result = $this->calcTestScore($questions, $answers, $applicantAnswers);
         $applicantTest->score = $result['score'];
         $applicantTest->percent = $result['percent'];
         $applicantTest->save();
     }
     $this->_helper->redirector('testing', 'test', null, array('link' => $link));
 }