From 33cd962f077ed8c2e4b696bdd18b54db00890ef2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 1 May 2013 10:42:43 +0200 Subject: [PATCH] Moving exercise.lib.php to the inc/lib/ folder in order to lazy load the class --- main/admin/career_dashboard.php | 1 - main/auth/my_progress.php | 1 - main/exercice/admin.php | 1 - main/exercice/adminhp.php | 1 - main/exercice/exercice.php | 5 +- main/exercice/exercise.class.php | 2 +- main/exercice/exercise.lib.php | 2532 ---------------- main/exercice/exercise_admin.php | 1 - main/exercice/exercise_reminder.php | 3 +- main/exercice/exercise_report.php | 3 +- main/exercice/exercise_result.php | 11 +- main/exercice/exercise_show.php | 7 +- main/exercice/exercise_submit.php | 16 +- main/exercice/exercise_submit_modal.php | 1 - main/exercice/feedback.php | 2 - main/exercice/hotpotatoes_exercise_report.php | 3 +- main/exercice/live_stats.php | 25 +- main/exercice/overview.php | 5 +- main/exercice/question_list_admin.inc.php | 2 +- main/exercice/question_pool.php | 5 +- main/exercice/result.php | 8 +- main/exercice/stats.php | 13 +- main/exercice/testcategory.class.php | 12 +- main/exercice/tests_category.php | 1 - main/inc/ajax/exercise.ajax.php | 3 +- main/inc/ajax/model.ajax.php | 10 +- main/inc/lib/events.lib.inc.php | 15 +- main/inc/lib/exercise.lib.php | 2535 +++++++++++++++++ main/inc/lib/page.lib.php | 3 +- main/inc/lib/tracking.lib.php | 40 +- main/newscorm/learnpath_functions.inc.php | 5 +- main/newscorm/lp_stats.php | 12 +- main/session/index.php | 13 +- main/tracking/courseLog.php | 1 - main/tracking/course_log_resources.php | 1 - main/tracking/course_log_tools.php | 1 - main/tracking/course_session_report.php | 2 +- main/tracking/lp_results_by_user.php | 2 +- main/tracking/question_course_report.php | 2 +- tests/datafiller/fill_exe.php | 5 +- tests/test_manager.inc.php | 1 - vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_real.php | 6 +- 44 files changed, 2644 insertions(+), 2677 deletions(-) delete mode 100644 main/exercice/exercise.lib.php create mode 100644 main/inc/lib/exercise.lib.php diff --git a/main/admin/career_dashboard.php b/main/admin/career_dashboard.php index eeb44f1bb3..9c1a7765b4 100644 --- a/main/admin/career_dashboard.php +++ b/main/admin/career_dashboard.php @@ -14,7 +14,6 @@ $cidReset = true; require_once '../inc/global.inc.php'; $libpath = api_get_path(LIBRARY_PATH); -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php'; api_protect_admin_script(); diff --git a/main/auth/my_progress.php b/main/auth/my_progress.php index 7aedbe016e..ab423ad0f7 100644 --- a/main/auth/my_progress.php +++ b/main/auth/my_progress.php @@ -12,7 +12,6 @@ $language_file = array('registration', 'tracking', 'exercice', 'admin', 'learnpa $cidReset = true; require_once '../inc/global.inc.php'; -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; $this_section = SECTION_TRACKING; diff --git a/main/exercice/admin.php b/main/exercice/admin.php index 599062e498..db01c27610 100644 --- a/main/exercice/admin.php +++ b/main/exercice/admin.php @@ -58,7 +58,6 @@ require_once 'answer.class.php'; $language_file = 'exercice'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; $current_course_tool = TOOL_QUIZ; $this_section = SECTION_COURSES; diff --git a/main/exercice/adminhp.php b/main/exercice/adminhp.php index c8652ed519..14204ba43a 100644 --- a/main/exercice/adminhp.php +++ b/main/exercice/adminhp.php @@ -16,7 +16,6 @@ require_once 'answer.class.php'; $language_file='exercice'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; $this_section=SECTION_COURSES; diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index ff0db9a48f..cd2e3e69ff 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -35,7 +35,6 @@ api_protect_course_script(true); // including additional libraries require_once 'exercise.class.php'; -require_once 'exercise.lib.php'; require_once 'question.class.php'; require_once 'answer.class.php'; require_once 'hotpotatoes.lib.php'; @@ -811,7 +810,7 @@ if (!empty($exercise_list)) { if ($num > 0) { $row_track = Database :: fetch_array($qryres); $attempt_text = get_lang('LatestAttempt').' : '; - $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']); + $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']); } else { //No attempts $attempt_text = get_lang('NotAttempted'); @@ -852,7 +851,7 @@ if (!empty($exercise_list)) { if ($num > 0) { $row_track = Database :: fetch_array($qryres); $attempt_text = get_lang('LatestAttempt').' : '; - $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']); + $attempt_text .= ExerciseLib::show_score($row_track['exe_result'], $row_track['exe_weighting']); } else { $attempt_text = get_lang('NotAttempted'); } diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index dfb823f8b2..8cbd5659ac 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -4431,7 +4431,7 @@ class Exercise public function get_exercise_result($exe_id) { $result = array(); - $track_exercise_info = get_exercise_track_exercise_info($exe_id); + $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($exe_id); if (!empty($track_exercise_info)) { $objExercise = new Exercise(); $objExercise->read($track_exercise_info['exe_exo_id']); diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php deleted file mode 100644 index cc2fdd9364..0000000000 --- a/main/exercice/exercise.lib.php +++ /dev/null @@ -1,2532 +0,0 @@ - - * @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $ - * Modified by Hubert Borderiou 2011-10-21 Question Category - */ -/** - * Code - */ - -/** - * Shows a question - * - * @param int question id - * @param bool if true only show the questions, no exercise title - * @param bool origin i.e = learnpath - * @param int current item from the list of questions - * @param int number of total questions - * */ -function showQuestion($objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false) { - // Text direction for the current language - //$is_ltr_text_direction = api_get_text_direction() != 'rtl'; - // Change false to true in the following line to enable answer hinting - $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false; - // Reads question information - if (!$objQuestionTmp) { - // Question not found - return false; - } - - $questionId = $objQuestionTmp->id; - - if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) { - $show_comment = false; - } - - $answerType = $objQuestionTmp->selectType(); - $pictureName = $objQuestionTmp->selectPicture(); - - $s = null; - - if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) { - // Question is not a hotspot - - if (!$only_questions) { - $questionDescription = $objQuestionTmp->selectDescription(); - if ($show_title) { - echo Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id); - echo Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class' => 'question_title')); - } - if (!empty($questionDescription)) { - echo Display::div($questionDescription, array('class' => 'question_description')); - } - } - - if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) { - return ''; - } - - echo '
'; - // construction of the Answer object (also gets all answers details) - $objAnswerTmp = new Answer($questionId); - - $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); - $course_id = api_get_course_int_id(); - $quiz_question_options = Question::readQuestionOption($questionId, $course_id); - - // For "matching" type here, we need something a little bit special - // because the match between the suggestions and the answers cannot be - // done easily (suggestions and answers are in the same table), so we - // have to go through answers first (elems with "correct" value to 0). - $select_items = array(); - //This will contain the number of answers on the left side. We call them - // suggestions here, for the sake of comprehensions, while the ones - // on the right side are called answers - $num_suggestions = 0; - - if ($answerType == MATCHING || $answerType == DRAGGABLE) { - if ($answerType == DRAGGABLE) { - $s .= '
-
    '; - } else { - $s .= '
    '; - $s .= ''; - } - - $j = 1; //iterate through answers - $letter = 'A'; //mark letters for each answer - $answer_matching = array(); - $capital_letter = array(); - //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) { - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $answer = $objAnswerTmp->selectAnswer($answerId); - if ($answerCorrect == 0) { - // options (A, B, C, ...) that will be put into the list-box - // have the "correct" field set to 0 because they are answer - $capital_letter[$j] = $letter; - //$answer_matching[$j]=$objAnswerTmp->selectAnswerByAutoId($numAnswer); - $answer_matching[$j] = array('id' => $answerId, 'answer' => $answer); - $j++; - $letter++; - } - } - - $i = 1; - - $select_items[0]['id'] = 0; - $select_items[0]['letter'] = '--'; - $select_items[0]['answer'] = ''; - - foreach ($answer_matching as $id => $value) { - $select_items[$i]['id'] = $value['id']; - $select_items[$i]['letter'] = $capital_letter[$id]; - $select_items[$i]['answer'] = $value['answer']; - $i++; - } - $num_suggestions = ($nbrAnswers - $j) + 1; - } elseif ($answerType == FREE_ANSWER) { - $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; - - $oFCKeditor = new FCKeditor("choice[".$questionId."]"); - - $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Height = '200'; - $oFCKeditor->Value = $fck_content; - $s .= $oFCKeditor->CreateHtml(); - } elseif ($answerType == ORAL_EXPRESSION) { - //Add nanog - if (api_get_setting('enable_nanogong') == 'true') { - - //@todo pass this as a parameter - global $exercise_stat_info, $exerciseId; - - if (!empty($exercise_stat_info)) { - $params = array( - 'exercise_id' => $exercise_stat_info['exe_exo_id'], - 'exe_id' => $exercise_stat_info['exe_id'], - 'question_id' => $questionId - ); - } else { - $params = array( - 'exercise_id' => $exerciseId, - 'exe_id' => 'temp_exe', - 'question_id' => $questionId - ); - } - - $nano = new Nanogong($params); - echo $nano->show_button(); - } - - $oFCKeditor = new FCKeditor("choice[".$questionId."]"); - $oFCKeditor->ToolbarSet = 'TestFreeAnswer'; - $oFCKeditor->Width = '100%'; - $oFCKeditor->Height = '150'; - $oFCKeditor->ToolbarStartExpanded = false; - $oFCKeditor->Value = ''; - $s .= $oFCKeditor->CreateHtml(); - } - - // Now navigate through the possible answers, using the max number of - // answers for the question as a limiter - $lines_count = 1; // a counter for matching-type answers - - if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $header = Display::tag('th', get_lang('Options')); - foreach ($objQuestionTmp->options as $key => $item) { - $header .= Display::tag('th', $item); - } - if ($show_comment) { - $header .= Display::tag('th', get_lang('Feedback')); - } - $s .= '
    '; - $s.= Display::tag('tr', $header, array('style' => 'text-align:left;')); - } - - if ($show_comment) { - if (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, GLOBAL_MULTIPLE_ANSWER))) { - $header = Display::tag('th', get_lang('Options')); - if ($exercise_feedback == EXERCISE_FEEDBACK_TYPE_END) { - $header .= Display::tag('th', get_lang('Feedback')); - } - $s .= '
    '; - $s.= Display::tag('tr', $header, array('style' => 'text-align:left;')); - } - } - - $matching_correct_answer = 0; - $user_choice_array = array(); - if (!empty($user_choice)) { - foreach ($user_choice as $item) { - $user_choice_array[] = $item['answer']; - } - } - - //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) { - - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - $answer = $objAnswerTmp->selectAnswer($answerId); - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $comment = $objAnswerTmp->selectComment($answerId); - - //$numAnswer = $objAnswerTmp->selectAutoId($answerId); - $numAnswer = $answerId; - - $attributes = array(); - // Unique answer - if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) { - $input_id = 'choice-'.$questionId.'-'.$answerId; - if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - $answer = Security::remove_XSS($answer, STUDENT); - - $s .= Display::input('hidden', 'choice2['.$questionId.']', '0'); - - $answer_input = null; - if ($answerType == UNIQUE_ANSWER_IMAGE) { - $attributes['style'] = 'display:none'; - $answer_input .= '
    '; - } - - $answer_input .= ''; - - if ($answerType == UNIQUE_ANSWER_IMAGE) { - $answer_input .= "
    "; - } - - if ($show_comment) { - $s .= ''; - $s .= ''; - $s .= ''; - } else { - $s .= $answer_input; - } - } elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) { - $input_id = 'choice-'.$questionId.'-'.$answerId; - $answer = Security::remove_XSS($answer, STUDENT); - - if (in_array($numAnswer, $user_choice_array)) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { - $s .= ''; - - $answer_input = ''; - - if ($show_comment) { - $s .= ''; - $s .= ''; - $s .=''; - } else { - $s .= $answer_input; - } - } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { - - $my_choice = array(); - if (!empty($user_choice_array)) { - foreach ($user_choice_array as $item) { - $item = explode(':', $item); - $my_choice[$item[0]] = $item[1]; - } - } - - $s .=''; - $s .= Display::tag('td', $answer); - - if (!empty($quiz_question_options)) { - foreach ($quiz_question_options as $id => $item) { - $id = $item['iid']; - if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) { - $attributes = array('checked' => 1, 'selected' => 1); - } else { - $attributes = array(); - } - - if ($debug_mark_answer) { - if ($id == $answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $id, $attributes), array('style' => '')); - } - } - - if ($show_comment) { - $s .= ''; - } - $s.=''; - } - } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { - - // multiple answers - $input_id = 'choice-'.$questionId.'-'.$answerId; - - if (in_array($numAnswer, $user_choice_array)) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - $answer = Security::remove_XSS($answer, STUDENT); - $answer_input = ''; - $answer_input .= ''; - - if ($show_comment) { - $s.= ''; - $s .= ''; - $s .= ''; - $s.= ''; - } else { - $s.= $answer_input; - } - } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $s .= ''; - - $my_choice = array(); - if (!empty($user_choice_array)) { - foreach ($user_choice_array as $item) { - $item = explode(':', $item); - $my_choice[$item[0]] = $item[1]; - } - } - $answer = Security::remove_XSS($answer, STUDENT); - $s .=''; - $s .= Display::tag('td', $answer); - - foreach ($objQuestionTmp->options as $key => $item) { - if (isset($my_choice[$numAnswer]) && $key == $my_choice[$numAnswer]) { - $attributes = array('checked' => 1, 'selected' => 1); - } else { - $attributes = array(); - } - - if ($debug_mark_answer) { - if ($key == $answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $key, $attributes)); - } - - if ($show_comment) { - $s .= ''; - } - $s.=''; - } elseif ($answerType == FILL_IN_BLANKS) { - list($answer) = explode('::', $answer); - - //Correct answer - api_preg_match_all('/\[[^]]+\]/', $answer, $correct_answer_list); - - //Student's answezr - if (isset($user_choice[0]['answer'])) { - api_preg_match_all('/\[[^]]+\]/', $user_choice[0]['answer'], $student_answer_list); - $student_answer_list = $student_answer_list[0]; - } - - //If debug - if ($debug_mark_answer) { - $student_answer_list = $correct_answer_list[0]; - } - - if (!empty($correct_answer_list) && !empty($student_answer_list)) { - $correct_answer_list = $correct_answer_list[0]; - $i = 0; - foreach ($correct_answer_list as $correct_item) { - $value = null; - if (isset($student_answer_list[$i]) && !empty($student_answer_list[$i])) { - - //Cleaning student answer list - $value = strip_tags($student_answer_list[$i]); - $value = api_substr($value, 1, api_strlen($value) - 2); - $value = explode('/', $value); - - if (!empty($value[0])) { - $value = str_replace(' ', '', trim($value[0])); - } - $correct_item = preg_quote($correct_item); - $correct_item = api_preg_replace('|/|', '\/', $correct_item); // to prevent error if there is a / in the text to find - $answer = api_preg_replace('/'.$correct_item.'/', Display::input('text', "choice[$questionId][]", $value), $answer, 1); - } - $i++; - } - } else { - $answer = api_preg_replace('/\[[^]]+\]/', Display::input('text', "choice[$questionId][]", '', $attributes), $answer); - } - $s .= $answer; - } elseif ($answerType == MATCHING) { - // matching type, showing suggestions and answers - // TODO: replace $answerId by $numAnswer - - if ($lines_count == 1) { - echo $objAnswerTmp->getJs(); - } - if ($answerCorrect != 0) { - // only show elements to be answered (not the contents of - // the select boxes, who are correct = 0) - $s .= ''; - - // middle part (matches selects) - - $s .= ''; - - $s.=''; - $s .= ''; - $lines_count++; - //if the left side of the "matching" has been completely - // shown but the right side still has values to show... - if (($lines_count - 1) == $num_suggestions) { - // if it remains answers to shown at the right side - while (isset($select_items[$lines_count])) { - $s .= ' - - - "; - $lines_count++; - } // end while() - } // end if() - $matching_correct_answer++; - } - } elseif ($answerType == DRAGGABLE) { - // matching type, showing suggestions and answers - // TODO: replace $answerId by $numAnswer - - if ($answerCorrect != 0) { - // only show elements to be answered (not the contents of - // the select boxes, who are correct = 0) - $s .= '
    '; - $s .= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $comment; - $s .= '
    '; - $s.= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $comment; - $s .= '
    '; - $parsed_answer = $answer; - $windowId = $questionId.'_'.$lines_count; - //left part questions - $s .= '
    - '.$lines_count.'. '.$parsed_answer.' -
    -
      '; - $s .= '
    '; - - $s .= '
    '; - - if (isset($select_items[$lines_count])) { - $s.= '
    - '.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].' -
    '; - } else { - $s.=' '; - } - - $s .= '
    '; - $s.=''.$select_items[$lines_count]['letter'].'.'; - $s .= $select_items[$lines_count]['answer']; - $s.="
    '; - $parsed_answer = $answer; - $windowId = $questionId.'_'.$numAnswer; //67_293 - 67_294 - - //left part questions - $s .= '
  • '; - $s .= '
    - '.$parsed_answer.' -
    '; - - $s .= '
    '; - $s .= ''; - - if (!empty($answerCorrect) && !empty($selectedValue)) { - $s.= ''; - } - - - if (isset($select_items[$lines_count])) { - $s.= '
    - '.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].' -
    '; - } else { - $s.=' '; - } - $lines_count++; - //if the left side of the "matching" has been completely - // shown but the right side still has values to show... - - if (($lines_count - 1) == $num_suggestions) { - // if it remains answers to shown at the right side - while (isset($select_items[$lines_count])) { - $s.=''.$select_items[$lines_count]['letter'].'.'; - $s .= $select_items[$lines_count]['answer']; - $lines_count++; - } - } - $s .= '
    '; - $matching_correct_answer++; - $s .= '
  • '; - } - } - } // end for() - - if ($show_comment) { - $s .= '
    '; - } else { - if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || - $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $s .= ''; - } - } - - if ($answerType == DRAGGABLE) { - $s .= '
