if (empty($course_code)) { $course_code = 0; } $form->setDefaults(array('course_code' => (string) $course_code)); $course_info = api_get_course_info($course_code); if (!empty($course_info)) { $list = new LearnpathList('', $course_code); $lp_list = $list->get_flat_list(); $_course = $course_info; $main_question_list = array(); foreach ($lp_list as $lp_id => $lp) { $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']); foreach ($exercise_list as $exercise) { $my_exercise = new Exercise(); $my_exercise->read($exercise['path']); $question_list = $my_exercise->selectQuestionList(); $exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['real_id'], $session_id); foreach ($question_list as $question_id) { $question_data = Question::read($question_id); $main_question_list[$question_id] = $question_data; $quantity_exercises = 0; $question_result = 0; foreach ($exercise_stats as $stats) { if (!empty($stats['question_list'])) { foreach ($stats['question_list'] as $my_question_stat) { if ($question_id == $my_question_stat['question_id']) { $question_result = $question_result + $my_question_stat['marks']; $quantity_exercises++; } } }
/** * return the number of question of a category id in a test * @param int $exerciseId * @param int $categoryId * * @return integer * * @author hubert.borderiou 07-04-2011 */ public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId) { $nbCatResult = 0; $quiz = new Exercise(); $quiz->read($exerciseId); $tabQuestionList = $quiz->selectQuestionList(); // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ? for ($i = 1; $i <= count($tabQuestionList); $i++) { if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) { $nbCatResult++; } } return $nbCatResult; }
} if ($temp_CurrentDate < $temp_StartDate || $temp_CurrentDate >= $temp_EndDate) { $message = $langExerciseExpired; $error = TRUE; } if ($error == TRUE) { echo "<br/><td class='alert alert-warning'>{$message}</td>"; exit; } } if (isset($_SESSION['questionList'][$exerciseId])) { $questionList = $_SESSION['questionList'][$exerciseId]; } if (!isset($_SESSION['questionList'][$exerciseId])) { // selects the list of question ID $questionList = $randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList(); // saves the question list into the session $_SESSION['questionList'][$exerciseId] = $questionList; } $nbrQuestions = sizeof($questionList); // if questionNum comes from POST and not from GET if (!isset($questionNum) || $_POST['questionNum']) { // only used for sequential exercises (see $exerciseType) if (!isset($questionNum)) { $questionNum = 1; } else { $questionNum++; } } if (@$_POST['questionNum']) { $QUERY_STRING = "questionNum={$questionNum}";
/** * Exports an exercise as a SCO. * This method is intended to be called from the prepare method. * * @note There's a lot of nearly cut-and-paste from exercise.lib.php here * because of some little differences... * Perhaps something that could be refactorised ? * * @see prepare * @param $quizId The quiz * @param $raw_to_pass The needed score to attain * @return False on error, True if everything went well. * @author Thanos Kyritsis <*****@*****.**> * @author Amand Tihon <*****@*****.**> */ function prepareQuiz($quizId, $raw_to_pass = 50) { global $langQuestion, $langOk, $langScore, $claro_stylesheet, $clarolineRepositorySys; global $charset, $langExerciseDone; // those two variables are needed by display_attached_file() global $attachedFilePathWeb; global $attachedFilePathSys; $attachedFilePathWeb = 'Exercises'; $attachedFilePathSys = $this->destDir . '/Exercises'; // Generate standard page header $pageHeader = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=' . $charset . '"> <meta http-equiv="expires" content="Tue, 05 DEC 2000 07:00:00 GMT"> <meta http-equiv="Pragma" content="no-cache"> <link rel="stylesheet" type="text/css" href="bootstrap-custom.css" /> <link rel="stylesheet" type="text/css" href="' . $claro_stylesheet . '" media="screen, projection, tv" /> <script language="javascript" type="text/javascript" src="APIWrapper.js"></script> <script language="javascript" type="text/javascript" src="scores.js"></script> ' . "\n"; $pageBody = '<body onload="loadPage()"> <div id="claroBody"><form id="quiz"> <table class="table-default"><tr><td>' . "\n"; // read the exercise $quiz = new Exercise(); if (!$quiz->read($quizId)) { $this->error[] = $GLOBALS['langErrorLoadingExercise']; return false; } // Get the question list $questionList = $quiz->selectQuestionList(); $questionCount = $quiz->selectNbrQuestions(); // Keep track of raw scores (ponderation) for each question $questionPonderationList = array(); // Keep track of correct texts for fill-in type questions $fillAnswerList = array(); // Counter used to generate the elements' id. Incremented after every <input> or <select> $idCounter = 0; // Display each question $questionCount = 0; foreach ($questionList as $questionId) { // Update question number $questionCount++; // read the question, abort on error $question = new Question(); if (!$question->read($questionId)) { $this->error[] = $GLOBALS['langErrorLoadingQuestion']; return false; } $qtype = $question->selectType(); $qtitle = $question->selectTitle(); $qdescription = $question->selectDescription(); $questionPonderationList[$questionId] = $question->selectWeighting(); // Generic display, valid for all kind of question $pageBody .= '<table class="table-default"> <tr><th valign="top" colspan="2">' . $langQuestion . ' ' . $questionCount . '</th></tr> <tfoot> <tr><td valign="top" colspan="2">' . $qtitle . '</td></tr> <tr><td valign="top" colspan="2"><i>' . parse_user_text($qdescription) . '</i></td></tr>' . "\n"; // Attached file, if it exists. //$attachedFile = $question->selectAttachedFile(); if (!empty($attachedFile)) { // copy the attached file if (!claro_copy_file($this->srcDirExercise . '/' . $attachedFile, $this->destDir . '/Exercises')) { $this->error[] = $GLOBALS['langErrorCopyAttachedFile'] . $attachedFile; return false; } // Ok, if it was an mp3, we need to copy the flash mp3-player too. $extension = substr(strrchr($attachedFile, '.'), 1); if ($extension == 'mp3') { $this->mp3Found = true; } $pageBody .= '<tr><td colspan="2">' . display_attached_file($attachedFile) . '</td></tr>' . "\n"; } /* * Display the possible answers */ $answer = new Answer($questionId); $answerCount = $answer->selectNbrAnswers(); // Used for matching: $letterCounter = 'A'; $choiceCounter = 1; $Select = array(); for ($answerId = 1; $answerId <= $answerCount; $answerId++) { $answerText = $answer->selectAnswer($answerId); $answerCorrect = $answer->isCorrect($answerId); // Unique answer if ($qtype == UNIQUE_ANSWER || $qtype == TRUE_FALSE) { // Construct the identifier $htmlQuestionId = 'unique_' . $questionCount . '_x'; $pageBody .= '<tr><td width="5%" align="center"> <input type="radio" name="' . $htmlQuestionId . '" id="scorm_' . $idCounter . '" value="' . $answer->selectWeighting($answerId) . '"></td> <td width="95%"><label for="scorm_' . $idCounter . '">' . $answerText . '</label> </td></tr>'; $idCounter++; } // Multiple answers elseif ($qtype == MULTIPLE_ANSWER) { // Construct the identifier $htmlQuestionId = 'multiple_' . $questionCount . '_' . $answerId; // Compute the score modifier if this answer is checked $raw = $answer->selectWeighting($answerId); $pageBody .= '<tr><td width="5%" align="center"> <input type="checkbox" name="' . $htmlQuestionId . '" id="scorm_' . $idCounter . '" value="' . $raw . '"></td> <td width="95%"><label for="scorm_' . $idCounter . '">' . $answerText . '</label> </td></tr>'; $idCounter++; } // Fill in blanks elseif ($qtype == FILL_IN_BLANKS || $qtype == FILL_IN_BLANKS_TOLERANT) { $pageBody .= '<tr><td colspan="2">'; // We must split the text, to be able to treat each input independently // separate the text and the scorings $explodedAnswer = explode('::', $answerText); $phrase = (isset($explodedAnswer[0])) ? $explodedAnswer[0] : ''; $weighting = (isset($explodedAnswer[1])) ? $explodedAnswer[1] : ''; $fillType = (!empty($explodedAnswer[2])) ? $explodedAnswer[2] : 1; // default value if value is invalid if ($fillType != TEXTFIELD_FILL && $fillType != LISTBOX_FILL) { $fillType = TEXTFIELD_FILL; } $wrongAnswers = (!empty($explodedAnswer[3])) ? explode('[', $explodedAnswer[3]) : array(); // get the scorings as a list $fillScoreList = explode(',', $weighting); $fillScoreCounter = 0; //listbox if ($fillType == LISTBOX_FILL) { // get the list of propositions (good and wrong) to display in lists // add wrongAnswers in the list $answerList = $wrongAnswers; // add good answers in the list // we save the answer because it will be modified $temp = $phrase; while (1) { // quits the loop if there are no more blanks if (($pos = strpos($temp, '[')) === false) { break; } // removes characters till '[' $temp = substr($temp, $pos + 1); // quits the loop if there are no more blanks if (($pos = strpos($temp, ']')) === false) { break; } // stores the found blank into the array $answerList[] = substr($temp, 0, $pos); // removes the character ']' $temp = substr($temp, $pos + 1); } // alphabetical sort of the array natcasesort($answerList); } // Split after each blank $responsePart = explode(']', $phrase); $acount = 0; foreach ($responsePart as $part) { // Split between text and (possible) blank if (strpos($part, '[') !== false) { list($rawtext, $blankText) = explode('[', $part); } else { $rawtext = $part; $blankText = ""; } $pageBody .= $rawtext; // If there's a blank to fill-in after the text (this is usually not the case at the end) if (!empty($blankText)) { // Build the element's name $name = 'fill_' . $questionCount . '_' . $acount; // Keep track of the correspondance between element's name and correct value + scoring $fillAnswerList[$name] = array($blankText, $fillScoreList[$fillScoreCounter]); if ($fillType == LISTBOX_FILL) {// listbox $pageBody .= '<select name="' . $name . '" id="scorm_' . $idCounter . '">' . "\n" . '<option value=""> </option>'; foreach ($answerList as $answer) { $pageBody .= '<option value="' . htmlspecialchars($answer) . '">' . $answer . '</option>' . "\n"; } $pageBody .= '</select>' . "\n"; } else { $pageBody .= '<input type="text" name="' . $name . '" size="10" id="scorm_' . $idCounter . '">'; } $fillScoreCounter++; $idCounter++; } $acount++; } $pageBody .= '</td></tr>' . "\n"; } // Matching elseif ($qtype == MATCHING) { if (!$answer->isCorrect($answerId)) { // Add the option as a possible answer. $Select[$answerId] = $answerText; } else { $pageBody .= '<tr><td colspan="2"> <table border="0" cellpadding="0" cellspacing="0" width="99%"> <tr> <td width="40%" valign="top"><b>' . $choiceCounter . '.</b> ' . $answerText . '</td> <td width="20%" valign="center"> <select name="matching_' . $questionCount . '_' . $answerId . '" id="scorm_' . $idCounter . '"> <option value="0">--</option>'; $idCounter++; // fills the list-box $letter = 'A'; foreach ($Select as $key => $val) { $scoreModifier = ( $key == $answer->isCorrect($answerId) ) ? $answer->selectWeighting($answerId) : 0; $pageBody .= '<option value="' . $scoreModifier . '">' . $letter++ . '</option>'; } $pageBody .= '</select></td><td width="40%" valign="top">'; if (isset($Select[$choiceCounter])) { $pageBody .= '<b>' . $letterCounter . '.</b> ' . $Select[$choiceCounter]; } $pageBody .= ' </td></tr></table></td></tr>' . "\n"; // Done with this one $letterCounter++; $choiceCounter++; // If the left side has been completely displayed : if ($answerId == $answerCount) { // Add all possibly remaining answers to the right while (isset($Select[$choiceCounter])) { $pageBody .= '<tr><td colspan="2"> <table border="0" cellpadding="0" cellspacing="0" width="99%"> <tr> <td width="40%"> </td> <td width="20%"> </td> <td width="40%"><b>' . $letterCounter . '.</b> ' . $Select[$choiceCounter] . '</td> </tr> </table> </td></tr>' . "\n"; $letterCounter++; $choiceCounter++; } // end while } // end if } // else } // end if (MATCHING) } // end for each answer // End of the question $pageBody .= '</tfoot></table>' . "\n\n"; } // foreach($questionList as $questionId) // No more questions, add the button. $pageEnd = '</td></tr> <tr> <td align="center"><br><input class="btn btn-primary" type="button" value="' . $langOk . '" onClick="calcScore()"></td> </tr> </table> </form> </div></body></html>' . "\n"; /* Generate the javascript that'll calculate the score * We have the following variables to help us : * $idCounter : number of elements to check. their id are "scorm_XY" * $raw_to_pass : score (on 100) needed to pass the quiz * $fillAnswerList : a list of arrays (text, score) indexed on <input>'s names * */ $pageHeader .= ' <script type="text/javascript" language="javascript"> var raw_to_pass = '******'; var weighting = ' . array_sum($questionPonderationList) . '; var rawScore; var scoreCommited = false; var showScore = true; var fillAnswerList = new Array();' . "\n"; // Add the data for fillAnswerList foreach ($fillAnswerList as $key => $val) { $pageHeader .= " fillAnswerList['" . $key . "'] = new Array('" . $val[0] . "', '" . $val[1] . "');\n"; } // This is the actual code present in every exported exercise. $pageHeader .= ' function calcScore() { if( !scoreCommited ) { rawScore = CalculateRawScore(document, ' . $idCounter . ', fillAnswerList); var score = Math.max(Math.round(rawScore * 100 / weighting), 0); var oldScore = doGetValue("cmi.score.raw"); doSetValue("cmi.score.max", weighting); doSetValue("cmi.score.min", 0); computeTime(); if (score > oldScore) // Update only if score is better than the previous time. { doSetValue("cmi.score.raw", rawScore); } var oldStatus = doGetValue( "cmi.success_status" ) if (score >= raw_to_pass) { doSetValue("cmi.success_status", "passed"); } else if (oldStatus != "passed" ) // If passed once, never mark it as failed. { doSetValue("cmi.success_status", "failed"); } doCommit(); doTerminate(); scoreCommited = true; if(showScore) alert(\'' . clean_str_for_javascript($langScore) . ' :\n\' + rawScore + \'/\' + weighting + \'\n\' + \'' . clean_str_for_javascript($langExerciseDone) . '\'); } } </script> '; // Construct the HTML file and save it. $filename = "quiz_" . $quizId . ".html"; $pageContent = $pageHeader . $pageBody . $pageEnd; if (!$f = fopen($this->destDir . '/' . $filename, 'w')) { $this->error[] = $GLOBALS['langErrorCreatingFile'] . $filename; return false; } fwrite($f, $pageContent); fclose($f); // Went well. return True; }
include 'question.class.php'; $exerciseId = $_GET['exerciseId']; $objExercise = new Exercise(); $objExercise->read($exerciseId); $pageName = $langExerciseStats; $navigation[] = array("url" => "index.php?course={$course_code}", "name" => $langExercices); $tool_content .= action_bar(array(array('title' => $langBack, 'level' => 'primary-label', 'icon' => 'fa-reply', 'url' => "index.php?course={$course_code}"))); $completedAttempts = Database::get()->querySingle("SELECT count(*) AS count FROM exercise_user_record WHERE eid = ?d AND attempt_status = ?d", $exerciseId, ATTEMPT_COMPLETED)->count; $pausedAttempts = Database::get()->querySingle("SELECT count(*) AS count FROM exercise_user_record WHERE eid = ?d AND attempt_status = ?d", $exerciseId, ATTEMPT_PAUSED)->count; $pendingAttempts = Database::get()->querySingle("SELECT count(*) AS count FROM exercise_user_record WHERE eid = ?d AND attempt_status = ?d", $exerciseId, ATTEMPT_PENDING)->count; $cancelledAttempts = Database::get()->querySingle("SELECT count(*) AS count FROM exercise_user_record WHERE eid = ?d AND attempt_status = ?d", $exerciseId, ATTEMPT_CANCELED)->count; $total_attempts = $completedAttempts + $pausedAttempts + $pendingAttempts + $cancelledAttempts; $grade_stats = Database::get()->querySingle("SELECT COUNT(DISTINCT uid) AS unique_users, AVG(TIME_TO_SEC(TIMEDIFF(record_end_date, record_start_date))) AS avg_time, AVG(total_score) AS avg_grade, MIN(total_score) AS min_grade, MAX(total_score) AS max_grade FROM exercise_user_record WHERE eid = ?d AND attempt_status = ?d", $exerciseId, ATTEMPT_COMPLETED); $max_grade = $grade_stats->max_grade; $min_grade = $grade_stats->min_grade; $avg_grade = $grade_stats->avg_grade; $avg_time = $grade_stats->avg_time; $unique_users = $grade_stats->unique_users; //average number of attempts //avg completion time $tool_content .= "\n <div class='table-responsive'>\n <table class='table-default'>\n <thead>\n <tr>\n <th colspan='4' class='text-center'>{$langAttempts}</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>{$langAttemptsCompleted}</th>\n <td>{$completedAttempts}</td>\n <td>{$langAttemptsPaused}</th>\n <td>{$pausedAttempts}</td> \n </tr>\n <tr>\n <td>{$langAttemptPending}</th>\n <td>{$pendingAttempts}</td>\n <td>{$langAttemptsCanceled}</th>\n <td>{$cancelledAttempts}</td> \n </tr>\n </tbody>\n <tfoot>\n <tr class='active'>\n <th colspan='3'>{$langTotal}:</th>\n <th colspan='1'>{$total_attempts}</th>\n </tr> \n </tfoot>\n </table>\n </div>\n <div class='table-responsive'>\n <table class='table-default'>\n <thead>\n <tr>\n <th colspan='2' class='text-center'>{$langScore}</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>{$langHighestGrade}</th>\n <td>{$max_grade}</td>\n \n </tr>\n <tr>\n <td>{$langLowestGrade}</th>\n <td>{$min_grade}</td> \n </tr>\n <tr>\n <td>{$langRatingAverage}</th>\n <td>{$avg_grade}</td> \n </tr> \n </tbody>\n </table>\n </div>\n <div class='table-responsive'>\n <table class='table-default'>\n <thead>\n <tr>\n <th colspan='2' class='text-center'>{$langStudents}</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>{$langStudentsExerciseCompleted}</th>\n <td>{$unique_users}</td> \n </tr> \n <tr>\n <td>{$langAverage} {$langExerciseDuration}</th>\n <td>" . format_time_duration($avg_time) . "</td> \n </tr> \n </tbody>\n </table>\n </div>"; //Questions Table $questionList = $objExercise->selectQuestionList(); $tool_content .= "\n <h3>{$langQuestions}</h3>\n <div class='table-responsive'>\n <table class='table-default'>\n <thead>\n <tr>\n <th>{$langTitle}</th>\n <th>Ποσοστό Επιτυχίας</th>\n </tr>\n </thead>\n <tbody>"; foreach ($questionList as $id) { $objQuestionTmp = new Question(); $objQuestionTmp->read($id); $tool_content .= "\n <tr>\n <td>" . $objQuestionTmp->selectTitle() . "</th>\n <td>\n <div class='progress'>\n <div class='progress-bar progress-bar-success progress-bar-striped' role='progressbar' aria-valuenow='" . $objQuestionTmp->successRate($exerciseId) . "' aria-valuemin='0' aria-valuemax='100' style='width: " . $objQuestionTmp->successRate($exerciseId) . "%;'>\n " . $objQuestionTmp->successRate($exerciseId) . "%\n </div>\n </div></td> \n </tr>"; } $tool_content .= "\n </tbody>\n </table>\n </div>"; draw($tool_content, 2, null, $head_content);