Пример #1
0
$sql = "SELECT max_score FROM #__guru_quiz WHERE id=" . $quiz_id;
$database->setQuery($sql);
$result_maxscore = $database->loadResult();
if ($number_of_questions > 0) {
    $score = intval($how_many_right_answers / $number_of_questions * 100);
} else {
    $score = 0;
}
if ($score >= $result_maxscore) {
    $score = $score . " %" . JText::_('GURU_QUIZ_PASSED');
} else {
    $score = $score . " %" . JText::_('GURU_QUIZ_FAILED');
}
$ans_gived = $guruModelguruOrder->getAnsGivedF($user_id, $id);
$ans_right = $guruModelguruOrder->getAnsRightF($quiz_id);
$the_question = $guruModelguruOrder->getQuestionNameF($id, $quiz_id);
$all_answers_array = $guruModelguruOrder->getAllAnsF($quiz_id, $id);
$all_answers_text_array = $guruModelguruOrder->getAllAnsTextF($quiz_id, $id);
for ($i = 0; $i < $number_of_questions; $i++) {
    $answer_count = 0;
    $all_answers_array_result = explode("|||", $all_answers_array[$i]);
    $all_answers_text_array_result = explode("|||", $all_answers_text_array[$i]);
    $ans_right_result = explode("|||", $ans_right[$i]->answers);
    $ans_gived_result = explode(" ||", $ans_gived[$i]->answers_gived);
    for ($t = 0; $t < count($ans_gived_result); $t++) {
        if ($ans_gived_result[$t] != "") {
            if (!in_array($ans_gived_result[$t], $ans_right_result)) {
                $gasit = false;
                break;
            } else {
                $gasit = true;
Пример #2
0
    function generatePassed_Failed_quizzes($quiz_id, $course_id, $number_of_questions, $pass)
    {
        $time_quiz_taken = "";
        $database = JFactory::getDBO();
        $db = JFactory::getDBO();
        $user = JFactory::getUser();
        $user_id = $user->id;
        $date = date('Y-m-d h:i:s');
        $quiz_form_content = "";
        $resultt = "";
        $your_score_text = JText::_("GURU_YOUR_SCORE");
        $guruModelguruOrder = new guruModelguruOrder();
        $id_quiz_question_row = JRequest::getVar("id_quiz_question", "");
        $sql = "SELECT show_countdown, max_score, questions_per_page FROM #__guru_quiz WHERE id=" . intval($quiz_id);
        $database->setQuery($sql);
        $result = $database->loadObject();
        $sql = "SELECT id, score_quiz, time_quiz_taken_per_user  FROM #__guru_quiz_taken WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($quiz_id) . " and pid=" . intval($course_id) . " ORDER BY id DESC LIMIT 0,1";
        $database->setQuery($sql);
        $result_q = $database->loadObject();
        if ($time_quiz_taken < 11) {
            $time_user = $time_quiz_taken - $result_q->time_quiz_taken_per_user;
        }
        $first = explode("|", @$result_q->score_quiz);
        @($res = intval($first[0] / $first[1] * 100));
        $k = 0;
        $quiz_id = intval($quiz_id);
        $id = intval($result_q->id);
        $quiz_name = $guruModelguruOrder->getQuizNameF($quiz_id);
        $number_of_questions = $first[1];
        $score = $res . " %";
        $ans_gived = $guruModelguruOrder->getAnsGivedFr($user_id, $id, $quiz_id);
        $ans_right = $guruModelguruOrder->getAnsRightFr($quiz_id, $id);
        $the_question = $guruModelguruOrder->getQuestionNameF($id, $quiz_id);
        $all_answers_array = $guruModelguruOrder->getAllAnsF($quiz_id, $id);
        $all_answers_text_array = $guruModelguruOrder->getAllAnsTextF($quiz_id, $id);
        if ($pass == 1) {
            @($quiz_result_content .= '<div class ="guru-quiz-timer">');
            $quiz_result_content .= '<span>' . JText::_("GURU_QUIZ_PASSED_TEXT") . '<span style="color:#669900;">' . $score . '</span>' . ',' . " " . JText::_("GURU_MIN_TO_PASS") . " " . '<span style="color:#669900;">' . $result->max_score . JText::_("GURU_PERCENT") . '</span></span>';
            $quiz_result_content .= '<br/>' . '<span>' . JText::_("GURU_CONGRAT") . '</span>';
            $quiz_result_content .= '<br/></br>' . '<span>' . JText::_("GURU_COURSE_CONTINUE_COURSE") . '</span>';
            $quiz_result_content .= '</div>';
        } else {
            @($quiz_result_content .= '<div class ="guru-quiz-timer">');
            $quiz_result_content .= '<span>' . JText::_("GURU_QUIZ_FAILED_TEXT") . '<span style="color:#669900;">' . $score . '</span>' . ',' . " " . JText::_("GURU_MIN_TO_PASS") . " " . '<span style="color:#669900;">' . $result->max_score . JText::_("GURU_PERCENT") . '</span></span>';
            $quiz_result_content .= '</div><br/>';
        }
        $quiz_result_content .= '<div id="the_quiz">';
        $per_page = $result->questions_per_page;
        // questions per page
        if ($per_page == 0) {
            $per_page = $number_of_questions;
        }
        $nr_pages = 1;
        // default one page
        if ($number_of_questions > 0 && $number_of_questions > $per_page) {
            $nr_pages = ceil($number_of_questions / $per_page);
        }
        for ($pag = 1; $pag <= $nr_pages; $pag++) {
            $k = ($pag - 1) * $per_page;
            $added = 0;
            $display = "";
            if ($pag == 1) {
                $display = "block";
            } else {
                $display = "none";
            }
            $quiz_result_content .= '<div id="quiz_page_' . $pag . '" style="display:' . $display . ';">';
            // start page
            for ($i = $k; $i < intval($pag * $per_page); $i++) {
                if (!isset($all_answers_array[$i])) {
                    continue;
                }
                $answer_count = 0;
                $all_answers_array_result = explode("|||", $all_answers_array[$i]);
                $all_answers_array_result = $this->eliminateBlankAnswers($all_answers_array_result);
                $all_answers_text_array_result = explode("|||", $all_answers_text_array[$i]);
                $ans_right_result = explode("|||", $ans_right[$i]->answers);
                $ans_gived_result = explode(" ||", $ans_gived[$i]->answers_gived);
                $all_answers_text_array_result = $this->eliminateBlankAnswers($all_answers_text_array_result);
                $ans_right_result = $this->eliminateBlankAnswers($ans_right_result);
                $ans_gived_result = $this->eliminateBlankAnswers($ans_gived_result);
                @($quiz_result_content .= '<ul class="guru_list">');
                $empty_elements = array("");
                $ans_gived_result = array_diff($ans_gived_result, $empty_elements);
                if (count(array_intersect($ans_right_result, $ans_gived_result)) == count($ans_right_result) && count($ans_gived_result) == count($ans_right_result)) {
                    $answer_count++;
                    $quiz_result_content .= '<li class="question right">' . str_replace("\\'", "&acute;", $the_question[$i]->text) . '</li>';
                } else {
                    $quiz_result_content .= '<li class="question wrong g_quize_q">' . str_replace("\\'", "&acute;", $the_question[$i]->text) . '</li>';
                }
                for ($j = 0; $j < count($all_answers_array_result); $j++) {
                    if ($all_answers_array_result[$j] != "") {
                        //--------------------------------------------
                        $inArray = in_array($all_answers_array_result[$j], $ans_right_result);
                        //--------------------------------------------
                        if ($inArray) {
                            $quiz_result_content .= '<li class="correct">' . $all_answers_text_array_result[$j] . '</li>';
                        } else {
                            $quiz_result_content .= '<li class="incorrect">' . $all_answers_text_array_result[$j] . '</li>';
                        }
                    }
                }
                $quiz_result_content .= '</ul>';
            }
            $quiz_result_content .= '</div>';
            // end page
        }
        if ($nr_pages > 1) {
            $quiz_result_content .= '<div class="pagination pagination-centered"><ul class="uk-pagination">';
            $quiz_result_content .= '<li class="pagination-start" id="pagination-start"><span class="pagenav">' . JText::_("GURU_START") . '</span></li>';
            $quiz_result_content .= '<li class="pagination-prev" id="pagination-prev"><span class="pagenav">' . JText::_("GURU_PREV") . '</span></li>';
            for ($p = 1; $p <= $nr_pages; $p++) {
                if ($p == 1) {
                    $quiz_result_content .= '<li id="list_1"><span class="pagenav">1</span></li>';
                } else {
                    $quiz_result_content .= '<li id="list_' . $p . '">
										<a onclick="changePage(' . intval($p) . ', ' . intval($nr_pages) . '); return false;" href="#">' . $p . '</a>
									 </li>';
                }
            }
            $quiz_result_content .= '<li class="pagination-next" id="pagination-next">
									<a href="#" onclick="changePage(2, ' . intval($nr_pages) . '); return false;">' . JText::_("GURU_NEXT") . '</a>
								 </li>';
            $quiz_result_content .= '<li class="pagination-end" id="pagination-end">
									<a href="#" onclick="changePage(' . intval($nr_pages) . ', ' . intval($nr_pages) . '); return false;">' . JText::_("GURU_END") . '</a>
								 </li>';
            $quiz_result_content .= '</ul></div>';
        }
        $quiz_result_content .= '</div>';
        $quiz_form_header = "";
        if (@$quiz_details["0"]["is_final"] == 0) {
            $lang_quizpassed = JText::_("GURU_QUIZ_PASSED_TEXT");
            $lang_quiz = JText::_("GURU_QUIZ_FAILED_TEXT");
            $next_button_text = JText::_("GURU_COURSE_CONTINUE_COURSE");
            $more_times = JText::_("GURU_MORE_TIMES");
        } else {
            $lang_quizpassed = JText::_("GURU_FEXAM_PASSED_TEXT");
            $lang_quiz = JText::_("GURU_FEXAM_FAILED_TEXT");
            $next_button_text = "";
            $more_times = JText::_("GURU_MOREFE_TIMES");
        }
        $passed_quiz = JText::_("GURU_QUIZ_PASSED");
        $percent = JText::_("GURU_PERCENT");
        $min_to_pass = JText::_("GURU_MIN_TO_PASS");
        $congrat = JText::_("GURU_CONGRAT");
        $failed = JText::_("GURU_QUIZ_FAILED");
        $take_again = JText::_("GURU_TAKE_AGAIN_QUIZ");
        $time_remain_task_quiz = JText::_("GURU_TIMES_REMAIN_TAKE_QUIZ");
        $yes = JText::_("GURU_YES");
        $unlimited = JText::_("GURU_UNLIMITED");
        $sql = "SELECT `time_quiz_taken_per_user`  FROM `#__guru_quiz_taken` WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($quiz_id) . " and pid=" . intval($course_id) . " ORDER BY id DESC LIMIT 0,1";
        $db->setQuery($sql);
        $time_quiz_taken_per_user = $db->loadColumn();
        $time_quiz_taken_per_user = $time_quiz_taken_per_user["0"];
        $chances_remained = intval($resultt - $time_quiz_taken_per_user);
        if (@$resultt >= 0) {
            if ($score >= @$quiz_details["0"]["max_score"]) {
                $quiz_form_header .= '<span class="guru_quiz_score">' . $your_score_text . ':' . $score . '<span style="color:#292522;">' . $passed_quiz . '</span></span>';
                $quiz_form_header .= '<div class ="guru-quiz-timer">';
                $quiz_form_header .= '<span>' . $lang_quizpassed . '<span style="color:#669900;">' . $score . " " . $percent . '</span>' . ',' . " " . $min_to_pass . " " . '<span style="color:#669900;">' . @$quiz_details["0"]["max_score"] . $percent . '</span></span>';
                $quiz_form_header .= '<br/><span>' . $congrat . '</span>';
                $quiz_form_header .= '<br/></br><span>' . $next_button_text . '</span>';
                $quiz_form_header .= '</div>';
            } else {
                $quiz_form_header .= '<span class="guru_quiz_score">' . $your_score_text . ':' . $score . $percent . '<span style="color:#292522;">' . $failed . '</span>';
                $quiz_form_header .= '<div class ="guru-quiz-timer">';
                $quiz_form_header .= '<span>' . $lang_quiz . '<span style="color:#669900;">' . $score . $percent . '</span>' . ',' . " " . " " . $min_to_pass . " " . '<span style="color:#669900;">' . @$quiz_details["0"]["max_score"] . $percent . '</span></span>';
                if ($time_quiz_taken < 11) {
                    $quiz_form_header .= '<br/><span>' . $time_remain_task_quiz . '<span style="color:#669900;">' . " " . $chances_remained . " " . '</span>' . $more_times . '</span>';
                } else {
                    $quiz_form_header .= '<br/><span>' . $time_remain_task_quiz . '<span style="color:#669900;">' . " " . $unlimited . " " . '</span>Unlimited</span>';
                }
                if ($time_quiz_taken > 1) {
                    $quiz_form_header .= '<br/></br><span>' . $take_again . '</span>';
                    $quiz_form_header .= '<br/><br/><input type="button" class="guru-yes-no-quiz-button"  onClick="window.location.reload()" name="yesbutton" value="' . $yes . '"/>' . '&nbsp;&nbsp;';
                }
                $quiz_form_header .= '</div>';
            }
        }
        return $quiz_result_content;
    }