'; - - $counterAnswer = 1; - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - //for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $windowId = $questionId.'_'.$counterAnswer; - if ($answerCorrect == 0) { - $s .= '
'.$counterAnswer.'
'; - $counterAnswer++; - } - } - } - - if ($answerType == MATCHING) { - $s .= '
'; - } - - $s .= '
'; - - // destruction of the Answer object - unset($objAnswerTmp); - - // destruction of the Question object - unset($objQuestionTmp); - - if ($origin != 'export') { - echo $s; - } else { - return $s; - } - } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { - // Question is a HOT_SPOT - //checking document/images visibility - if (api_is_platform_admin() || api_is_course_admin()) { - $course = api_get_course_info(); - $doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName); - if (is_numeric($doc_id)) { - $images_folder_visibility = api_get_item_visibility($course, 'document', $doc_id, api_get_session_id()); - if (!$images_folder_visibility) { - //This message is shown only to the course/platform admin if the image is set to visibility = false - Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage')); - } - } - } - $questionName = $objQuestionTmp->selectTitle(); - $questionDescription = $objQuestionTmp->selectDescription(); - - if ($freeze) { - echo Display::img($objQuestionTmp->selectPicturePath()); - return; - } - - // Get the answers, make a list - $objAnswerTmp = new Answer($questionId); - $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); - - // get answers of hotpost - $answers_hotspot = array(); - //for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - //$answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId)); - $answers_hotspot[$answerId] = $objAnswerTmp->selectAnswer($answerId); - } - - // display answers of hotpost order by id - $answer_list = '
'.get_lang('HotspotZones').'
'; - if (!empty($answers_hotspot)) { - ksort($answers_hotspot); - foreach ($answers_hotspot as $key => $value) { - $answer_list .= '
'.$key.'.- '.$value.'

'; - } - } - $answer_list .= '
'; - - if ($answerType == HOT_SPOT_DELINEATION) { - $answer_list = ''; - $swf_file = 'hotspot_delineation_user'; - $swf_height = 405; - } else { - $swf_file = 'hotspot_user'; - $swf_height = 436; - } - - if (!$only_questions) { - if ($show_title) { - echo Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id); - echo '
'.$current_item.'. '.$questionName.'
'; - } - //@todo I need to the get the feedback type - echo ''; - echo ' - - '; - } - $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); - - $s .= ' - - - - - '; - $s .= ''; - echo $s; - echo '
'; - echo $questionDescription; - echo '
- -
- - '.$answer_list.'
-
'; - } - return $nbrAnswers; -} - -/** - * @param int $exe_id - * @return array - */ -function get_exercise_track_exercise_info($exe_id) -{ - $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); - $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $TBL_COURSE = Database::get_main_table(TABLE_MAIN_COURSE); - $exe_id = intval($exe_id); - $result_array = array(); - if (!empty($exe_id)) { - $sql = "SELECT q.*, tee.* - FROM $TBL_EXERCICES as q - INNER JOIN $TBL_TRACK_EXERCICES as tee - ON q.iid = tee.exe_exo_id - INNER JOIN $TBL_COURSE c - ON c.id = tee.c_id - WHERE tee.exe_id = $exe_id - AND q.c_id = c.id"; - - $result = Database::query($sql); - $result_array = Database::fetch_array($result, 'ASSOC'); - } - return $result_array; -} - -/** - * Validates the time control key - */ -function exercise_time_control_is_valid($exercise_id, $lp_id = 0, $lp_item_id = 0) -{ - $course_id = api_get_course_int_id(); - $exercise_id = intval($exercise_id); - $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); - $sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $exercise_id"; - $result = Database::query($sql); - $row = Database::fetch_array($result, 'ASSOC'); - if (!empty($row['expired_time'])) { - $current_expired_time_key = get_time_control_key($exercise_id, $lp_id, $lp_item_id); - if (isset($_SESSION['expired_time'][$current_expired_time_key])) { - $current_time = time(); - $expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC'); - $total_time_allowed = $expired_time + 30; - //error_log('expired time converted + 30: '.$total_time_allowed); - //error_log('$current_time: '.$current_time); - if ($total_time_allowed < $current_time) { - return false; - } - return true; - } else { - return false; - } - } else { - return true; - } -} - -/** - Deletes the time control token - */ -function exercise_time_control_delete($exercise_id, $lp_id = 0, $lp_item_id = 0) -{ - $current_expired_time_key = get_time_control_key($exercise_id, $lp_id, $lp_item_id); - unset($_SESSION['expired_time'][$current_expired_time_key]); -} - -/** - Generates the time control key - */ -function get_time_control_key($exercise_id, $lp_id = 0, $lp_item_id = 0) -{ - $exercise_id = intval($exercise_id); - $lp_id = intval($lp_id); - $lp_item_id = intval($lp_item_id); - return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id().'_'.$lp_id.'_'.$lp_item_id; -} - -/** - * Get session time control - */ -function get_session_time_control_key($exercise_id, $lp_id = 0, $lp_item_id = 0) -{ - $return_value = 0; - $time_control_key = get_time_control_key($exercise_id, $lp_id, $lp_item_id); - if (isset($_SESSION['expired_time']) && isset($_SESSION['expired_time'][$time_control_key])) { - $return_value = $_SESSION['expired_time'][$time_control_key]; - } - return $return_value; -} - -/** - * Gets count of exam results - * @todo this function should be moved in a library + no global calls - */ -function get_count_exam_results($exercise_id, $extra_where_conditions) -{ - $count = get_exam_results_data(null, null, null, null, $exercise_id, $extra_where_conditions, true); - return $count; -} - -function get_count_exam_hotpotatoes_results($in_hotpot_path) -{ - return get_exam_results_hotpotatoes_data(0, 0, '', '', $in_hotpot_path, true, ''); -} - -//function get_exam_results_hotpotatoes_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) { -function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_column, $in_direction, $in_hotpot_path, $in_get_count = false, $where_condition = null) -{ - $tab_res = array(); - $courseId = api_get_course_int_id(); - - // by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name - if ($in_column == 1) { - $in_column = 'firstname'; - } - - $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); - $TBL_GROUP_REL_USER = Database :: get_course_table(TABLE_GROUP_USER); - $TBL_GROUP = Database :: get_course_table(TABLE_GROUP); - $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); - - $sql = "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp - JOIN $TBL_USER u ON thp.exe_user_id = u.user_id - WHERE thp.c_id = '$courseId' AND - exe_name LIKE '$in_hotpot_path%'"; - - // just count how many answers - if ($in_get_count) { - $res = Database::query($sql); - return Database::num_rows($res); - } - - // get a number of sorted results - $sql .= " $where_condition ORDER BY $in_column $in_direction LIMIT $in_from, $in_number_of_items"; - - $res = Database::query($sql); - while ($data = Database::fetch_array($res)) { - $tab_one_res = array(); - $tab_one_res['firstname'] = $data['firstname']; - $tab_one_res['lastname'] = $data['lastname']; - $tab_one_res['username'] = $data['username']; - $tab_one_res['group_name'] = implode("
", GroupManager::get_user_group_name($data['user_id'])); - $tab_one_res['exe_date'] = $data['exe_date']; - $tab_one_res['score'] = $data['exe_result'].'/'.$data['exe_weighting']; - $tab_one_res['actions'] = ""; - $tab_res[] = $tab_one_res; - } - return $tab_res; -} - -/** - * Gets the exam'data results - * @todo this function should be moved in a library + no global calls - */ -function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) -{ - //@todo replace all this globals - global $documentPath, $filter; - - if (empty($extra_where_conditions)) { - $extra_where_conditions = "1 = 1 "; - } - - $course_id = api_get_course_int_id(); - $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh(); - - $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); - $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); - $TBL_GROUP_REL_USER = Database :: get_course_table(TABLE_GROUP_USER); - $TBL_GROUP = Database :: get_course_table(TABLE_GROUP); - - $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); - $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - - $session_id_and = ' AND te.session_id = '.api_get_session_id().' '; - - $exercise_id = intval($exercise_id); - - $exercise_where = ''; - if (!empty($exercise_id)) { - $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.' '; - } - - $hotpotatoe_where = ''; - if (!empty($_GET['path'])) { - $hotpotatoe_path = Database::escape_string($_GET['path']); - $hotpotatoe_where .= ' AND exe_name = "'.$hotpotatoe_path.'" '; - } - - // sql for chamilo-type tests for teacher / tutor view - $sql_inner_join_tbl_track_exercices = " ( - SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised - FROM $TBL_TRACK_EXERCICES ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr - ON (ttte.exe_id = tr.exe_id) - WHERE ttte.c_id = '$course_id' AND - exe_exo_id = $exercise_id AND - ttte.session_id = ".api_get_session_id()." - )"; - if ($is_allowedToEdit) { - //Teacher view - if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { - //$exercise_where_query = ' te.exe_exo_id = ce.id AND '; - } - - $sqlFromOption = ""; - $sqlWhereOption = ""; // for hpsql - //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries - //Hack in order to filter groups - $sql_inner_join_tbl_user = ''; - - if (strpos($extra_where_conditions, 'group_id')) { - $sql_inner_join_tbl_user = " - ( - SELECT u.user_id, firstname, lastname, email, username, g.name as group_name, g.id as group_id - FROM $TBL_USER u - INNER JOIN $TBL_GROUP_REL_USER gru ON ( gru.user_id = u.user_id AND gru.c_id=".$course_id.") - INNER JOIN $TBL_GROUP g ON (gru.group_id = g.id AND g.c_id=".$course_id.") - )"; - } - - if (strpos($extra_where_conditions, 'group_all')) { - - $extra_where_conditions = str_replace("AND ( group_id = 'group_all' )", '', $extra_where_conditions); - $extra_where_conditions = str_replace("AND group_id = 'group_all'", '', $extra_where_conditions); - $extra_where_conditions = str_replace("group_id = 'group_all' AND", '', $extra_where_conditions); - - $sql_inner_join_tbl_user = " - ( - SELECT u.user_id, firstname, lastname, email, username, '' as group_name, '' as group_id - FROM $TBL_USER u - )"; - $sql_inner_join_tbl_user = null; - } - - if (strpos($extra_where_conditions, 'group_none')) { - $extra_where_conditions = str_replace("AND ( group_id = 'group_none' )", "AND ( group_id is null )", $extra_where_conditions); - $extra_where_conditions = str_replace("AND group_id = 'group_none'", "AND ( group_id is null )", $extra_where_conditions); - $sql_inner_join_tbl_user = " - ( - SELECT u.user_id, firstname, lastname, email, username, g.name as group_name, g.id as group_id - FROM $TBL_USER u - LEFT OUTER JOIN $TBL_GROUP_REL_USER gru ON ( gru.user_id = u.user_id AND gru.c_id=".$course_id." ) - LEFT OUTER JOIN $TBL_GROUP g ON (gru.group_id = g.id AND g.c_id = ".$course_id.") - )"; - } - - //All - $is_empty_sql_inner_join_tbl_user = false; - - if (empty($sql_inner_join_tbl_user)) { - $is_empty_sql_inner_join_tbl_user = true; - $sql_inner_join_tbl_user = " - ( - SELECT u.user_id, firstname, lastname, email, username, ' ' as group_name, '' as group_id - FROM $TBL_USER u - )"; - } - - - $sqlFromOption = " , $TBL_GROUP_REL_USER AS gru "; - $sqlWhereOption = " AND gru.c_id = ".api_get_course_int_id()." AND gru.user_id = user.user_id "; - - $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname"; - - if ($get_count) { - $sql_select = "SELECT count(te.exe_id) "; - } else { - $sql_select = "SELECT DISTINCT - user_id, - $first_and_last_name, - ce.title, - username, - te.exe_result, - te.exe_weighting, - te.exe_date, - te.exe_id, - email as exemail, - te.start_date, - steps_counter, - exe_user_id, - te.exe_duration, - propagate_neg, - revised, - group_name, - group_id, - orig_lp_id"; - } - - $sql = " $sql_select - FROM $TBL_EXERCICES AS ce - INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.iid) - INNER JOIN $sql_inner_join_tbl_user AS user ON (user.user_id = exe_user_id) - WHERE $extra_where_conditions AND - te.status != 'incomplete' - AND te.c_id='".$course_id."' $session_id_and - AND ce.active <>-1 - AND ce.c_id=".$course_id." - $exercise_where "; - - // sql for hotpotatoes tests for teacher / tutor view - - if ($get_count) { - $hpsql_select = "SELECT count(username)"; - } else { - $hpsql_select = "SELECT - $first_and_last_name , - username, - tth.exe_name, - tth.exe_result , - tth.exe_weighting, - tth.exe_date"; - } - // AND $where_condition seems not to be used - $hpsql = " $hpsql_select - FROM - $TBL_TRACK_HOTPOTATOES tth, - $TBL_USER user - $sqlFromOption - WHERE - user.user_id=tth.exe_user_id - AND tth.c_id = '".$course_id."' - $hotpotatoe_where - $sqlWhereOption - - ORDER BY - tth.c_id ASC, - tth.exe_date DESC"; - } - - if ($get_count) { - $resx = Database::query($sql); - $rowx = Database::fetch_row($resx, 'ASSOC'); - return $rowx[0]; - } - - $teacher_list = CourseManager::get_teacher_list_from_course_code(api_get_course_int_id()); - $teacher_id_list = array(); - foreach ($teacher_list as $teacher) { - $teacher_id_list[] = $teacher['user_id']; - } - - //Simple exercises - if (empty($hotpotatoe_where)) { - $column = !empty($column) ? Database::escape_string($column) : null; - $from = intval($from); - $number_of_items = intval($number_of_items); - - if (!empty($column)) { - $sql .= " ORDER BY $column $direction "; - } - $sql .= " LIMIT $from, $number_of_items"; - - $results = array(); - $resx = Database::query($sql); - while ($rowx = Database::fetch_array($resx, 'ASSOC')) { - $results[] = $rowx; - } - - $list_info = array(); - - $group_list = GroupManager::get_group_list(); - $clean_group_list = array(); - - if (!empty($group_list)) { - foreach ($group_list as $group) { - $clean_group_list[$group['id']] = $group['name']; - } - } - - $lp_list_obj = new LearnpathList(api_get_user_id()); - $lp_list = $lp_list_obj->get_flat_list(); - - if (is_array($results)) { - - $users_array_id = array(); - if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { - $from_gradebook = true; - } - $sizeof = count($results); - - $user_list_id = array(); - - $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE); - - //Looping results - for ($i = 0; $i < $sizeof; $i++) { - $revised = $results[$i]['revised']; - - if (isset($from_gradebook) && $from_gradebook && $is_allowedToEdit) { - if (in_array($results[$i]['username'].$results[$i]['firstname'].$results[$i]['lastname'], $users_array_id)) { - continue; - } - $users_array_id[] = $results[$i]['username'].$results[$i]['firstname'].$results[$i]['lastname']; - } - - $lp_obj = isset($results[$i]['orig_lp_id']) && isset($lp_list[$results[$i]['orig_lp_id']]) ? $lp_list[$results[$i]['orig_lp_id']] : null; - $lp_name = null; - - if ($lp_obj) { - $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$results[$i]['orig_lp_id']; - $lp_name = Display::url($lp_obj['lp_name'], $url, array('target' => '_blank')); - } - - //Add all groups by user - $group_name_list = null; - - if ($is_empty_sql_inner_join_tbl_user) { - $group_list = GroupManager::get_group_ids(api_get_course_int_id(), $results[$i]['user_id']); - - foreach ($group_list as $id) { - $group_name_list .= $clean_group_list[$id].'
'; - } - $results[$i]['group_name'] = $group_name_list; - } - - $results[$i]['exe_duration'] = !empty($results[$i]['exe_duration']) ? round($results[$i]['exe_duration'] / 60) : 0; - - $user_list_id[] = $results[$i]['exe_user_id']; - $id = $results[$i]['exe_id']; - - $dt = api_convert_and_format_date($results[$i]['exe_weighting']); - - // we filter the results if we have the permission to - if (isset($results[$i]['results_disabled'])) { - $result_disabled = intval($results[$i]['results_disabled']); - } else { - $result_disabled = 0; - } - - if ($result_disabled == 0) { - - $my_res = $results[$i]['exe_result']; - $my_total = $results[$i]['exe_weighting']; - - $results[$i]['start_date'] = api_get_local_time($results[$i]['start_date']); - $results[$i]['exe_date'] = api_get_local_time($results[$i]['exe_date']); - - if (!$results[$i]['propagate_neg'] && $my_res < 0) { - $my_res = 0; - } - $score = show_score($my_res, $my_total); - - $actions = ''; - if ($is_allowedToEdit) { - if (isset($teacher_id_list)) { - if (in_array($results[$i]['exe_user_id'], $teacher_id_list)) { - $actions .= Display::return_icon('teachers.gif', get_lang('Teacher')); - } - } - if ($revised) { - $actions .= "".Display :: return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); - $actions .= ' '; - } else { - $actions .="".Display :: return_icon('quiz.gif', get_lang('Qualify')); - $actions .=' '; - } - $actions .=""; - - if ($filter == 2) { - $actions .=' '.Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).''; - } - - //Admin can always delete the attempt - if ($locked == false || api_is_platform_admin()) { - $ip = TrackingUserLog::get_ip_from_user_event($results[$i]['exe_user_id'], $results[$i]['exe_date'], false); - $actions .= ''; - $delete_link = ''.Display :: return_icon('delete.png', get_lang('Delete')).''; - $delete_link = utf8_encode($delete_link); - $actions .= $delete_link.' '; - } - } else { - $attempt_url = api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&id='.$results[$i]['exe_id'].'&id_session='.api_get_session_id().'&height=500&width=750'; - $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class' => 'ajax btn')); - $actions .= $attempt_link; - } - - if ($revised) { - $revised = Display::label(get_lang('Validated'), 'success'); - } else { - $revised = Display::label(get_lang('NotValidated'), 'info'); - } - - if ($is_allowedToEdit) { - $results[$i]['status'] = $revised; - $results[$i]['score'] = $score; - $results[$i]['lp'] = $lp_name; - $results[$i]['actions'] = $actions; - $list_info[] = $results[$i]; - } else { - $results[$i]['status'] = $revised; - $results[$i]['score'] = $score; - $results[$i]['actions'] = $actions; - $list_info[] = $results[$i]; - } - } - } - } - } else { - - $hpresults = getManyResultsXCol($hpsql, 6); - - // Print HotPotatoes test results. - if (is_array($hpresults)) { - - for ($i = 0; $i < sizeof($hpresults); $i++) { - $hp_title = GetQuizName($hpresults[$i][3], $documentPath); - if ($hp_title == '') { - $hp_title = basename($hpresults[$i][3]); - } - - $hp_date = api_get_local_time($hpresults[$i][6], null, date_default_timezone_get()); - $hp_result = round(($hpresults[$i][4] / ($hpresults[$i][5] != 0 ? $hpresults[$i][5] : 1)) * 100, 2).'% ('.$hpresults[$i][4].' / '.$hpresults[$i][5].')'; - if ($is_allowedToEdit) { - $list_info[] = array($hpresults[$i][0], $hpresults[$i][1], $hpresults[$i][2], '', $hp_title, '-', $hp_date, $hp_result, '-'); - } else { - $list_info[] = array($hp_title, '-', $hp_date, $hp_result, '-'); - } - } - } - } - - return $list_info; -} - -/** - * Converts the score with the exercise_max_note and exercise_min_score the platform settings + formats the results using the Text::float_format function - * - * @param float score - * @param float weight - * @param bool show porcentage or not - * @param bool use or not the platform settings - * @return string an html with the score modified - */ -function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true, $show_only_percentage = false) -{ - if (is_null($score) && is_null($weight)) { - return '-'; - } - - $max_note = api_get_setting('exercise_max_score'); - $min_note = api_get_setting('exercise_min_score'); - - if ($use_platform_settings) { - if ($max_note != '' && $min_note != '') { - if (!empty($weight) && intval($weight) != 0) { - $score = $min_note + ($max_note - $min_note) * $score / $weight; - } else { - $score = $min_note; - } - $weight = $max_note; - } - } - $percentage = (100 * $score) / ($weight != 0 ? $weight : 1); - - //Formats values - $percentage = Text::float_format($percentage, 1); - $score = Text::float_format($score, 1); - $weight = Text::float_format($weight, 1); - - $html = null; - if ($show_percentage) { - $parent = '('.$score.' / '.$weight.')'; - $html = $percentage." % $parent"; - if ($show_only_percentage) { - $html = $percentage."% "; - } - } else { - $html = $score.' / '.$weight; - } - $html = Display::span($html, array('class' => 'score_exercise')); - return $html; -} - -function is_success_exercise_result($score, $weight, $pass_percentage) -{ - $percentage = Text::float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1); - if (isset($pass_percentage) && !empty($pass_percentage)) { - if ($percentage >= $pass_percentage) { - return true; - } - } - return false; -} - -function show_success_message($score, $weight, $pass_percentage) -{ - $res = ""; - if (is_pass_pourcentage_enabled($pass_percentage)) { - $is_success = is_success_exercise_result($score, $weight, $pass_percentage); - - $icon = ''; - if ($is_success) { - $html = get_lang('CongratulationsYouPassedTheTest'); - $icon = Display::return_icon('completed.png', get_lang('Correct'), array(), ICON_SIZE_MEDIUM); - } else { - //$html .= Display::return_message(get_lang('YouDidNotReachTheMinimumScore'), 'warning'); - $html = get_lang('YouDidNotReachTheMinimumScore'); - $icon = Display::return_icon('warning.png', get_lang('Wrong'), array(), ICON_SIZE_MEDIUM); - } - $html = Display::tag('h4', $html); - $html .= Display::tag('h5', $icon, array('style' => 'width:40px; padding:2px 10px 0px 0px')); - $res = $html; - } - return $res; -} - -/** - * Return true if pass_pourcentage activated (we use the pass pourcentage feature - * return false if pass_percentage = 0 (we don't use the pass pourcentage feature - * @param $in_pass_pourcentage - * @return boolean - * In this version, pass_percentage and show_success_message are disabled if - * pass_percentage is set to 0 - */ -function is_pass_pourcentage_enabled($in_pass_pourcentage) -{ - return $in_pass_pourcentage > 0; -} - -/** - * Converts a numeric value in a percentage example 0.66666 to 66.67 % - * @param $value - * @return float Converted number - */ -function convert_to_percentage($value) -{ - $return = '-'; - if ($value != '') { - $return = Text::float_format($value * 100, 1).' %'; - } - return $return; -} - -/** - * Converts a score/weight values to the platform scale - * @param float score - * @param float weight - * @return float the score rounded converted to the new range - */ -function convert_score($score, $weight) -{ - $max_note = api_get_setting('exercise_max_score'); - $min_note = api_get_setting('exercise_min_score'); - - if ($score != '' && $weight != '') { - if ($max_note != '' && $min_note != '') { - if (!empty($weight)) { - $score = $min_note + ($max_note - $min_note) * $score / $weight; - } else { - $score = $min_note; - } - } - } - $score_rounded = Text::float_format($score, 1); - return $score_rounded; -} - -/** - * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session) - * @param array course data - * @param int session id - * @return array array with exercise data - */ -function get_all_exercises($course_info = null, $session_id = 0, $check_publication_dates = false) -{ - $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); - $course_id = api_get_course_int_id(); - if (!empty($course_info) && !empty($course_info['real_id'])) { - $course_id = $course_info['real_id']; - } - - if ($session_id == -1) { - $session_id = 0; - } - - $now = api_get_utc_datetime(); - $time_conditions = ''; - - if ($check_publication_dates) { - $time_conditions = " AND ((start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now' ) OR "; //start and end are set - $time_conditions .= " (start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time = '0000-00-00 00:00:00') OR "; // only start is set - $time_conditions .= " (start_time = '0000-00-00 00:00:00' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now') OR "; // only end is set - $time_conditions .= " (start_time = '0000-00-00 00:00:00' AND end_time = '0000-00-00 00:00:00')) "; // nothing is set - } - - if ($session_id == 0) { - $conditions = array('where' => array('active = ? AND session_id = ? AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order' => 'title'); - } else { - //All exercises - $conditions = array('where' => array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order' => 'title'); - } - $result = Database::select('*', $TBL_EXERCICES, $conditions); - return $result; -} - -/** - * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session) - * @param array course data - * @param int session id - * @param int course c_id - * @return array array with exercise data - * modified by Hubert Borderiou - */ -function get_all_exercises_for_course_id($course_info = null, $session_id = 0, $course_id = 0) -{ - $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); - if ($session_id == -1) { - $session_id = 0; - } - if ($session_id == 0) { - $conditions = array('where' => array('active = ? AND session_id = ? AND c_id = ?' => array('1', $session_id, $course_id)), 'order' => 'title'); - } else { - //All exercises - $conditions = array('where' => array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id=?' => array('1', $session_id, $course_id)), 'order' => 'title'); - } - return Database::select('*', $TBL_EXERCICES, $conditions); -} - -/** - * Gets the position of the score based in a given score (result/weight) and the exe_id based in the user list - * (NO Exercises in LPs ) - * @param float user score to be compared *attention* $my_score = score/weight and not just the score - * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) - * @param int exercise id - * @param string course code - * @param int session id - * @return int the position of the user between his friends in a course (or course within a session) - */ -function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_id, $session_id = 0, $user_list = array(), $return_string = true) -{ - //No score given we return - if (is_null($my_score)) { - return '-'; - } - if (empty($user_list)) { - return '-'; - } - - $best_attempts = array(); - foreach ($user_list as $user_data) { - $user_id = $user_data['user_id']; - $best_attempts[$user_id] = get_best_attempt_by_user($user_id, $exercise_id, $course_id, $session_id); - } - - if (empty($best_attempts)) { - return 1; - } else { - $position = 1; - $my_ranking = array(); - foreach ($best_attempts as $user_id => $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $my_ranking[$user_id] = $result['exe_result'] / $result['exe_weighting']; - } else { - $my_ranking[$user_id] = 0; - } - } - //if (!empty($my_ranking)) { - asort($my_ranking); - $position = count($my_ranking); - if (!empty($my_ranking)) { - foreach ($my_ranking as $user_id => $ranking) { - if ($my_score >= $ranking) { - if ($my_score == $ranking) { - $exe_id = $best_attempts[$user_id]['exe_id']; - if ($my_exe_id < $exe_id) { - $position--; - } - } else { - $position--; - } - } - } - } - //} - $return_value = array('position' => $position, 'count' => count($my_ranking)); - - if ($return_string) { - if (!empty($position) && !empty($my_ranking)) { - $return_value = $position.'/'.count($my_ranking); - } else { - $return_value = '-'; - } - } - return $return_value; - } -} - -/** - * Gets the position of the score based in a given score (result/weight) and the exe_id based in all attempts - * (NO Exercises in LPs ) old funcionality by attempt - * @param float user score to be compared attention => score/weight - * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) - * @param int exercise id - * @param int course id - * @param int session id - * @return int the position of the user between his friends in a course (or course within a session) - */ -function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $courseId, $session_id = 0, $return_string = true) -{ - if (empty($session_id)) { - $session_id = 0; - } - if (is_null($my_score)) { - return '-'; - } - $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false); - $position_data = array(); - if (empty($user_results)) { - return 1; - } else { - $position = 1; - $my_ranking = array(); - foreach ($user_results as $result) { - //print_r($result); - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $my_ranking[$result['exe_id']] = $result['exe_result'] / $result['exe_weighting']; - } else { - $my_ranking[$result['exe_id']] = 0; - } - } - asort($my_ranking); - $position = count($my_ranking); - if (!empty($my_ranking)) { - foreach ($my_ranking as $exe_id => $ranking) { - if ($my_score >= $ranking) { - if ($my_score == $ranking) { - if ($my_exe_id < $exe_id) { - $position--; - } - } else { - $position--; - } - } - } - } - $return_value = array('position' => $position, 'count' => count($my_ranking)); - - if ($return_string) { - if (!empty($position) && !empty($my_ranking)) { - return $position.'/'.count($my_ranking); - } - } - return $return_value; - } -} -/* - * Get the best attempt in a exercise (NO Exercises in LPs ) - */ - -function get_best_attempt_in_course($exercise_id, $courseId, $session_id) -{ - $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false); - $best_score_data = array(); - $best_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - if ($score >= $best_score) { - $best_score = $score; - $best_score_data = $result; - } - } - } - } - return $best_score_data; -} - -/** - * Get the best score in a exercise (NO Exercises in LPs ) - * @param $user_id - * @param $exercise_id - * @param $courseId - * @param $session_id - * @return array - */ -function get_best_attempt_by_user($user_id, $exercise_id, $courseId, $session_id) -{ - $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id, false, $user_id); - $best_score_data = array(); - $best_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - if ($score >= $best_score) { - $best_score = $score; - $best_score_data = $result; - } - } - } - } - return $best_score_data; -} - -/** - * Get average score (NO Exercises in LPs ) - * @param int exercise id - * @param int course id - * @param int session id - * @return float Average score - */ -function get_average_score($exercise_id, $courseId, $session_id) -{ - $user_results = get_all_exercise_results($exercise_id, $courseId, $session_id); - $avg_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - $avg_score +=$score; - } - } - $avg_score = Text::float_format($avg_score / count($user_results), 1); - } - return $avg_score; -} - -/** - * Get average score by score (NO Exercises in LPs ) - * @param int exercise id - * @param int course id - * @param int session id - * @return float Average score - */ -function get_average_score_by_course($courseId, $session_id) -{ - $user_results = get_all_exercise_results_by_course($courseId, $session_id, false); - $avg_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - $avg_score +=$score; - } - } - //We asume that all exe_weighting - //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); - $avg_score = ($avg_score / count($user_results)); - } - return $avg_score; -} - -/** - * - * @param $user_id - * @param $courseId - * @param $session_id - * - * @return float|int - */ -function get_average_score_by_course_by_user($user_id, $courseId, $session_id) -{ - $user_results = get_all_exercise_results_by_user($user_id, $courseId, $session_id); - $avg_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - $avg_score +=$score; - } - } - //We asume that all exe_weighting - //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); - $avg_score = ($avg_score / count($user_results)); - } - return $avg_score; -} - -/** - * Get average score by score (NO Exercises in LPs ) - * @param int exercise id - * @param int course id - * @param int session id - * - * @return float Best average score - */ -function get_best_average_score_by_exercise($exercise_id, $course_code, $session_id, $user_count) -{ - $user_results = get_best_exercise_results_by_user($exercise_id, $course_code, $session_id); - $avg_score = 0; - if (!empty($user_results)) { - foreach ($user_results as $result) { - if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { - $score = $result['exe_result'] / $result['exe_weighting']; - $avg_score +=$score; - } - } - //We asume that all exe_weighting - //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); - //$avg_score = ($avg_score / count($user_results)); - if (!empty($user_count)) { - $avg_score = Text::float_format($avg_score / $user_count, 1) * 100; - } else { - $avg_score = 0; - } - } - return $avg_score; -} - -/** - * @param $course_code - * @param $session_id - * @return array - */ -function get_exercises_to_be_taken($course_code, $session_id) -{ - $course_info = api_get_course_info($course_code); - $exercises = get_all_exercises($course_info, $session_id); - $result = array(); - $now = time() + 15 * 24 * 60 * 60; - foreach ($exercises as $exercise_item) { - if (isset($exercise_item['end_time']) && !empty($exercise_item['end_time']) && $exercise_item['end_time'] != '0000-00-00 00:00:00' && api_strtotime($exercise_item['end_time'], 'UTC') < $now) { - $result[] = $exercise_item; - } - } - return $result; -} - -/** - * Get student results (only in completed exercises) stats by question - * - * @param int question id - * @param int exercise id - * @param int course id - * @param int session id - * - * */ -function get_student_stats_by_question($question_id, $exercise_id, $courseId, $session_id) -{ - $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - - $question_id = intval($question_id); - $exercise_id = intval($exercise_id); - $courseId = intval($courseId); - $session_id = intval($session_id); - - $sql = "SELECT MAX(marks) as max , MIN(marks) as min, AVG(marks) as average - FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) - WHERE exe_exo_id = $exercise_id AND - e.c_id = $courseId AND - a.c_id = $courseId - e.session_id = $session_id AND - question_id = $question_id AND status = '' LIMIT 1"; - $result = Database::query($sql); - $return = array(); - if ($result) { - $return = Database::fetch_array($result, 'ASSOC'); - } - return $return; -} - -/** - * @param int $question_id - * @param int $exercise_id - * @param int $courseId - * @param int $session_id - * @return int - */ -function get_number_students_question_with_answer_count($question_id, $exercise_id, $courseId, $session_id) -{ - $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - - $question_id = intval($question_id); - $exercise_id = intval($exercise_id); - $courseId = intval($courseId); - $session_id = intval($session_id); - - - $sql = "SELECT DISTINCT exe_user_id - FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) INNER JOIN $course_user cu - ON cu.c_id = a.c_id AND cu.user_id = exe_user_id - WHERE exe_exo_id = $exercise_id AND - a.c_id = $courseId AND - e.session_id = $session_id AND - question_id = $question_id AND - answer <> '0' AND - cu.status = ".STUDENT." AND - relation_type <> 2 AND - e.status = ''"; - $result = Database::query($sql); - $return = 0; - if ($result) { - $return = Database::num_rows($result); - } - return $return; -} - -/** - * @param int $answer_id - * @param int $question_id - * @param int $exercise_id - * @param int $courseId - * @param int $session_id - * @return int - */ -function get_number_students_answer_hotspot_count($answer_id, $question_id, $exercise_id, $courseId, $session_id) -{ - $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $track_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); - $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - - $question_id = intval($question_id); - $answer_id = intval($answer_id); - $exercise_id = intval($exercise_id); - $courseId = intval($courseId); - $session_id = intval($session_id); - - $sql = "SELECT DISTINCT exe_user_id - FROM $track_exercises e - INNER JOIN $track_hotspot a ON (a.hotspot_exe_id = e.exe_id) - INNER JOIN $course_user cu - ON cu.c_id = a.c_id AND cu.user_id = exe_user_id - WHERE exe_exo_id = $exercise_id AND - a.c_id = $courseId AND - e.session_id = $session_id AND - hotspot_answer_id = $answer_id AND - hotspot_question_id = $question_id AND - cu.status = ".STUDENT." AND - hotspot_correct = 1 AND - relation_type <> 2 AND - e.status = ''"; - - $result = Database::query($sql); - $return = 0; - if ($result) { - $return = Database::num_rows($result); - } - return $return; -} - -/** - * - * @param int $answer_id - * @param int $question_id - * @param int $exercise_id - * @param int $courseId - * @param int $session_id - * @param string $question_type - * @param null $correct_answer - * @param null $current_answer - * @return int - */ -function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $courseId, $session_id, $question_type = null, $correct_answer = null, $current_answer = null) -{ - $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - - $question_id = intval($question_id); - $answer_id = intval($answer_id); - $exercise_id = intval($exercise_id); - $courseId = intval($courseId); - $session_id = intval($session_id); - - switch ($question_type) { - case FILL_IN_BLANKS: - $answer_condition = ""; - $select_condition = " e.exe_id, answer "; - break; - case MATCHING: - default: - $answer_condition = " answer = $answer_id AND "; - $select_condition = " DISTINCT exe_user_id "; - } - - $sql = "SELECT $select_condition - FROM $track_exercises e - INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) - INNER JOIN $course_user cu - ON cu.c_id = a.c_id AND cu.user_id = exe_user_id - WHERE exe_exo_id = $exercise_id AND - a.c_id = $courseId AND - e.session_id = $session_id AND - $answer_condition - question_id = $question_id AND - cu.status = ".STUDENT." AND - relation_type <> 2 AND - e.status = ''"; - $result = Database::query($sql); - $return = 0; - if ($result) { - $good_answers = 0; - switch ($question_type) { - case FILL_IN_BLANKS: - while ($row = Database::fetch_array($result, 'ASSOC')) { - $fill_blank = check_fill_in_blanks($correct_answer, $row['answer']); - if (isset($fill_blank[$current_answer]) && $fill_blank[$current_answer] == 1) { - $good_answers++; - } - } - return $good_answers; - break; - case MATCHING: - default: - $return = Database::num_rows($result); - } - } - return $return; -} - -function check_fill_in_blanks($answer, $user_answer) -{ - // the question is encoded like this - // [A] B [C] D [E] F::10,10,10@1 - // number 1 before the "@" means that is a switchable fill in blank question - // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 - // means that is a normal fill blank question - // first we explode the "::" - $pre_array = explode('::', $answer); - // is switchable fill blank or not - $last = count($pre_array) - 1; - $is_set_switchable = explode('@', $pre_array[$last]); - $switchable_answer_set = false; - if (isset($is_set_switchable[1]) && $is_set_switchable[1] == 1) { - $switchable_answer_set = true; - } - $answer = ''; - for ($k = 0; $k < $last; $k++) { - $answer .= $pre_array[$k]; - } - // splits weightings that are joined with a comma - $answerWeighting = explode(',', $is_set_switchable[0]); - - // we save the answer because it will be modified - //$temp = $answer; - $temp = $answer; - - $answer = ''; - $j = 0; - //initialise answer tags - $user_tags = $correct_tags = $real_text = array(); - // the loop will stop at the end of the text - while (1) { - // quits the loop if there are no more blanks (detect '[') - if (($pos = api_strpos($temp, '[')) === false) { - // adds the end of the text - $answer = $temp; - /* // Deprecated code - // TeX parsing - replacement of texcode tags - $answer = str_replace("{texcode}", $texstring, $answer); - */ - $real_text[] = $answer; - break; //no more "blanks", quit the loop - } - // adds the piece of text that is before the blank - //and ends with '[' into a general storage array - $real_text[] = api_substr($temp, 0, $pos + 1); - $answer .= api_substr($temp, 0, $pos + 1); - //take the string remaining (after the last "[" we found) - $temp = api_substr($temp, $pos + 1); - // quit the loop if there are no more blanks, and update $pos to the position of next ']' - if (($pos = api_strpos($temp, ']')) === false) { - // adds the end of the text - $answer .= $temp; - break; - } - - $str = $user_answer; - - preg_match_all('#\[([^[]*)\]#', $str, $arr); - $str = str_replace('\r\n', '', $str); - $choice = $arr[1]; - - $tmp = api_strrpos($choice[$j], ' / '); - $choice[$j] = api_substr($choice[$j], 0, $tmp); - $choice[$j] = trim($choice[$j]); - - //Needed to let characters ' and " to work as part of an answer - $choice[$j] = stripslashes($choice[$j]); - - $user_tags[] = api_strtolower($choice[$j]); - //put the contents of the [] answer tag into correct_tags[] - $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos)); - $j++; - $temp = api_substr($temp, $pos + 1); - } - - $answer = ''; - $real_correct_tags = $correct_tags; - $chosen_list = array(); - - $good_answer = array(); - - for ($i = 0; $i < count($real_correct_tags); $i++) { - if (!$switchable_answer_set) { - //needed to parse ' and " characters - $user_tags[$i] = stripslashes($user_tags[$i]); - if ($correct_tags[$i] == $user_tags[$i]) { - $good_answer[$correct_tags[$i]] = 1; - } elseif (!empty($user_tags[$i])) { - $good_answer[$correct_tags[$i]] = 0; - } else { - $good_answer[$correct_tags[$i]] = 0; - } - } else { - // switchable fill in the blanks - if (in_array($user_tags[$i], $correct_tags)) { - $correct_tags = array_diff($correct_tags, $chosen_list); - $good_answer[$correct_tags[$i]] = 1; - } elseif (!empty($user_tags[$i])) { - $good_answer[$correct_tags[$i]] = 0; - } else { - $good_answer[$correct_tags[$i]] = 0; - } - } - // adds the correct word, followed by ] to close the blank - $answer .= ' / '.$real_correct_tags[$i].']'; - if (isset($real_text[$i + 1])) { - $answer .= $real_text[$i + 1]; - } - } - return $good_answer; -} - -/** - * - * @param int $exercise_id - * @param int $courseId - * @param int $session_id - * @depracted seems not to be used - * @return int - */ -function get_number_students_finish_exercise($exercise_id, $courseId, $session_id) -{ - $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - - $exercise_id = intval($exercise_id); - $courseId = intval($courseId); - $session_id = intval($session_id); - - $sql = "SELECT DISTINCT exe_user_id - FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) - WHERE exe_exo_id = $exercise_id AND - a.c_id = $courseId AND - e.c_id = $courseId AND - e.session_id = $session_id AND - status = ''"; - $result = Database::query($sql); - $return = 0; - if ($result) { - $return = Database::num_rows($result); - } - return $return; -} - -/** - // return the HTML code for a menu with students group - // @input : $in_name : is the name and the id of the - */ -function displayGroupMenu($in_name, $in_default, $in_onchange = "") -{ - // check the default value of option - $tabSelected = array($in_default => " selected='selected' "); - $res = ""; - $res .= ""; - return $res; -} - -/** - * Return a list of group for user with user_id=in_userid separated with in_separator - * @deprecated ? - */ -function displayGroupsForUser($in_separator, $in_userid) -{ - $res = implode($in_separator, GroupManager::get_user_group_name($in_userid)); - if ($res == "") { - $res = "
-
"; - } - return $res; -} - -function create_chat_exercise_session($exe_id) -{ - if (!isset($_SESSION['current_exercises'])) { - $_SESSION['current_exercises'] = array(); - } - $_SESSION['current_exercises'][$exe_id] = true; -} - -function delete_chat_exercise_session($exe_id) -{ - if (isset($_SESSION['current_exercises'])) { - $_SESSION['current_exercises'][$exe_id] = false; - } -} - -/** - * Display the exercise results - * @param obj exercise obj - * @param int attempt id (exe_id) - * @param bool save users results (true) or just show the results (false) - */ -function display_question_list_by_attempt($objExercise, $exe_id, $save_user_result = false) -{ - global $origin, $debug; - - //Getting attempt info - $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id); - - //Getting question list - $question_list = array(); - if (!empty($exercise_stat_info['data_tracking'])) { - $question_list = explode(',', $exercise_stat_info['data_tracking']); - } else { - //Try getting the question list only if save result is off - if ($save_user_result == false) { - $question_list = $objExercise->get_validated_question_list(); - } - error_log("Data tracking is empty! exe_id: $exe_id"); - } - - $counter = 1; - $total_score = 0; - $total_weight = 0; - - $exercise_content = null; - - //Hide results - $show_results = false; - $show_only_score = false; - - if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) { - $show_results = true; - } - - if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) { - $show_only_score = true; - } - - if ($show_results || $show_only_score) { - $user_info = api_get_user_info($exercise_stat_info['exe_user_id']); - //Shows exercise header - echo $objExercise->show_exercise_result_header($user_info['complete_name'], api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration']); - } - - // Display text when test is finished #4074 and for LP #4227 - $end_of_message = $objExercise->selectTextWhenFinished(); - if (!empty($end_of_message)) { - Display::display_normal_message($end_of_message, false); - echo "
 
"; - } - - $question_list_answers = array(); - $media_list = array(); - $category_list = array(); - - // Loop over all question to show results for each of them, one by one - if (!empty($question_list)) { - if ($debug) { - error_log('Looping question_list '.print_r($question_list, 1)); - } - - $media_questions = $objExercise->get_media_list(); - $media_is_activated = $objExercise->media_is_activated($media_questions); - - $medias_showed = array(); - - foreach ($question_list as $questionId) { - - // Creates a temporary Question object - $objQuestionTmp = Question::read($questionId); - - // This variable commes from exercise_submit_modal.php - ob_start(); - $hotspot_delineation_result = null; - - // We're inside *one* question. Go through each possible answer for this question - $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result); - - if (empty($result)) { - continue; - } - - $total_score += $result['score']; - $total_weight += $result['weight']; - - $question_list_answers[] = array( - 'question' => $result['open_question'], - 'answer' => $result['open_answer'], - 'answer_type' => $result['answer_type'] - ); - - $my_total_score = $result['score']; - $my_total_weight = $result['weight']; - - // Category report - $category_was_added_for_this_test = false; - - if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) { - foreach ($objQuestionTmp->category_list as $category_id) { - if (!isset($category_list[$category_id])) { - $category_list[$category_id] = array(); - $category_list[$category_id]['score'] = 0; - $category_list[$category_id]['total'] = 0; - } - $category_list[$category_id]['score'] += $my_total_score; - $category_list[$category_id]['total'] += $my_total_weight; - $category_was_added_for_this_test = true; - } - } - - // No category for this question! - if ($category_was_added_for_this_test == false) { - if (!isset($category_list['none'])) { - $category_list['none'] = array(); - $category_list['none']['score'] = 0; - $category_list['none']['total'] = 0; - } - - $category_list['none']['score'] += $my_total_score; - $category_list['none']['total'] += $my_total_weight; - } - - if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) { - $my_total_score = 0; - } - - $comnt = null; - if ($show_results) { - $comnt = get_comments($exe_id, $questionId); - if (!empty($comnt)) { - echo ''.get_lang('Feedback').''; - echo '
'.$comnt.'
'; - } - } - - $score = array(); - if ($show_results) { - $score['result'] = get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, true); - $score['pass'] = $my_total_score >= $my_total_weight ? true : false; - $score['score'] = $my_total_score; - $score['weight'] = $my_total_weight; - $score['comments'] = $comnt; - } - - $contents = ob_get_clean(); - - $question_content = '
'; - - if ($show_results) { - - $show_media = false; - if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) { - $show_media = true; - $media_list[] = $objQuestionTmp->parent_id; - } - - //Shows question title an description - $question_content .= $objQuestionTmp->return_header(null, $counter, $score, $show_media); - - // display question category, if any - $question_content .= Testcategory::getCategoryNamesForQuestion($questionId); - } - $counter++; - - $question_content .= $contents; - $question_content .= '
'; - - $exercise_content .= $question_content; - } // end foreach() block that loops over all questions - } - - $total_score_text = null; - - if ($origin != 'learnpath') { - if ($show_results || $show_only_score) { - $total_score_text .= '
'; - $total_score_text .= get_question_ribbon($objExercise, $total_score, $total_weight, true); - $total_score_text .= '
'; - } - } - - if (!empty($category_list) && ($show_results || $show_only_score)) { - //Adding total - $category_list['total'] = array('score' => $total_score, 'total' => $total_weight); - echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list); - } - - echo $total_score_text; - echo $exercise_content; - - if (!$show_only_score) { - echo $total_score_text; - } - - if ($save_user_result) { - - // Tracking of results - $learnpath_id = $exercise_stat_info['orig_lp_id']; - $learnpath_item_id = $exercise_stat_info['orig_lp_item_id']; - $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id']; - - if (api_is_allowed_to_session_edit()) { - update_event_exercise($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array()); - } - - // Send notification .. - if (!api_is_allowed_to_edit(null, true)) { - $objExercise->send_notification_for_open_questions($question_list_answers, $origin, $exe_id); - $objExercise->send_notification_for_oral_questions($question_list_answers, $origin, $exe_id); - } - } -} - -/** - * @param $objExercise - * @param $score - * @param $weight - * @param bool $check_pass_percentage - * @return string - */ -function get_question_ribbon($objExercise, $score, $weight, $check_pass_percentage = false) -{ - $ribbon = '
'; - if ($check_pass_percentage) { - $is_success = is_success_exercise_result($score, $weight, $objExercise->selectPassPercentage()); - // Color the final test score if pass_percentage activated - $ribbon_total_success_or_error = ""; - if (is_pass_pourcentage_enabled($objExercise->selectPassPercentage())) { - if ($is_success) { - $ribbon_total_success_or_error = ' ribbon-total-success'; - } else { - $ribbon_total_success_or_error = ' ribbon-total-error'; - } - } - $ribbon .= '
'; - } else { - $ribbon .= '
'; - } - $ribbon .= '

'.get_lang('YourTotalScore').": "; - $ribbon .= show_score($score, $weight, false, true); - $ribbon .= '

'; - $ribbon .= '
'; - if ($check_pass_percentage) { - $ribbon .= show_success_message($score, $weight, $objExercise->selectPassPercentage()); - } - $ribbon .= '
'; - return $ribbon; -} \ No newline at end of file diff --git a/main/exercice/exercise_admin.php b/main/exercice/exercise_admin.php index 7ad561e6ca..4a15509f44 100644 --- a/main/exercice/exercise_admin.php +++ b/main/exercice/exercise_admin.php @@ -20,7 +20,6 @@ require_once 'exercise.class.php'; require_once 'question.class.php'; require_once 'answer.class.php'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; $this_section = SECTION_COURSES; if (!api_is_allowed_to_edit(null,true)) { diff --git a/main/exercice/exercise_reminder.php b/main/exercice/exercise_reminder.php index 0b45fb4fb7..8100bd104b 100644 --- a/main/exercice/exercise_reminder.php +++ b/main/exercice/exercise_reminder.php @@ -15,7 +15,6 @@ require_once 'answer.class.php'; $language_file = 'exercice'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; if ($_GET['origin'] == 'learnpath') { require_once '../newscorm/learnpath.class.php'; @@ -52,7 +51,7 @@ if (!$objExercise) { } $time_control = false; -$clock_expired_time = get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); +$clock_expired_time = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) { $time_control = true; diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 4b32b0c866..dda4698e5b 100644 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -29,7 +29,6 @@ api_protect_course_script(true, false, true); // including additional libraries require_once 'exercise.class.php'; -require_once 'exercise.lib.php'; require_once 'question.class.php'; require_once 'answer.class.php'; require_once 'hotpotatoes.lib.php'; @@ -118,7 +117,7 @@ if (isset($_REQUEST['comments']) && $_REQUEST['comments'] == 'update' && ($is_al ) ) { $id = intval($_GET['exeid']); //filtered by post-condition - $track_exercise_info = get_exercise_track_exercise_info($id); + $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id); if (empty($track_exercise_info)) { api_not_allowed(); } diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 24d87935e5..9938b6a745 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -27,7 +27,6 @@ require_once 'answer.class.php'; $language_file = 'exercice'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; if ($_GET['origin'] == 'learnpath') { require_once '../newscorm/learnpath.class.php'; @@ -140,20 +139,20 @@ if ($objExercise->selectAttempts() > 0) { Display :: display_normal_message(get_lang('Saved').'
', false); //Display questions -display_question_list_by_attempt($objExercise, $exe_id, true); +ExerciseLib::display_question_list_by_attempt($objExercise, $exe_id, true); //If is not valid -$session_control_key = get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); -if (isset($session_control_key) && !exercise_time_control_is_valid($objExercise->id, $learnpath_id, $learnpath_item_id)) { +$session_control_key = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); +if (isset($session_control_key) && !ExerciseLib::exercise_time_control_is_valid($objExercise->id, $learnpath_id, $learnpath_item_id)) { $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks = 0, position = 0 WHERE exe_id = $exe_id "; Database::query($sql_fraud); } //Unset session for clock time -exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id); +ExerciseLib::exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id); -delete_chat_exercise_session($exe_id); +ExerciseLib::delete_chat_exercise_session($exe_id); if ($origin != 'learnpath') { echo '
'; diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index 1efb844487..5300e9567a 100644 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -24,7 +24,6 @@ require_once 'exercise.class.php'; require_once 'question.class.php'; //also defines answer type constants require_once 'answer.class.php'; require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; if (empty($origin) ) { $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null; @@ -72,7 +71,7 @@ if (api_is_course_session_coach(api_get_user_id(), api_get_course_int_id(), api_ $is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor || api_is_session_admin() || api_is_drh(); //Getting results from the exe_id. This variable also contain all the information about the exercise -$track_exercise_info = get_exercise_track_exercise_info($id); +$track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id); //No track info if (empty($track_exercise_info)) { @@ -618,7 +617,7 @@ foreach ($questionList as $questionId) { $score = array(); if ($show_results) { - $score['result'] = get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false); + $score['result'] = get_lang('Score')." : ".ExerciseLib::show_score($my_total_score, $my_total_weight, false, false); $score['pass'] = $my_total_score >= $my_total_weight ? true : false; $score['type'] = $answerType; $score['score'] = $my_total_score; @@ -666,7 +665,7 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) { $my_total_score_temp = 0; } - $total_score_text .= get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true); + $total_score_text .= ExerciseLib::get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true); $total_score_text .= '
'; } } diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 1e754c24cf..8510882568 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -39,7 +39,6 @@ $language_file = 'exercice'; require_once '../inc/global.inc.php'; $current_course_tool = TOOL_QUIZ; -require_once 'exercise.lib.php'; $nameTools = get_lang('Quiz'); @@ -427,7 +426,7 @@ if ($objExercise->expired_time != 0) { } //Generating the time control key for the user -$current_expired_time_key = get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); +$current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); if ($debug) error_log("4. current_expired_time_key: $current_expired_time_key "); $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp; @@ -469,7 +468,7 @@ if ($objExercise->selectAttempts() > 0) { $attempt_html .= Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score')); } } - $score = show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']); + $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']); $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score')); } else { $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); @@ -557,7 +556,7 @@ if (empty($exercise_stat_info)) { } //Array to check in order to block the chat -create_chat_exercise_session($exe_id); +ExerciseLib::create_chat_exercise_session($exe_id); if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); }; @@ -741,7 +740,7 @@ if ($formSent && isset($_POST)) { //Time control is only enabled for ONE PER PAGE if (!empty($exe_id) && is_numeric($exe_id)) { //Verify if the current test is fraudulent - if (exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id)) { + if (ExerciseLib::exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id)) { $sql_exe_result = ""; if ($debug) { error_log('exercise_time_control_is_valid is valid'); } } else { @@ -800,7 +799,7 @@ if ($question_count != 0) { //Time control is only enabled for ONE PER PAGE if (!empty($exe_id) && is_numeric($exe_id)) { //Verify if the current test is fraudulent - $check = exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id); + $check = ExerciseLib::exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id); if ($check) { $sql_exe_result = ""; @@ -875,7 +874,10 @@ if ($objExercise->type == ONE_PER_PAGE) { $conditions[] = array("class" => 'remind', 'items' => $my_remind_list); $conditions[] = array("class" => 'answered', 'items' => $exercise_result); $link = api_get_self().'?'.$params.'&num='; + + //$category_list = Testcategory::getListOfCategoriesNameForTest($objExercise->id, false); echo Display::progress_pagination_bar($questionList, $current_question, $conditions, $link); + //var_dump($category_list); } $is_visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); @@ -1359,7 +1361,7 @@ function render_question($objExercise, $questionId, $attempt_list, $remind_list, echo '
'; // Shows the question + possible answers - showQuestion($question_obj, false, $origin, $i, true, false, $user_choice, false); + ExerciseLib::showQuestion($question_obj, false, $origin, $i, true, false, $user_choice, false); // Button save and continue switch ($objExercise->type) { diff --git a/main/exercice/exercise_submit_modal.php b/main/exercice/exercise_submit_modal.php index 6c0cbf5e70..8b34c21680 100644 --- a/main/exercice/exercise_submit_modal.php +++ b/main/exercice/exercise_submit_modal.php @@ -23,7 +23,6 @@ $dbg_local = 0; require_once 'exercise.class.php'; require_once 'question.class.php'; require_once 'answer.class.php'; -require_once 'exercise.lib.php'; if (empty ($exerciseResult)) { $exerciseResult = $_SESSION['exerciseResult']; diff --git a/main/exercice/feedback.php b/main/exercice/feedback.php index 69b70012e1..b1254ccf47 100644 --- a/main/exercice/feedback.php +++ b/main/exercice/feedback.php @@ -14,8 +14,6 @@ include('exercise.class.php'); include('question.class.php'); include('answer.class.php'); -include('exercise.lib.php'); - // name of the language file that needs to be included $language_file = 'exercice'; diff --git a/main/exercice/hotpotatoes_exercise_report.php b/main/exercice/hotpotatoes_exercise_report.php index 833df6a073..668641b732 100644 --- a/main/exercice/hotpotatoes_exercise_report.php +++ b/main/exercice/hotpotatoes_exercise_report.php @@ -27,7 +27,6 @@ api_protect_course_script(true, false, true); // including additional libraries require_once 'exercise.class.php'; -require_once 'exercise.lib.php'; require_once 'question.class.php'; require_once 'answer.class.php'; require_once 'hotpotatoes.lib.php'; @@ -97,7 +96,7 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') { //Send student email @todo move this code in a class, library //if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) { // $id = intval($_GET['exeid']); //filtered by post-condition -// $track_exercise_info = get_exercise_track_exercise_info($id); +// $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id); // if (empty($track_exercise_info)) { // api_not_allowed(); // } diff --git a/main/exercice/live_stats.php b/main/exercice/live_stats.php index f32703499f..8cbcb931e8 100644 --- a/main/exercice/live_stats.php +++ b/main/exercice/live_stats.php @@ -6,7 +6,6 @@ require_once 'question.class.php'; require_once 'answer.class.php'; $language_file = array('exercice','tracking'); require_once '../inc/global.inc.php'; -require_once 'exercise.lib.php'; $this_section = SECTION_COURSES; $exercise_id = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? intval($_GET['exerciseId']) : 0; @@ -21,8 +20,8 @@ $objExercise = new Exercise(); $result = $objExercise->read($exercise_id); if (!$result) { - api_not_allowed(true); -} + api_not_allowed(true); +} $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name); @@ -38,7 +37,7 @@ Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow')); $minutes = 60; $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes; -//The order is important you need to check the the $column variable in the model.ajax.php file +//The order is important you need to check the the $column variable in the model.ajax.php file $columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score')); //Column config @@ -48,20 +47,20 @@ $column_model = array( array('name'=>'start_date', 'index'=>'start_date', 'width'=>'100', 'align'=>'left'), array('name'=>'question', 'index'=>'count_questions', 'width'=>'60', 'align'=>'left', 'sortable'=>'false'), array('name'=>'score', 'index'=>'score', 'width'=>'50', 'align'=>'left','sortable'=>'false'), - ); -//Autowidth + ); +//Autowidth $extra_params['autowidth'] = 'true'; -//height auto -$extra_params['height'] = 'auto'; +//height auto +$extra_params['height'] = 'auto'; /* //With this function we can add actions to the jgrid (edit, delete, etc) $action_links = 'function action_formatter(cellvalue, options, rowObject) { return \''.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''. ' '.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).''. ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''. - '\'; + '\'; }'; - */ + */ ?> '; + } + $s .= '
'; + + $s.=''; + + if (isset($select_items[$lines_count])) { + $s.= '
+ '.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].' +
'; + } else { + $s.=' '; + } + + $s .= ''; + $s .= ''; + $lines_count++; + //if the left side of the "matching" has been completely + // shown but the right side still has values to show... + if (($lines_count - 1) == $num_suggestions) { + // if it remains answers to shown at the right side + while (isset($select_items[$lines_count])) { + $s .= ' + + '; + $s.=''.$select_items[$lines_count]['letter'].'.'; + $s .= $select_items[$lines_count]['answer']; + $s.=" + "; + $lines_count++; + } // end while() + } // end if() + $matching_correct_answer++; + } + } elseif ($answerType == DRAGGABLE) { + // matching type, showing suggestions and answers + // TODO: replace $answerId by $numAnswer + + if ($answerCorrect != 0) { + // only show elements to be answered (not the contents of + // the select boxes, who are correct = 0) + $s .= ''; + $parsed_answer = $answer; + $windowId = $questionId.'_'.$numAnswer; //67_293 - 67_294 + + //left part questions + $s .= '
  • '; + $s .= '
    + '.$parsed_answer.' +
    '; + + $s .= '
    '; + $s .= ''; + + if (!empty($answerCorrect) && !empty($selectedValue)) { + $s.= ''; + } + + + if (isset($select_items[$lines_count])) { + $s.= '
    + '.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].' +
    '; + } else { + $s.=' '; + } + $lines_count++; + //if the left side of the "matching" has been completely + // shown but the right side still has values to show... + + if (($lines_count - 1) == $num_suggestions) { + // if it remains answers to shown at the right side + while (isset($select_items[$lines_count])) { + $s.=''.$select_items[$lines_count]['letter'].'.'; + $s .= $select_items[$lines_count]['answer']; + $lines_count++; + } + } + $s .= '
    '; + $matching_correct_answer++; + $s .= '
  • '; + } + } + } // end for() + + if ($show_comment) { + $s .= ''; + } else { + if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || + $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { + $s .= ''; + } + } + + if ($answerType == DRAGGABLE) { + $s .= '
    '; + + $counterAnswer = 1; + foreach ($objAnswerTmp->answer as $answerId => $answer_item) { + //for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { + $answerCorrect = $objAnswerTmp->isCorrect($answerId); + $windowId = $questionId.'_'.$counterAnswer; + if ($answerCorrect == 0) { + $s .= '
    '.$counterAnswer.'
    '; + $counterAnswer++; + } + } + } + + if ($answerType == MATCHING) { + $s .= ''; + } + + $s .= ''; + + // destruction of the Answer object + unset($objAnswerTmp); + + // destruction of the Question object + unset($objQuestionTmp); + + if ($origin != 'export') { + echo $s; + } else { + return $s; + } + } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { + // Question is a HOT_SPOT + //checking document/images visibility + if (api_is_platform_admin() || api_is_course_admin()) { + $course = api_get_course_info(); + $doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName); + if (is_numeric($doc_id)) { + $images_folder_visibility = api_get_item_visibility($course, 'document', $doc_id, api_get_session_id()); + if (!$images_folder_visibility) { + //This message is shown only to the course/platform admin if the image is set to visibility = false + Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage')); + } + } + } + $questionName = $objQuestionTmp->selectTitle(); + $questionDescription = $objQuestionTmp->selectDescription(); + + if ($freeze) { + echo Display::img($objQuestionTmp->selectPicturePath()); + return; + } + + // Get the answers, make a list + $objAnswerTmp = new Answer($questionId); + $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); + + // get answers of hotpost + $answers_hotspot = array(); + //for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { + foreach ($objAnswerTmp->answer as $answerId => $answer_item) { + //$answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId)); + $answers_hotspot[$answerId] = $objAnswerTmp->selectAnswer($answerId); + } + + // display answers of hotpost order by id + $answer_list = '
    '.get_lang('HotspotZones').'
    '; + if (!empty($answers_hotspot)) { + ksort($answers_hotspot); + foreach ($answers_hotspot as $key => $value) { + $answer_list .= '
    '.$key.'.- '.$value.'

    '; + } + } + $answer_list .= '
    '; + + if ($answerType == HOT_SPOT_DELINEATION) { + $answer_list = ''; + $swf_file = 'hotspot_delineation_user'; + $swf_height = 405; + } else { + $swf_file = 'hotspot_user'; + $swf_height = 436; + } + + if (!$only_questions) { + if ($show_title) { + echo Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id); + echo '
    '.$current_item.'. '.$questionName.'
    '; + } + //@todo I need to the get the feedback type + echo ''; + echo ' + + '; + } + $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); + + $s .= ' + + + + + '; + $s .= ''; + echo $s; + echo '
    '; + echo $questionDescription; + echo '
    + +
    + + '.$answer_list.'
    +
    '; + } + return $nbrAnswers; + } + + /** + * @param int $exe_id + * @return array + */ + public static function get_exercise_track_exercise_info($exe_id) + { + $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); + $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $TBL_COURSE = Database::get_main_table(TABLE_MAIN_COURSE); + $exe_id = intval($exe_id); + $result_array = array(); + if (!empty($exe_id)) { + $sql = "SELECT q.*, tee.* + FROM $TBL_EXERCICES as q + INNER JOIN $TBL_TRACK_EXERCICES as tee + ON q.iid = tee.exe_exo_id + INNER JOIN $TBL_COURSE c + ON c.id = tee.c_id + WHERE tee.exe_id = $exe_id + AND q.c_id = c.id"; + + $result = Database::query($sql); + $result_array = Database::fetch_array($result, 'ASSOC'); + } + return $result_array; + } + + /** + * Validates the time control key + */ + public static function exercise_time_control_is_valid($exercise_id, $lp_id = 0, $lp_item_id = 0) + { + $course_id = api_get_course_int_id(); + $exercise_id = intval($exercise_id); + $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST); + $sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $exercise_id"; + $result = Database::query($sql); + $row = Database::fetch_array($result, 'ASSOC'); + if (!empty($row['expired_time'])) { + $current_expired_time_key = ExerciseLib::get_time_control_key($exercise_id, $lp_id, $lp_item_id); + if (isset($_SESSION['expired_time'][$current_expired_time_key])) { + $current_time = time(); + $expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC'); + $total_time_allowed = $expired_time + 30; + //error_log('expired time converted + 30: '.$total_time_allowed); + //error_log('$current_time: '.$current_time); + if ($total_time_allowed < $current_time) { + return false; + } + return true; + } else { + return false; + } + } else { + return true; + } + } + + /** + Deletes the time control token + */ + public static function exercise_time_control_delete($exercise_id, $lp_id = 0, $lp_item_id = 0) + { + $current_expired_time_key = self::get_time_control_key($exercise_id, $lp_id, $lp_item_id); + unset($_SESSION['expired_time'][$current_expired_time_key]); + } + + /** + Generates the time control key + */ + public static function get_time_control_key($exercise_id, $lp_id = 0, $lp_item_id = 0) + { + $exercise_id = intval($exercise_id); + $lp_id = intval($lp_id); + $lp_item_id = intval($lp_item_id); + return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id().'_'.$lp_id.'_'.$lp_item_id; + } + + /** + * Get session time control + */ + public static function get_session_time_control_key($exercise_id, $lp_id = 0, $lp_item_id = 0) + { + $return_value = 0; + $time_control_key = self::get_time_control_key($exercise_id, $lp_id, $lp_item_id); + if (isset($_SESSION['expired_time']) && isset($_SESSION['expired_time'][$time_control_key])) { + $return_value = $_SESSION['expired_time'][$time_control_key]; + } + return $return_value; + } + + /** + * Gets count of exam results + * @todo this public static function should be moved in a library + no global calls + */ + public static function get_count_exam_results($exercise_id, $extra_where_conditions) + { + $count = self::get_exam_results_data(null, null, null, null, $exercise_id, $extra_where_conditions, true); + return $count; + } + + public static function get_count_exam_hotpotatoes_results($in_hotpot_path) + { + return self::get_exam_results_hotpotatoes_data(0, 0, '', '', $in_hotpot_path, true, ''); + } + + //function get_exam_results_hotpotatoes_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) { + public static function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_column, $in_direction, $in_hotpot_path, $in_get_count = false, $where_condition = null) + { + $tab_res = array(); + $courseId = api_get_course_int_id(); + + // by default in_column = 1 If parameters given, it is the name of the column witch is the bdd field name + if ($in_column == 1) { + $in_column = 'firstname'; + } + + $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); + $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); + + $sql = "SELECT * FROM $TBL_TRACK_HOTPOTATOES thp + JOIN $TBL_USER u ON thp.exe_user_id = u.user_id + WHERE thp.c_id = '$courseId' AND + exe_name LIKE '$in_hotpot_path%'"; + + // just count how many answers + if ($in_get_count) { + $res = Database::query($sql); + return Database::num_rows($res); + } + + // get a number of sorted results + $sql .= " $where_condition ORDER BY $in_column $in_direction LIMIT $in_from, $in_number_of_items"; + + $res = Database::query($sql); + while ($data = Database::fetch_array($res)) { + $tab_one_res = array(); + $tab_one_res['firstname'] = $data['firstname']; + $tab_one_res['lastname'] = $data['lastname']; + $tab_one_res['username'] = $data['username']; + $tab_one_res['group_name'] = implode("
    ", GroupManager::get_user_group_name($data['user_id'])); + $tab_one_res['exe_date'] = $data['exe_date']; + $tab_one_res['score'] = $data['exe_result'].'/'.$data['exe_weighting']; + $tab_one_res['actions'] = ""; + $tab_res[] = $tab_one_res; + } + return $tab_res; + } + + /** + * Gets the exam'data results + * @todo this function should be moved in a library + no global calls + */ + public static function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) + { + //@todo replace all this globals + global $documentPath, $filter; + + if (empty($extra_where_conditions)) { + $extra_where_conditions = "1 = 1 "; + } + + $course_id = api_get_course_int_id(); + $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh(); + + $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); + $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); + $TBL_GROUP_REL_USER = Database :: get_course_table(TABLE_GROUP_USER); + $TBL_GROUP = Database :: get_course_table(TABLE_GROUP); + + $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); + $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); + + $session_id_and = ' AND te.session_id = '.api_get_session_id().' '; + + $exercise_id = intval($exercise_id); + + $exercise_where = ''; + if (!empty($exercise_id)) { + $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.' '; + } + + $hotpotatoe_where = ''; + if (!empty($_GET['path'])) { + $hotpotatoe_path = Database::escape_string($_GET['path']); + $hotpotatoe_where .= ' AND exe_name = "'.$hotpotatoe_path.'" '; + } + + // sql for chamilo-type tests for teacher / tutor view + $sql_inner_join_tbl_track_exercices = " ( + SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised + FROM $TBL_TRACK_EXERCICES ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr + ON (ttte.exe_id = tr.exe_id) + WHERE ttte.c_id = '$course_id' AND + exe_exo_id = $exercise_id AND + ttte.session_id = ".api_get_session_id()." + )"; + if ($is_allowedToEdit) { + //Teacher view + if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { + //$exercise_where_query = ' te.exe_exo_id = ce.id AND '; + } + + $sqlFromOption = ""; + $sqlWhereOption = ""; // for hpsql + //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries + //Hack in order to filter groups + $sql_inner_join_tbl_user = ''; + + if (strpos($extra_where_conditions, 'group_id')) { + $sql_inner_join_tbl_user = " + ( + SELECT u.user_id, firstname, lastname, email, username, g.name as group_name, g.id as group_id + FROM $TBL_USER u + INNER JOIN $TBL_GROUP_REL_USER gru ON ( gru.user_id = u.user_id AND gru.c_id=".$course_id.") + INNER JOIN $TBL_GROUP g ON (gru.group_id = g.id AND g.c_id=".$course_id.") + )"; + } + + if (strpos($extra_where_conditions, 'group_all')) { + + $extra_where_conditions = str_replace("AND ( group_id = 'group_all' )", '', $extra_where_conditions); + $extra_where_conditions = str_replace("AND group_id = 'group_all'", '', $extra_where_conditions); + $extra_where_conditions = str_replace("group_id = 'group_all' AND", '', $extra_where_conditions); + + $sql_inner_join_tbl_user = " + ( + SELECT u.user_id, firstname, lastname, email, username, '' as group_name, '' as group_id + FROM $TBL_USER u + )"; + $sql_inner_join_tbl_user = null; + } + + if (strpos($extra_where_conditions, 'group_none')) { + $extra_where_conditions = str_replace("AND ( group_id = 'group_none' )", "AND ( group_id is null )", $extra_where_conditions); + $extra_where_conditions = str_replace("AND group_id = 'group_none'", "AND ( group_id is null )", $extra_where_conditions); + $sql_inner_join_tbl_user = " + ( + SELECT u.user_id, firstname, lastname, email, username, g.name as group_name, g.id as group_id + FROM $TBL_USER u + LEFT OUTER JOIN $TBL_GROUP_REL_USER gru ON ( gru.user_id = u.user_id AND gru.c_id=".$course_id." ) + LEFT OUTER JOIN $TBL_GROUP g ON (gru.group_id = g.id AND g.c_id = ".$course_id.") + )"; + } + + //All + $is_empty_sql_inner_join_tbl_user = false; + + if (empty($sql_inner_join_tbl_user)) { + $is_empty_sql_inner_join_tbl_user = true; + $sql_inner_join_tbl_user = " + ( + SELECT u.user_id, firstname, lastname, email, username, ' ' as group_name, '' as group_id + FROM $TBL_USER u + )"; + } + + + $sqlFromOption = " , $TBL_GROUP_REL_USER AS gru "; + $sqlWhereOption = " AND gru.c_id = ".api_get_course_int_id()." AND gru.user_id = user.user_id "; + + $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname"; + + if ($get_count) { + $sql_select = "SELECT count(te.exe_id) "; + } else { + $sql_select = "SELECT DISTINCT + user_id, + $first_and_last_name, + ce.title, + username, + te.exe_result, + te.exe_weighting, + te.exe_date, + te.exe_id, + email as exemail, + te.start_date, + steps_counter, + exe_user_id, + te.exe_duration, + propagate_neg, + revised, + group_name, + group_id, + orig_lp_id"; + } + + $sql = " $sql_select + FROM $TBL_EXERCICES AS ce + INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.iid) + INNER JOIN $sql_inner_join_tbl_user AS user ON (user.user_id = exe_user_id) + WHERE $extra_where_conditions AND + te.status != 'incomplete' + AND te.c_id='".$course_id."' $session_id_and + AND ce.active <>-1 + AND ce.c_id=".$course_id." + $exercise_where "; + + // sql for hotpotatoes tests for teacher / tutor view + + if ($get_count) { + $hpsql_select = "SELECT count(username)"; + } else { + $hpsql_select = "SELECT + $first_and_last_name , + username, + tth.exe_name, + tth.exe_result , + tth.exe_weighting, + tth.exe_date"; + } + // AND $where_condition seems not to be used + $hpsql = " $hpsql_select + FROM + $TBL_TRACK_HOTPOTATOES tth, + $TBL_USER user + $sqlFromOption + WHERE + user.user_id=tth.exe_user_id + AND tth.c_id = '".$course_id."' + $hotpotatoe_where + $sqlWhereOption + + ORDER BY + tth.c_id ASC, + tth.exe_date DESC"; + } + + if ($get_count) { + $resx = Database::query($sql); + $rowx = Database::fetch_row($resx, 'ASSOC'); + return $rowx[0]; + } + + $teacher_list = CourseManager::get_teacher_list_from_course_code(api_get_course_int_id()); + $teacher_id_list = array(); + foreach ($teacher_list as $teacher) { + $teacher_id_list[] = $teacher['user_id']; + } + + //Simple exercises + if (empty($hotpotatoe_where)) { + $column = !empty($column) ? Database::escape_string($column) : null; + $from = intval($from); + $number_of_items = intval($number_of_items); + + if (!empty($column)) { + $sql .= " ORDER BY $column $direction "; + } + $sql .= " LIMIT $from, $number_of_items"; + + $results = array(); + $resx = Database::query($sql); + while ($rowx = Database::fetch_array($resx, 'ASSOC')) { + $results[] = $rowx; + } + + $list_info = array(); + + $group_list = GroupManager::get_group_list(); + $clean_group_list = array(); + + if (!empty($group_list)) { + foreach ($group_list as $group) { + $clean_group_list[$group['id']] = $group['name']; + } + } + + $lp_list_obj = new LearnpathList(api_get_user_id()); + $lp_list = $lp_list_obj->get_flat_list(); + + if (is_array($results)) { + + $users_array_id = array(); + if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') { + $from_gradebook = true; + } + $sizeof = count($results); + + $user_list_id = array(); + + $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE); + + //Looping results + for ($i = 0; $i < $sizeof; $i++) { + $revised = $results[$i]['revised']; + + if (isset($from_gradebook) && $from_gradebook && $is_allowedToEdit) { + if (in_array($results[$i]['username'].$results[$i]['firstname'].$results[$i]['lastname'], $users_array_id)) { + continue; + } + $users_array_id[] = $results[$i]['username'].$results[$i]['firstname'].$results[$i]['lastname']; + } + + $lp_obj = isset($results[$i]['orig_lp_id']) && isset($lp_list[$results[$i]['orig_lp_id']]) ? $lp_list[$results[$i]['orig_lp_id']] : null; + $lp_name = null; + + if ($lp_obj) { + $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$results[$i]['orig_lp_id']; + $lp_name = Display::url($lp_obj['lp_name'], $url, array('target' => '_blank')); + } + + //Add all groups by user + $group_name_list = null; + + if ($is_empty_sql_inner_join_tbl_user) { + $group_list = GroupManager::get_group_ids(api_get_course_int_id(), $results[$i]['user_id']); + + foreach ($group_list as $id) { + $group_name_list .= $clean_group_list[$id].'
    '; + } + $results[$i]['group_name'] = $group_name_list; + } + + $results[$i]['exe_duration'] = !empty($results[$i]['exe_duration']) ? round($results[$i]['exe_duration'] / 60) : 0; + + $user_list_id[] = $results[$i]['exe_user_id']; + $id = $results[$i]['exe_id']; + + $dt = api_convert_and_format_date($results[$i]['exe_weighting']); + + // we filter the results if we have the permission to + if (isset($results[$i]['results_disabled'])) { + $result_disabled = intval($results[$i]['results_disabled']); + } else { + $result_disabled = 0; + } + + if ($result_disabled == 0) { + + $my_res = $results[$i]['exe_result']; + $my_total = $results[$i]['exe_weighting']; + + $results[$i]['start_date'] = api_get_local_time($results[$i]['start_date']); + $results[$i]['exe_date'] = api_get_local_time($results[$i]['exe_date']); + + if (!$results[$i]['propagate_neg'] && $my_res < 0) { + $my_res = 0; + } + $score = self::show_score($my_res, $my_total); + + $actions = ''; + if ($is_allowedToEdit) { + if (isset($teacher_id_list)) { + if (in_array($results[$i]['exe_user_id'], $teacher_id_list)) { + $actions .= Display::return_icon('teachers.gif', get_lang('Teacher')); + } + } + if ($revised) { + $actions .= "".Display :: return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); + $actions .= ' '; + } else { + $actions .="".Display :: return_icon('quiz.gif', get_lang('Qualify')); + $actions .=' '; + } + $actions .=""; + + if ($filter == 2) { + $actions .=' '.Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).''; + } + + //Admin can always delete the attempt + if ($locked == false || api_is_platform_admin()) { + $ip = TrackingUserLog::get_ip_from_user_event($results[$i]['exe_user_id'], $results[$i]['exe_date'], false); + $actions .= ''; + $delete_link = ''.Display :: return_icon('delete.png', get_lang('Delete')).''; + $delete_link = utf8_encode($delete_link); + $actions .= $delete_link.' '; + } + } else { + $attempt_url = api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&id='.$results[$i]['exe_id'].'&id_session='.api_get_session_id().'&height=500&width=750'; + $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class' => 'ajax btn')); + $actions .= $attempt_link; + } + + if ($revised) { + $revised = Display::label(get_lang('Validated'), 'success'); + } else { + $revised = Display::label(get_lang('NotValidated'), 'info'); + } + + if ($is_allowedToEdit) { + $results[$i]['status'] = $revised; + $results[$i]['score'] = $score; + $results[$i]['lp'] = $lp_name; + $results[$i]['actions'] = $actions; + $list_info[] = $results[$i]; + } else { + $results[$i]['status'] = $revised; + $results[$i]['score'] = $score; + $results[$i]['actions'] = $actions; + $list_info[] = $results[$i]; + } + } + } + } + } else { + + $hpresults = getManyResultsXCol($hpsql, 6); + + // Print HotPotatoes test results. + if (is_array($hpresults)) { + + for ($i = 0; $i < sizeof($hpresults); $i++) { + $hp_title = GetQuizName($hpresults[$i][3], $documentPath); + if ($hp_title == '') { + $hp_title = basename($hpresults[$i][3]); + } + + $hp_date = api_get_local_time($hpresults[$i][6], null, date_default_timezone_get()); + $hp_result = round(($hpresults[$i][4] / ($hpresults[$i][5] != 0 ? $hpresults[$i][5] : 1)) * 100, 2).'% ('.$hpresults[$i][4].' / '.$hpresults[$i][5].')'; + if ($is_allowedToEdit) { + $list_info[] = array($hpresults[$i][0], $hpresults[$i][1], $hpresults[$i][2], '', $hp_title, '-', $hp_date, $hp_result, '-'); + } else { + $list_info[] = array($hp_title, '-', $hp_date, $hp_result, '-'); + } + } + } + } + + return $list_info; + } + + /** + * Converts the score with the exercise_max_note and exercise_min_score the platform settings + formats the results using the Text::float_format function + * + * @param float score + * @param float weight + * @param bool show porcentage or not + * @param bool use or not the platform settings + * @return string an html with the score modified + */ + public static function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true, $show_only_percentage = false) + { + if (is_null($score) && is_null($weight)) { + return '-'; + } + + $max_note = api_get_setting('exercise_max_score'); + $min_note = api_get_setting('exercise_min_score'); + + if ($use_platform_settings) { + if ($max_note != '' && $min_note != '') { + if (!empty($weight) && intval($weight) != 0) { + $score = $min_note + ($max_note - $min_note) * $score / $weight; + } else { + $score = $min_note; + } + $weight = $max_note; + } + } + $percentage = (100 * $score) / ($weight != 0 ? $weight : 1); + + //Formats values + $percentage = Text::float_format($percentage, 1); + $score = Text::float_format($score, 1); + $weight = Text::float_format($weight, 1); + + $html = null; + if ($show_percentage) { + $parent = '('.$score.' / '.$weight.')'; + $html = $percentage." % $parent"; + if ($show_only_percentage) { + $html = $percentage."% "; + } + } else { + $html = $score.' / '.$weight; + } + $html = Display::span($html, array('class' => 'score_exercise')); + return $html; + } + + public static function is_success_exercise_result($score, $weight, $pass_percentage) + { + $percentage = Text::float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1); + if (isset($pass_percentage) && !empty($pass_percentage)) { + if ($percentage >= $pass_percentage) { + return true; + } + } + return false; + } + + public static function show_success_message($score, $weight, $pass_percentage) + { + $res = ""; + if (self::is_pass_pourcentage_enabled($pass_percentage)) { + $is_success = self::is_success_exercise_result($score, $weight, $pass_percentage); + + $icon = ''; + if ($is_success) { + $html = get_lang('CongratulationsYouPassedTheTest'); + $icon = Display::return_icon('completed.png', get_lang('Correct'), array(), ICON_SIZE_MEDIUM); + } else { + //$html .= Display::return_message(get_lang('YouDidNotReachTheMinimumScore'), 'warning'); + $html = get_lang('YouDidNotReachTheMinimumScore'); + $icon = Display::return_icon('warning.png', get_lang('Wrong'), array(), ICON_SIZE_MEDIUM); + } + $html = Display::tag('h4', $html); + $html .= Display::tag('h5', $icon, array('style' => 'width:40px; padding:2px 10px 0px 0px')); + $res = $html; + } + return $res; + } + + /** + * Return true if pass_pourcentage activated (we use the pass pourcentage feature + * return false if pass_percentage = 0 (we don't use the pass pourcentage feature + * @param $in_pass_pourcentage + * @return boolean + * In this version, pass_percentage and show_success_message are disabled if + * pass_percentage is set to 0 + */ + public static function is_pass_pourcentage_enabled($in_pass_pourcentage) + { + return $in_pass_pourcentage > 0; + } + + /** + * Converts a numeric value in a percentage example 0.66666 to 66.67 % + * @param $value + * @return float Converted number + */ + public static function convert_to_percentage($value) + { + $return = '-'; + if ($value != '') { + $return = Text::float_format($value * 100, 1).' %'; + } + return $return; + } + + /** + * Converts a score/weight values to the platform scale + * @param float score + * @param float weight + * @return float the score rounded converted to the new range + */ + public static function convert_score($score, $weight) + { + $max_note = api_get_setting('exercise_max_score'); + $min_note = api_get_setting('exercise_min_score'); + + if ($score != '' && $weight != '') { + if ($max_note != '' && $min_note != '') { + if (!empty($weight)) { + $score = $min_note + ($max_note - $min_note) * $score / $weight; + } else { + $score = $min_note; + } + } + } + $score_rounded = Text::float_format($score, 1); + return $score_rounded; + } + + /** + * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session) + * @param array course data + * @param int session id + * @return array array with exercise data + */ + public static function get_all_exercises($course_info = null, $session_id = 0, $check_publication_dates = false) + { + $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); + $course_id = api_get_course_int_id(); + if (!empty($course_info) && !empty($course_info['real_id'])) { + $course_id = $course_info['real_id']; + } + + if ($session_id == -1) { + $session_id = 0; + } + + $now = api_get_utc_datetime(); + $time_conditions = ''; + + if ($check_publication_dates) { + $time_conditions = " AND ((start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now' ) OR "; //start and end are set + $time_conditions .= " (start_time <> '0000-00-00 00:00:00' AND start_time < '$now' AND end_time = '0000-00-00 00:00:00') OR "; // only start is set + $time_conditions .= " (start_time = '0000-00-00 00:00:00' AND end_time <> '0000-00-00 00:00:00' AND end_time > '$now') OR "; // only end is set + $time_conditions .= " (start_time = '0000-00-00 00:00:00' AND end_time = '0000-00-00 00:00:00')) "; // nothing is set + } + + if ($session_id == 0) { + $conditions = array('where' => array('active = ? AND session_id = ? AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order' => 'title'); + } else { + //All exercises + $conditions = array('where' => array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id = ? '.$time_conditions => array('1', $session_id, $course_id)), 'order' => 'title'); + } + $result = Database::select('*', $TBL_EXERCICES, $conditions); + return $result; + } + + /** + * Getting all active exercises from a course from a session (if a session_id is provided we will show all the exercises in the course + all exercises in the session) + * @param array course data + * @param int session id + * @param int course c_id + * @return array array with exercise data + * modified by Hubert Borderiou + */ + public static function get_all_exercises_for_course_id($course_info = null, $session_id = 0, $course_id = 0) + { + $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); + if ($session_id == -1) { + $session_id = 0; + } + if ($session_id == 0) { + $conditions = array('where' => array('active = ? AND session_id = ? AND c_id = ?' => array('1', $session_id, $course_id)), 'order' => 'title'); + } else { + //All exercises + $conditions = array('where' => array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id=?' => array('1', $session_id, $course_id)), 'order' => 'title'); + } + return Database::select('*', $TBL_EXERCICES, $conditions); + } + + /** + * Gets the position of the score based in a given score (result/weight) and the exe_id based in the user list + * (NO Exercises in LPs ) + * @param float user score to be compared *attention* $my_score = score/weight and not just the score + * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) + * @param int exercise id + * @param string course code + * @param int session id + * @return int the position of the user between his friends in a course (or course within a session) + */ + public static function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_id, $session_id = 0, $user_list = array(), $return_string = true) + { + //No score given we return + if (is_null($my_score)) { + return '-'; + } + if (empty($user_list)) { + return '-'; + } + + $best_attempts = array(); + foreach ($user_list as $user_data) { + $user_id = $user_data['user_id']; + $best_attempts[$user_id] = self::get_best_attempt_by_user($user_id, $exercise_id, $course_id, $session_id); + } + + if (empty($best_attempts)) { + return 1; + } else { + $position = 1; + $my_ranking = array(); + foreach ($best_attempts as $user_id => $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $my_ranking[$user_id] = $result['exe_result'] / $result['exe_weighting']; + } else { + $my_ranking[$user_id] = 0; + } + } + //if (!empty($my_ranking)) { + asort($my_ranking); + $position = count($my_ranking); + if (!empty($my_ranking)) { + foreach ($my_ranking as $user_id => $ranking) { + if ($my_score >= $ranking) { + if ($my_score == $ranking) { + $exe_id = $best_attempts[$user_id]['exe_id']; + if ($my_exe_id < $exe_id) { + $position--; + } + } else { + $position--; + } + } + } + } + //} + $return_value = array('position' => $position, 'count' => count($my_ranking)); + + if ($return_string) { + if (!empty($position) && !empty($my_ranking)) { + $return_value = $position.'/'.count($my_ranking); + } else { + $return_value = '-'; + } + } + return $return_value; + } + } + + /** + * Gets the position of the score based in a given score (result/weight) and the exe_id based in all attempts + * (NO Exercises in LPs ) old funcionality by attempt + * @param float user score to be compared attention => score/weight + * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) + * @param int exercise id + * @param int course id + * @param int session id + * @todo seems that is not used + * @return int the position of the user between his friends in a course (or course within a session) + */ + public static function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $courseId, $session_id = 0, $return_string = true) + { + if (empty($session_id)) { + $session_id = 0; + } + if (is_null($my_score)) { + return '-'; + } + $user_results = self::get_all_exercise_results($exercise_id, $courseId, $session_id, false); + $position_data = array(); + if (empty($user_results)) { + return 1; + } else { + $position = 1; + $my_ranking = array(); + foreach ($user_results as $result) { + //print_r($result); + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $my_ranking[$result['exe_id']] = $result['exe_result'] / $result['exe_weighting']; + } else { + $my_ranking[$result['exe_id']] = 0; + } + } + asort($my_ranking); + $position = count($my_ranking); + if (!empty($my_ranking)) { + foreach ($my_ranking as $exe_id => $ranking) { + if ($my_score >= $ranking) { + if ($my_score == $ranking) { + if ($my_exe_id < $exe_id) { + $position--; + } + } else { + $position--; + } + } + } + } + $return_value = array('position' => $position, 'count' => count($my_ranking)); + + if ($return_string) { + if (!empty($position) && !empty($my_ranking)) { + return $position.'/'.count($my_ranking); + } + } + return $return_value; + } + } + /* + * Get the best attempt in a exercise (NO Exercises in LPs ) + */ + + public static function get_best_attempt_in_course($exercise_id, $courseId, $session_id) + { + $user_results = self::get_all_exercise_results($exercise_id, $courseId, $session_id, false); + $best_score_data = array(); + $best_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + if ($score >= $best_score) { + $best_score = $score; + $best_score_data = $result; + } + } + } + } + return $best_score_data; + } + + /** + * Get the best score in a exercise (NO Exercises in LPs ) + * @param $user_id + * @param $exercise_id + * @param $courseId + * @param $session_id + * @return array + */ + public static function get_best_attempt_by_user($user_id, $exercise_id, $courseId, $session_id) + { + $user_results = self::get_all_exercise_results($exercise_id, $courseId, $session_id, false, $user_id); + $best_score_data = array(); + $best_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + if ($score >= $best_score) { + $best_score = $score; + $best_score_data = $result; + } + } + } + } + return $best_score_data; + } + + /** + * Get average score (NO Exercises in LPs ) + * @param int exercise id + * @param int course id + * @param int session id + * @return float Average score + */ + public static function get_average_score($exercise_id, $courseId, $session_id) + { + $user_results = self::get_all_exercise_results($exercise_id, $courseId, $session_id); + $avg_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + $avg_score +=$score; + } + } + $avg_score = Text::float_format($avg_score / count($user_results), 1); + } + return $avg_score; + } + + /** + * Get average score by score (NO Exercises in LPs ) + * @param int exercise id + * @param int course id + * @param int session id + * @return float Average score + */ + public static function get_average_score_by_course($courseId, $session_id) + { + $user_results = self::get_all_exercise_results_by_course($courseId, $session_id, false); + $avg_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + $avg_score +=$score; + } + } + //We asume that all exe_weighting + //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); + $avg_score = ($avg_score / count($user_results)); + } + return $avg_score; + } + + /** + * + * @param $user_id + * @param $courseId + * @param $session_id + * + * @return float|int + */ + public static function get_average_score_by_course_by_user($user_id, $courseId, $session_id) + { + $user_results = self::get_all_exercise_results_by_user($user_id, $courseId, $session_id); + $avg_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + $avg_score +=$score; + } + } + //We asume that all exe_weighting + //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); + $avg_score = ($avg_score / count($user_results)); + } + return $avg_score; + } + + /** + * Get average score by score (NO Exercises in LPs ) + * @param int exercise id + * @param int course id + * @param int session id + * + * @return float Best average score + */ + public static function get_best_average_score_by_exercise($exercise_id, $course_code, $session_id, $user_count) + { + $user_results = self::get_best_exercise_results_by_user($exercise_id, $course_code, $session_id); + $avg_score = 0; + if (!empty($user_results)) { + foreach ($user_results as $result) { + if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { + $score = $result['exe_result'] / $result['exe_weighting']; + $avg_score +=$score; + } + } + //We asume that all exe_weighting + //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); + //$avg_score = ($avg_score / count($user_results)); + if (!empty($user_count)) { + $avg_score = Text::float_format($avg_score / $user_count, 1) * 100; + } else { + $avg_score = 0; + } + } + return $avg_score; + } + + /** + * @param $course_code + * @param $session_id + * @return array + */ + public static function get_exercises_to_be_taken($course_code, $session_id) + { + $course_info = api_get_course_info($course_code); + $exercises = self::get_all_exercises($course_info, $session_id); + $result = array(); + $now = time() + 15 * 24 * 60 * 60; + foreach ($exercises as $exercise_item) { + if (isset($exercise_item['end_time']) && !empty($exercise_item['end_time']) && $exercise_item['end_time'] != '0000-00-00 00:00:00' && api_strtotime($exercise_item['end_time'], 'UTC') < $now) { + $result[] = $exercise_item; + } + } + return $result; + } + + /** + * Get student results (only in completed exercises) stats by question + * + * @param int question id + * @param int exercise id + * @param int course id + * @param int session id + * + * */ + public static function get_student_stats_by_question($question_id, $exercise_id, $courseId, $session_id) + { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + + $question_id = intval($question_id); + $exercise_id = intval($exercise_id); + $courseId = intval($courseId); + $session_id = intval($session_id); + + $sql = "SELECT MAX(marks) as max , MIN(marks) as min, AVG(marks) as average + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + WHERE exe_exo_id = $exercise_id AND + e.c_id = $courseId AND + a.c_id = $courseId + e.session_id = $session_id AND + question_id = $question_id AND status = '' LIMIT 1"; + $result = Database::query($sql); + $return = array(); + if ($result) { + $return = Database::fetch_array($result, 'ASSOC'); + } + return $return; + } + + /** + * @param int $question_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @return int + */ + public static function get_number_students_question_with_answer_count($question_id, $exercise_id, $courseId, $session_id) + { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + + $question_id = intval($question_id); + $exercise_id = intval($exercise_id); + $courseId = intval($courseId); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) INNER JOIN $course_user cu + ON cu.c_id = a.c_id AND cu.user_id = exe_user_id + WHERE exe_exo_id = $exercise_id AND + a.c_id = $courseId AND + e.session_id = $session_id AND + question_id = $question_id AND + answer <> '0' AND + cu.status = ".STUDENT." AND + relation_type <> 2 AND + e.status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + } + return $return; + } + + /** + * @param int $answer_id + * @param int $question_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @return int + */ + public static function get_number_students_answer_hotspot_count($answer_id, $question_id, $exercise_id, $courseId, $session_id) + { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_hotspot = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); + $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + + $question_id = intval($question_id); + $answer_id = intval($answer_id); + $exercise_id = intval($exercise_id); + $courseId = intval($courseId); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e + INNER JOIN $track_hotspot a ON (a.hotspot_exe_id = e.exe_id) + INNER JOIN $course_user cu + ON cu.c_id = a.c_id AND cu.user_id = exe_user_id + WHERE exe_exo_id = $exercise_id AND + a.c_id = $courseId AND + e.session_id = $session_id AND + hotspot_answer_id = $answer_id AND + hotspot_question_id = $question_id AND + cu.status = ".STUDENT." AND + hotspot_correct = 1 AND + relation_type <> 2 AND + e.status = ''"; + + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + } + return $return; + } + + /** + * + * @param int $answer_id + * @param int $question_id + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @param string $question_type + * @param null $correct_answer + * @param null $current_answer + * @return int + */ + public static function get_number_students_answer_count($answer_id, $question_id, $exercise_id, $courseId, $session_id, $question_type = null, $correct_answer = null, $current_answer = null) + { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + + $question_id = intval($question_id); + $answer_id = intval($answer_id); + $exercise_id = intval($exercise_id); + $courseId = intval($courseId); + $session_id = intval($session_id); + + switch ($question_type) { + case FILL_IN_BLANKS: + $answer_condition = ""; + $select_condition = " e.exe_id, answer "; + break; + case MATCHING: + default: + $answer_condition = " answer = $answer_id AND "; + $select_condition = " DISTINCT exe_user_id "; + } + + $sql = "SELECT $select_condition + FROM $track_exercises e + INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + INNER JOIN $course_user cu + ON cu.c_id = a.c_id AND cu.user_id = exe_user_id + WHERE exe_exo_id = $exercise_id AND + a.c_id = $courseId AND + e.session_id = $session_id AND + $answer_condition + question_id = $question_id AND + cu.status = ".STUDENT." AND + relation_type <> 2 AND + e.status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $good_answers = 0; + switch ($question_type) { + case FILL_IN_BLANKS: + while ($row = Database::fetch_array($result, 'ASSOC')) { + $fill_blank = self::check_fill_in_blanks($correct_answer, $row['answer']); + if (isset($fill_blank[$current_answer]) && $fill_blank[$current_answer] == 1) { + $good_answers++; + } + } + return $good_answers; + break; + case MATCHING: + default: + $return = Database::num_rows($result); + } + } + return $return; + } + + public static function check_fill_in_blanks($answer, $user_answer) + { + // the question is encoded like this + // [A] B [C] D [E] F::10,10,10@1 + // number 1 before the "@" means that is a switchable fill in blank question + // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 + // means that is a normal fill blank question + // first we explode the "::" + $pre_array = explode('::', $answer); + // is switchable fill blank or not + $last = count($pre_array) - 1; + $is_set_switchable = explode('@', $pre_array[$last]); + $switchable_answer_set = false; + if (isset($is_set_switchable[1]) && $is_set_switchable[1] == 1) { + $switchable_answer_set = true; + } + $answer = ''; + for ($k = 0; $k < $last; $k++) { + $answer .= $pre_array[$k]; + } + // splits weightings that are joined with a comma + $answerWeighting = explode(',', $is_set_switchable[0]); + + // we save the answer because it will be modified + //$temp = $answer; + $temp = $answer; + + $answer = ''; + $j = 0; + //initialise answer tags + $user_tags = $correct_tags = $real_text = array(); + // the loop will stop at the end of the text + while (1) { + // quits the loop if there are no more blanks (detect '[') + if (($pos = api_strpos($temp, '[')) === false) { + // adds the end of the text + $answer = $temp; + /* // Deprecated code + // TeX parsing - replacement of texcode tags + $answer = str_replace("{texcode}", $texstring, $answer); + */ + $real_text[] = $answer; + break; //no more "blanks", quit the loop + } + // adds the piece of text that is before the blank + //and ends with '[' into a general storage array + $real_text[] = api_substr($temp, 0, $pos + 1); + $answer .= api_substr($temp, 0, $pos + 1); + //take the string remaining (after the last "[" we found) + $temp = api_substr($temp, $pos + 1); + // quit the loop if there are no more blanks, and update $pos to the position of next ']' + if (($pos = api_strpos($temp, ']')) === false) { + // adds the end of the text + $answer .= $temp; + break; + } + + $str = $user_answer; + + preg_match_all('#\[([^[]*)\]#', $str, $arr); + $str = str_replace('\r\n', '', $str); + $choice = $arr[1]; + + $tmp = api_strrpos($choice[$j], ' / '); + $choice[$j] = api_substr($choice[$j], 0, $tmp); + $choice[$j] = trim($choice[$j]); + + //Needed to let characters ' and " to work as part of an answer + $choice[$j] = stripslashes($choice[$j]); + + $user_tags[] = api_strtolower($choice[$j]); + //put the contents of the [] answer tag into correct_tags[] + $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos)); + $j++; + $temp = api_substr($temp, $pos + 1); + } + + $answer = ''; + $real_correct_tags = $correct_tags; + $chosen_list = array(); + + $good_answer = array(); + + for ($i = 0; $i < count($real_correct_tags); $i++) { + if (!$switchable_answer_set) { + //needed to parse ' and " characters + $user_tags[$i] = stripslashes($user_tags[$i]); + if ($correct_tags[$i] == $user_tags[$i]) { + $good_answer[$correct_tags[$i]] = 1; + } elseif (!empty($user_tags[$i])) { + $good_answer[$correct_tags[$i]] = 0; + } else { + $good_answer[$correct_tags[$i]] = 0; + } + } else { + // switchable fill in the blanks + if (in_array($user_tags[$i], $correct_tags)) { + $correct_tags = array_diff($correct_tags, $chosen_list); + $good_answer[$correct_tags[$i]] = 1; + } elseif (!empty($user_tags[$i])) { + $good_answer[$correct_tags[$i]] = 0; + } else { + $good_answer[$correct_tags[$i]] = 0; + } + } + // adds the correct word, followed by ] to close the blank + $answer .= ' / '.$real_correct_tags[$i].']'; + if (isset($real_text[$i + 1])) { + $answer .= $real_text[$i + 1]; + } + } + return $good_answer; + } + + /** + * + * @param int $exercise_id + * @param int $courseId + * @param int $session_id + * @depracated seems not to be used + * @return int + */ + public static function get_number_students_finish_exercise($exercise_id, $courseId, $session_id) + { + $track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + + $exercise_id = intval($exercise_id); + $courseId = intval($courseId); + $session_id = intval($session_id); + + $sql = "SELECT DISTINCT exe_user_id + FROM $track_exercises e INNER JOIN $track_attempt a ON (a.exe_id = e.exe_id) + WHERE exe_exo_id = $exercise_id AND + a.c_id = $courseId AND + e.c_id = $courseId AND + e.session_id = $session_id AND + status = ''"; + $result = Database::query($sql); + $return = 0; + if ($result) { + $return = Database::num_rows($result); + } + return $return; + } + + /** + return the HTML code for a menu with students group + @input : $in_name : is the name and the id of the + */ + public static function displayGroupMenu($in_name, $in_default, $in_onchange = "") + { + // check the default value of option + $tabSelected = array($in_default => " selected='selected' "); + $res = ""; + $res .= ""; + return $res; + } + + /** + * Return a list of group for user with user_id=in_userid separated with in_separator + * @deprecated ? + */ + public static function displayGroupsForUser($in_separator, $in_userid) + { + $res = implode($in_separator, GroupManager::get_user_group_name($in_userid)); + if ($res == "") { + $res = "
    -
    "; + } + return $res; + } + + public static function create_chat_exercise_session($exe_id) + { + if (!isset($_SESSION['current_exercises'])) { + $_SESSION['current_exercises'] = array(); + } + $_SESSION['current_exercises'][$exe_id] = true; + } + + public static function delete_chat_exercise_session($exe_id) + { + if (isset($_SESSION['current_exercises'])) { + $_SESSION['current_exercises'][$exe_id] = false; + } + } + + /** + * Display the exercise results + * @param obj exercise obj + * @param int attempt id (exe_id) + * @param bool save users results (true) or just show the results (false) + */ + public static function display_question_list_by_attempt($objExercise, $exe_id, $save_user_result = false) + { + global $origin, $debug; + + //Getting attempt info + $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id); + + //Getting question list + $question_list = array(); + if (!empty($exercise_stat_info['data_tracking'])) { + $question_list = explode(',', $exercise_stat_info['data_tracking']); + } else { + //Try getting the question list only if save result is off + if ($save_user_result == false) { + $question_list = $objExercise->get_validated_question_list(); + } + error_log("Data tracking is empty! exe_id: $exe_id"); + } + + $counter = 1; + $total_score = 0; + $total_weight = 0; + + $exercise_content = null; + + //Hide results + $show_results = false; + $show_only_score = false; + + if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS) { + $show_results = true; + } + + if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) { + $show_only_score = true; + } + + if ($show_results || $show_only_score) { + $user_info = api_get_user_info($exercise_stat_info['exe_user_id']); + //Shows exercise header + echo $objExercise->show_exercise_result_header($user_info['complete_name'], api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration']); + } + + // Display text when test is finished #4074 and for LP #4227 + $end_of_message = $objExercise->selectTextWhenFinished(); + if (!empty($end_of_message)) { + Display::display_normal_message($end_of_message, false); + echo "
     
    "; + } + + $question_list_answers = array(); + $media_list = array(); + $category_list = array(); + + // Loop over all question to show results for each of them, one by one + if (!empty($question_list)) { + if ($debug) { + error_log('Looping question_list '.print_r($question_list, 1)); + } + + $media_questions = $objExercise->get_media_list(); + $media_is_activated = $objExercise->media_is_activated($media_questions); + + $medias_showed = array(); + + foreach ($question_list as $questionId) { + + // Creates a temporary Question object + $objQuestionTmp = Question::read($questionId); + + // This variable commes from exercise_submit_modal.php + ob_start(); + $hotspot_delineation_result = null; + + // We're inside *one* question. Go through each possible answer for this question + $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null, 'exercise_result', array(), $save_user_result, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result); + + if (empty($result)) { + continue; + } + + $total_score += $result['score']; + $total_weight += $result['weight']; + + $question_list_answers[] = array( + 'question' => $result['open_question'], + 'answer' => $result['open_answer'], + 'answer_type' => $result['answer_type'] + ); + + $my_total_score = $result['score']; + $my_total_weight = $result['weight']; + + // Category report + $category_was_added_for_this_test = false; + + if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) { + foreach ($objQuestionTmp->category_list as $category_id) { + if (!isset($category_list[$category_id])) { + $category_list[$category_id] = array(); + $category_list[$category_id]['score'] = 0; + $category_list[$category_id]['total'] = 0; + } + $category_list[$category_id]['score'] += $my_total_score; + $category_list[$category_id]['total'] += $my_total_weight; + $category_was_added_for_this_test = true; + } + } + + // No category for this question! + if ($category_was_added_for_this_test == false) { + if (!isset($category_list['none'])) { + $category_list['none'] = array(); + $category_list['none']['score'] = 0; + $category_list['none']['total'] = 0; + } + + $category_list['none']['score'] += $my_total_score; + $category_list['none']['total'] += $my_total_weight; + } + + if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) { + $my_total_score = 0; + } + + $comnt = null; + if ($show_results) { + $comnt = get_comments($exe_id, $questionId); + if (!empty($comnt)) { + echo ''.get_lang('Feedback').''; + echo '
    '.$comnt.'
    '; + } + } + + $score = array(); + if ($show_results) { + $score['result'] = get_lang('Score')." : ".self::show_score($my_total_score, $my_total_weight, false, true); + $score['pass'] = $my_total_score >= $my_total_weight ? true : false; + $score['score'] = $my_total_score; + $score['weight'] = $my_total_weight; + $score['comments'] = $comnt; + } + + $contents = ob_get_clean(); + + $question_content = '
    '; + + if ($show_results) { + + $show_media = false; + if ($objQuestionTmp->parent_id != 0 && !in_array($objQuestionTmp->parent_id, $media_list)) { + $show_media = true; + $media_list[] = $objQuestionTmp->parent_id; + } + + //Shows question title an description + $question_content .= $objQuestionTmp->return_header(null, $counter, $score, $show_media); + + // display question category, if any + $question_content .= Testcategory::getCategoryNamesForQuestion($questionId); + } + $counter++; + + $question_content .= $contents; + $question_content .= '
    '; + + $exercise_content .= $question_content; + } // end foreach() block that loops over all questions + } + + $total_score_text = null; + + if ($origin != 'learnpath') { + if ($show_results || $show_only_score) { + $total_score_text .= '
    '; + $total_score_text .= self::get_question_ribbon($objExercise, $total_score, $total_weight, true); + $total_score_text .= '
    '; + } + } + + if (!empty($category_list) && ($show_results || $show_only_score)) { + //Adding total + $category_list['total'] = array('score' => $total_score, 'total' => $total_weight); + echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list); + } + + echo $total_score_text; + echo $exercise_content; + + if (!$show_only_score) { + echo $total_score_text; + } + + if ($save_user_result) { + + // Tracking of results + $learnpath_id = $exercise_stat_info['orig_lp_id']; + $learnpath_item_id = $exercise_stat_info['orig_lp_item_id']; + $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id']; + + if (api_is_allowed_to_session_edit()) { + update_event_exercise($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array()); + } + + // Send notification .. + if (!api_is_allowed_to_edit(null, true)) { + $objExercise->send_notification_for_open_questions($question_list_answers, $origin, $exe_id); + $objExercise->send_notification_for_oral_questions($question_list_answers, $origin, $exe_id); + } + } + } + + /** + * @param $objExercise + * @param $score + * @param $weight + * @param bool $check_pass_percentage + * @return string + */ + public static function get_question_ribbon($objExercise, $score, $weight, $check_pass_percentage = false) + { + $ribbon = '
    '; + if ($check_pass_percentage) { + $is_success = self::is_success_exercise_result($score, $weight, $objExercise->selectPassPercentage()); + // Color the final test score if pass_percentage activated + $ribbon_total_success_or_error = ""; + if (self::is_pass_pourcentage_enabled($objExercise->selectPassPercentage())) { + if ($is_success) { + $ribbon_total_success_or_error = ' ribbon-total-success'; + } else { + $ribbon_total_success_or_error = ' ribbon-total-error'; + } + } + $ribbon .= '
    '; + } else { + $ribbon .= '
    '; + } + $ribbon .= '

    '.get_lang('YourTotalScore').": "; + $ribbon .= self::show_score($score, $weight, false, true); + $ribbon .= '

    '; + $ribbon .= '
    '; + if ($check_pass_percentage) { + $ribbon .= self::show_success_message($score, $weight, $objExercise->selectPassPercentage()); + } + $ribbon .= '
    '; + return $ribbon; + } +} \ No newline at end of file diff --git a/main/inc/lib/page.lib.php b/main/inc/lib/page.lib.php index 00ae1bb5b7..03ead39184 100644 --- a/main/inc/lib/page.lib.php +++ b/main/inc/lib/page.lib.php @@ -500,14 +500,13 @@ class PageController */ public function return_exercise_block($personal_course_list, $tpl) { - require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; $exercise_list = array(); if (!empty($personal_course_list)) { foreach ($personal_course_list as $course_item) { $course_code = $course_item['c']; $session_id = $course_item['id_session']; - $exercises = get_exercises_to_be_taken($course_code, $session_id); + $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id); foreach ($exercises as $exercise_item) { $exercise_item['course_code'] = $course_code; diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index dc78e86a50..394cf417f4 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -11,8 +11,6 @@ * Code */ -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; - /** * Class * @package chamilo.library @@ -2395,7 +2393,7 @@ class Tracking foreach ($course_list as $course_data) { - $exercise_list = get_all_exercises($course_data, $my_session_id); + $exercise_list = ExerciseLib::get_all_exercises($course_data, $my_session_id); foreach ($exercise_list as $exercise_data) { $exercise_obj = new Exercise($course_data['id']); @@ -2405,11 +2403,11 @@ class Tracking if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) { //if ($visible_return['value'] == true) { - $best_average = intval(get_best_average_score_by_exercise($exercise_data['id'], $course_data['code'], $my_session_id, $user_count)); + $best_average = intval(ExerciseLib::get_best_average_score_by_exercise($exercise_data['id'], $course_data['code'], $my_session_id, $user_count)); $exercise_graph_list[] = $best_average; $all_exercise_graph_list[] = $best_average; - $user_result_data = get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['real_id'], $my_session_id); + $user_result_data = ExerciseLib::get_best_attempt_by_user(api_get_user_id(), $exercise_data['id'], $course_data['real_id'], $my_session_id); $score = 0; if (!empty($user_result_data['exe_weighting']) && intval($user_result_data['exe_weighting']) != 0) { $score = intval($user_result_data['exe_result'] / $user_result_data['exe_weighting'] * 100); @@ -2419,7 +2417,7 @@ class Tracking $all_exercise_start_time[] = $time; $my_results[] = $score; if (count($exercise_list) <= 10) { - $title = Text::cut($course_data['title'], 30)." \n ".cut($exercise_data['title'], 30); + $title = Text::cut($course_data['title'], 30)." \n ".Text::cut($exercise_data['title'], 30); $exercise_graph_name_list[] = $title; $all_exercise_graph_name_list[] = $title; } else { @@ -2488,7 +2486,7 @@ class Tracking foreach ($course_list as $course_data) { //All exercises in the course @todo change for a real count - $exercises = get_all_exercises($course_data, $my_session_id); + $exercises = ExerciseLib::get_all_exercises($course_data, $my_session_id); $count_exercises = 0; if (is_array($exercises) && !empty($exercises)) { $count_exercises = count($exercises); @@ -2511,7 +2509,7 @@ class Tracking } //Average - $average = get_average_score_by_course($course_data['real_id'], $my_session_id); + $average = ExerciseLib::get_average_score_by_course($course_data['real_id'], $my_session_id); $all_exercises += $count_exercises; @@ -2535,7 +2533,7 @@ class Tracking $html .= Display::tag('td', $all_unanswered_exercises_by_user); //$html .= Display::tag('td', $all_done_exercise); - $html .= Display::tag('td', convert_to_percentage($all_average)); + $html .= Display::tag('td', ExerciseLib::convert_to_percentage($all_average)); if (isset($_GET['session_id']) && $my_session_id == $_GET['session_id']) { $icon = Display::url(Display::return_icon('2rightarrow_na.gif', get_lang('Details')), '?session_id='.$my_session_id); @@ -2580,7 +2578,7 @@ class Tracking $course_title = $course_data['title']; //All exercises in the course @todo change for a real count - $exercises = get_all_exercises($course_data, $session_id_from_get); + $exercises = ExerciseLib::get_all_exercises($course_data, $session_id_from_get); $count_exercises = 0; if (!empty($exercises)) { $count_exercises = count($exercises); @@ -2600,8 +2598,8 @@ class Tracking $unanswered_exercises = $count_exercises - $answered_exercises; //Average - $average = get_average_score_by_course($courseId, $session_id_from_get); - $my_average = get_average_score_by_course_by_user(api_get_user_id(), $courseId, $session_id_from_get); + $average = ExerciseLib::get_average_score_by_course($courseId, $session_id_from_get); + $my_average = ExerciseLib::get_average_score_by_course_by_user(api_get_user_id(), $courseId, $session_id_from_get); $stats_array[$course_code] = array( 'exercises' => $count_exercises, @@ -2630,9 +2628,9 @@ class Tracking $html .= Display::tag('td', $stats_array[$course_code]['exercises']); $html .= Display::tag('td', $stats_array[$course_code]['unanswered_exercises_by_user']); //$html .= Display::tag('td', $stats_array[$course_code]['done_exercises']); - $html .= Display::tag('td', convert_to_percentage($stats_array[$course_code]['my_average'])); + $html .= Display::tag('td', ExerciseLib::convert_to_percentage($stats_array[$course_code]['my_average'])); - $html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '('.convert_to_percentage($stats_array[$course_code]['average']).')'); + $html .= Display::tag('td', $stats_array[$course_code]['average'] == 0 ? '-' : '('.ExerciseLib::convert_to_percentage($stats_array[$course_code]['average']).')'); $html .= Display::tag('td', $time, array('align' => 'center')); if (is_numeric($progress)) { @@ -2711,7 +2709,7 @@ class Tracking } // Show exercise results of invisible exercises? see BT#4091 - $exercise_list = get_all_exercises($course_info, $session_id, false); + $exercise_list = ExerciseLib::get_all_exercises($course_info, $session_id, false); $to_graph_exercise_result = array(); @@ -2749,14 +2747,14 @@ class Tracking $graph = $normal_graph = null; //Getting best results - $best_score_data = get_best_attempt_in_course($exerciseId, $course_info['real_id'], $session_id); + $best_score_data = ExerciseLib::get_best_attempt_in_course($exerciseId, $course_info['real_id'], $session_id); if (!empty($best_score_data)) { - $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); + $best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); } if ($attempts > 0) { - $exercise_stat = get_best_attempt_by_user(api_get_user_id(), $exerciseId, $course_info['real_id'], $session_id); + $exercise_stat = ExerciseLib::get_best_attempt_by_user(api_get_user_id(), $exerciseId, $course_info['real_id'], $session_id); if (!empty($exercise_stat)) { //Always getting the BEST attempt @@ -2765,13 +2763,13 @@ class Tracking $exe_id = $exercise_stat['exe_id']; $latest_attempt_url .= api_get_path(WEB_CODE_PATH).'exercice/result.php?id='.$exe_id.'&cidReq='.$course_info['code'].'&show_headers=1&id_session='.$session_id; - $percentage_score_result = Display::url(show_score($score, $weighting), $latest_attempt_url); + $percentage_score_result = Display::url(ExerciseLib::show_score($score, $weighting), $latest_attempt_url); $my_score = 0; if (!empty($weighting) && intval($weighting) != 0) { $my_score = $score / $weighting; } //@todo this function slows the page - $position = get_exercise_result_ranking($my_score, $exe_id, $exerciseId, $course_info['real_id'], $session_id, $user_list); + $position = ExerciseLib::get_exercise_result_ranking($my_score, $exe_id, $exerciseId, $course_info['real_id'], $session_id, $user_list); $graph = self::generate_exercise_result_thumbnail_graph($to_graph_exercise_result[$exerciseId]); $normal_graph = self::generate_exercise_result_graph($to_graph_exercise_result[$exerciseId]); @@ -3733,7 +3731,7 @@ class TrackingCourseLog $courseInfo = api_get_course_info($course_code); $courseId = $courseInfo['real_id']; $total_surveys = 0; - $total_exercises = get_all_exercises($courseInfo, $session_id); + $total_exercises = ExerciseLib::get_all_exercises($courseInfo, $session_id); if (empty($session_id)) { $survey_user_list = array(); diff --git a/main/newscorm/learnpath_functions.inc.php b/main/newscorm/learnpath_functions.inc.php index d8660c64f1..00edbaf713 100644 --- a/main/newscorm/learnpath_functions.inc.php +++ b/main/newscorm/learnpath_functions.inc.php @@ -1279,8 +1279,6 @@ function export_exercise($item_id) require_once '../exercice/exercise.class.php'; require_once '../exercice/question.class.php'; require_once '../exercice/answer.class.php'; - require_once '../exercice/exercise.lib.php'; - $TBL_EXERCISES = Database :: get_course_table(TABLE_QUIZ_TEST); /* Clears the exercise session */ @@ -1420,7 +1418,7 @@ function export_exercise($item_id) echo $s = "".get_lang('Question')." "; // Call the showQuestion() function from exercise.lib.php. This basically displays the question in a table. $question_obj = Question::read($questionId); - $test .= showQuestion($question_obj, false, 'export', $i); + $test .= ExerciseLib::showQuestion($question_obj, false, 'export', $i); } // end foreach() @@ -1454,7 +1452,6 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false include_once $libp.'exercice/exercise.class.php'; include_once $libp.'question.class.php'; include_once $libp.'answer.class.php'; - include_once $libp.'exercise.lib.php'; $langLasting = ''; //avoid code parser warning include_once $libp.'lang/english/announcements.inc.php'; //this line is here only for $langPubl in announcements diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 1d83466d1c..aaf7a24ecc 100644 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -346,14 +346,14 @@ if (is_array($list) && count($list) > 0) { if ($maxscore == 0) { $view_score = $score; } else { - $view_score = show_score($score, $maxscore, false); + $view_score = ExerciseLib::show_score($score, $maxscore, false); } break; case 'document': - $view_score = ($score == 0 ? '/' : show_score($score, $maxscore, false)); + $view_score = ($score == 0 ? '/' : ExerciseLib::show_score($score, $maxscore, false)); break; default: - $view_score = show_score($score, $maxscore, false); + $view_score = ExerciseLib::show_score($score, $maxscore, false); break; } } @@ -683,7 +683,7 @@ if (is_array($list) && count($list) > 0) { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { - $output .= show_score($score, $maxscore, false); + $output .= ExerciseLib::show_score($score, $maxscore, false); } } else { $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore)); @@ -791,12 +791,12 @@ if (is_array($list) && count($list) > 0) { } else { // Show only float when need it if ($my_score == 0) { - $view_score = show_score(0, $my_maxscore, false); + $view_score = ExerciseLib::show_score(0, $my_maxscore, false); } else { if ($my_maxscore == 0) { $view_score = $my_score; } else { - $view_score = show_score($my_score, $my_maxscore, false); + $view_score = ExerciseLib::show_score($my_score, $my_maxscore, false); } } } diff --git a/main/session/index.php b/main/session/index.php index c5d68ff08a..4e7f1da687 100644 --- a/main/session/index.php +++ b/main/session/index.php @@ -16,7 +16,6 @@ $language_file = array('learnpath', 'courses', 'index','tracking','exercice', 'a $cidReset = true; require_once '../inc/global.inc.php'; -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php'; api_block_anonymous_users(); // Only users who are logged in can proceed. @@ -69,7 +68,7 @@ if (!empty($new_session_list)) { $course_info = api_get_course_info_by_id($my_course['id']); //Getting all exercises from the current course - $exercise_list = get_all_exercises($course_info, $my_session_id, true); + $exercise_list = ExerciseLib::get_all_exercises($course_info, $my_session_id, true); $course['name'] = $course_info['name']; $course['id'] = $course_info['real_id']; @@ -109,7 +108,7 @@ if (!empty($course_list)) { $lp_list = $list->get_flat_list(); $lp_count = count($lp_list); $course_info = api_get_course_info($course_data['code']); - $exercise_count = count(get_all_exercises($course_info, $session_id, true)); + $exercise_count = count(ExerciseLib::get_all_exercises($course_info, $session_id, true)); $max_mutation_date = ''; @@ -203,11 +202,11 @@ foreach($final_array as $session_data) { if (!empty($course_data['exercises'])) { //Exercises foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) { - $best_score_data = get_best_attempt_in_course($my_exercise_id, $course_data['id'], $session_id); + $best_score_data = ExerciseLib::get_best_attempt_in_course($my_exercise_id, $course_data['id'], $session_id); $best_score = ''; if (!empty($best_score_data)) { - $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); + $best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); } //Exercise results $counter = 1; @@ -222,12 +221,12 @@ foreach($final_array as $session_data) { } if (!empty($result_list)) { foreach ($result_list as $exercise_result) { - $platform_score = show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']); + $platform_score = ExerciseLib::show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']); $my_score = 0; if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) { $my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting']; } - $position = get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $course_data['id'], $session_id, $user_list); + $position = ExerciseLib::get_exercise_result_ranking($my_score, $exercise_result['exe_id'], $my_exercise_id, $course_data['id'], $session_id, $user_list); //$exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/exercice.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id&show=result", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link')); $exercise_info->exercise = Display::url($exercise_info->exercise, api_get_path(WEB_CODE_PATH)."exercice/result.php?cidReq=$my_course_code&id={$exercise_result['exe_id']}&id_session=$session_id&show_headers=1", array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link')); diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index 367bb3ff58..f37c2b6230 100644 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -49,7 +49,6 @@ require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php'; require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php'; require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php'; require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php'; -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; // Starting the output buffering when we are exporting the information. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false; diff --git a/main/tracking/course_log_resources.php b/main/tracking/course_log_resources.php index 3257a39e33..53b04ee327 100644 --- a/main/tracking/course_log_resources.php +++ b/main/tracking/course_log_resources.php @@ -49,7 +49,6 @@ require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php'; require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php'; require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php'; require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php'; -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; // Starting the output buffering when we are exporting the information. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false; diff --git a/main/tracking/course_log_tools.php b/main/tracking/course_log_tools.php index 5b2897cc1a..2738f0a345 100644 --- a/main/tracking/course_log_tools.php +++ b/main/tracking/course_log_tools.php @@ -44,7 +44,6 @@ require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php'; require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php'; require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php'; require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php'; -require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php'; $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST); diff --git a/main/tracking/course_session_report.php b/main/tracking/course_session_report.php index 455032540b..86e0294641 100644 --- a/main/tracking/course_session_report.php +++ b/main/tracking/course_session_report.php @@ -130,7 +130,7 @@ foreach ($course_list as $current_course ) { // Looping LPs foreach ($lp_list as $lp_id =>$lp) { - $exercise_list = get_all_exercises_from_lp($lp_id, $course_info['real_id']); + $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']); //Looping Chamilo Exercises in LP foreach ($exercise_list as $exercise) { $exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['real_id'], $session_id); diff --git a/main/tracking/lp_results_by_user.php b/main/tracking/lp_results_by_user.php index 8b5b567133..42068cbc4e 100644 --- a/main/tracking/lp_results_by_user.php +++ b/main/tracking/lp_results_by_user.php @@ -133,7 +133,7 @@ foreach($course_list as $current_course ) { // Looping LPs $lps = array(); foreach ($lp_list as $lp_id =>$lp) { - $exercise_list = get_all_exercises_from_lp($lp_id, $course_info['real_id']); + $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']); $attempt_result = array(); //Looping Chamilo Exercises in LP foreach ($exercise_list as $exercise) { diff --git a/main/tracking/question_course_report.php b/main/tracking/question_course_report.php index ede6766b01..e6db97dc84 100644 --- a/main/tracking/question_course_report.php +++ b/main/tracking/question_course_report.php @@ -91,7 +91,7 @@ if (!empty($course_info)) { $_course = $course_info; $main_question_list = array(); foreach ($lp_list as $lp_id =>$lp) { - $exercise_list = get_all_exercises_from_lp($lp_id, $course_info['real_id']); + $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']); foreach ($exercise_list as $exercise) { $my_exercise = new Exercise(); diff --git a/tests/datafiller/fill_exe.php b/tests/datafiller/fill_exe.php index 41db447676..ca22adf7b5 100644 --- a/tests/datafiller/fill_exe.php +++ b/tests/datafiller/fill_exe.php @@ -25,7 +25,6 @@ function fill_exe() { require_once $lib.'exercice/exercise.class.php'; require_once $lib.'exercice/question.class.php'; require_once $lib.'exercice/answer.class.php'; - require_once $lib.'exercice/exercise.lib.php'; foreach ($courses as $i => $course) { $res = 0; //first check that the first item doesn't exist already @@ -57,7 +56,7 @@ function fill_exe() { while ($qi < $qc) { foreach ($qst as $q) { error_log('Created '.$qi.' questions'); - $question = Question::getInstance($q['type']); + $question = Question::getInstance($q['type']); $question->id = 0; $question->question = $q['title'].' '.$qi; $question->description = $q['desc']; @@ -75,7 +74,7 @@ function fill_exe() { $qi++; } } - } + } } } } diff --git a/tests/test_manager.inc.php b/tests/test_manager.inc.php index 7fe041f4a0..0c19062ab6 100755 --- a/tests/test_manager.inc.php +++ b/tests/test_manager.inc.php @@ -85,7 +85,6 @@ require_once $libdir.'geometry.lib.php'; ob_end_clean(); /**Problem with this file to test objects*/ -//require_once $maindir.'exercice/exercise.lib.php'; class TestManager { diff --git a/vendor/autoload.php b/vendor/autoload.php index 560564f915..00fcc4cfba 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit9686e641bdeddab21fbf49db8b6b38e6::getLoader(); +return ComposerAutoloaderInit0fa381a041b9622c3d1748381ff09118::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index fcb8c2fa1b..b52b140fe6 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -164,6 +164,7 @@ return array( 'EventsDispatcher' => $baseDir . '/main/inc/lib/events_dispatcher.class.php', 'EventsMail' => $baseDir . '/main/inc/lib/events_email.class.php', 'Exercise' => $baseDir . '/main/exercice/exercise.class.php', + 'ExerciseLib' => $baseDir . '/main/inc/lib/exercise.lib.php', 'ExerciseLink' => $baseDir . '/main/gradebook/lib/be/exerciselink.class.php', 'ExerciseResult' => $baseDir . '/main/exercice/exercise_result.class.php', 'ExerciseShowFunctions' => $baseDir . '/main/inc/lib/exercise_show_functions.lib.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 28f27eb7f5..a68fa8131f 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php generated by Composer -class ComposerAutoloaderInit9686e641bdeddab21fbf49db8b6b38e6 +class ComposerAutoloaderInit0fa381a041b9622c3d1748381ff09118 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit9686e641bdeddab21fbf49db8b6b38e6 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit9686e641bdeddab21fbf49db8b6b38e6', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit0fa381a041b9622c3d1748381ff09118', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit9686e641bdeddab21fbf49db8b6b38e6', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit0fa381a041b9622c3d1748381ff09118', 'loadClassLoader')); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir);