diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 8524258d76..0596b86447 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -316,13 +316,14 @@ class TestCategory * return : array of category id (integer) * hubert.borderiou 07-04-2011 * @param int $exerciseId + * @param int $courseId * * @return array */ - public static function getListOfCategoriesIDForTest($exerciseId) + public static function getListOfCategoriesIDForTest($exerciseId, $courseId = 0) { // parcourir les questions d'un test, recup les categories uniques dans un tableau - $exercise = new Exercise(); + $exercise = new Exercise($courseId); $exercise->read($exerciseId, false); $categoriesInExercise = $exercise->getQuestionWithCategories(); // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? @@ -337,14 +338,14 @@ class TestCategory } /** - * @param Exercise $exercise_obj + * @param Exercise $exercise * @return array */ - public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj) + public static function getListOfCategoriesIDForTestObject(Exercise $exercise) { // parcourir les questions d'un test, recup les categories uniques dans un tableau $categories_in_exercise = array(); - $question_list = $exercise_obj->getQuestionOrderedListByName(); + $question_list = $exercise->getQuestionOrderedListByName(); // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? foreach ($question_list as $questionInfo) { @@ -397,13 +398,13 @@ class TestCategory } /** - * @param Exercise $exercise_obj + * @param Exercise $exercise * @return array */ - public static function getListOfCategoriesForTest(Exercise $exercise_obj) + public static function getListOfCategoriesForTest(Exercise $exercise) { $result = array(); - $categories = self::getListOfCategoriesIDForTestObject($exercise_obj); + $categories = self::getListOfCategoriesIDForTestObject($exercise); foreach ($categories as $cat_id) { $cat = new TestCategory(); $cat = (array) $cat->getCategory($cat_id); @@ -1011,19 +1012,19 @@ class TestCategory /** * Returns the category form. - * @param Exercise $exercise_obj + * @param Exercise $exercise * @return string */ - public function returnCategoryForm(Exercise $exercise_obj) + public function returnCategoryForm(Exercise $exercise) { - $categories = $this->getListOfCategoriesForTest($exercise_obj); - $saved_categories = $exercise_obj->get_categories_in_exercise(); + $categories = $this->getListOfCategoriesForTest($exercise); + $saved_categories = $exercise->get_categories_in_exercise(); $return = null; if (!empty($categories)) { - $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory(); - $exercise_obj->setCategoriesGrouping(true); - $real_question_count = count($exercise_obj->getQuestionList()); + $nbQuestionsTotal = $exercise->getNumberQuestionExerciseCategory(); + $exercise->setCategoriesGrouping(true); + $real_question_count = count($exercise->getQuestionList()); $warning = null; if ($nbQuestionsTotal != $real_question_count) { diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index c788b7cc21..9d67ec2ddc 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -3475,7 +3475,7 @@ class Exercise } // Construction of the Answer object - $objAnswerTmp = new Answer($questionId); + $objAnswerTmp = new Answer($questionId, $course_id); $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); if ($debug) { diff --git a/main/exercise/question.class.php b/main/exercise/question.class.php index 3a91601404..2061a3a406 100755 --- a/main/exercise/question.class.php +++ b/main/exercise/question.class.php @@ -159,7 +159,7 @@ abstract class Question $objQuestion->extra = $object->extra; $objQuestion->course = $course_info; $objQuestion->feedback = isset($object->feedback) ? $object->feedback : ''; - $objQuestion->category = TestCategory::getCategoryForQuestion($id); + $objQuestion->category = TestCategory::getCategoryForQuestion($id, $course_id); $tblQuiz = Database::get_course_table(TABLE_QUIZ_TEST); $sql = "SELECT DISTINCT q.exercice_id diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 4a1485b758..fb1d1caa65 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -33,6 +33,7 @@ if (!in_array( $action, array( 'get_exercise_results', + 'get_exercise_results_report', 'get_work_student_list_overview', 'get_hotpotatoes_exercise_results', 'get_work_teacher', @@ -520,6 +521,19 @@ switch ($action) { $whereCondition ); break; + case 'get_exercise_results_report': + $exerciseId = $_REQUEST['exercise_id']; + $courseId = $_REQUEST['course_id']; + $startDate = Database::escape_string($_REQUEST['start_date']); + $courseInfo = api_get_course_info_by_id($courseId); + $whereCondition .= " AND exe_date > '$startDate' "; + $count = ExerciseLib::get_count_exam_results( + $exerciseId, + $whereCondition, + $courseInfo['code'], + true + ); + break; case 'get_hotpotatoes_exercise_results': $hotpot_path = $_REQUEST['path']; $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path); @@ -1147,6 +1161,43 @@ switch ($action) { $whereCondition ); break; + case 'get_exercise_results_report': + api_protect_admin_script(); + + // Used inside ExerciseLib::get_exam_results_data() + $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document"; + + $columns = array( + 'firstname', + 'lastname', + 'username', + 'session', + 'start_date', + 'exe_date', + 'score' + ); + $categoryList = TestCategory::getListOfCategoriesIDForTest($exerciseId, $courseId); + if (!empty($categoryList)) { + foreach ($categoryList as $categoryInfo) { + $columns[] = 'category_'.$categoryInfo['id']; + } + } + + $columns[] = 'actions'; + + $result = ExerciseLib::get_exam_results_data( + $start, + $limit, + $sidx, + $sord, + $exerciseId, + $whereCondition, + false, + $courseInfo['code'], + true, + true + ); + break; case 'get_hotpotatoes_exercise_results': $course = api_get_course_info(); $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document"; @@ -1966,6 +2017,7 @@ $allowed_actions = array( 'get_session_progress', 'get_exercise_progress', 'get_exercise_results', + 'get_exercise_results_report', 'get_work_student_list_overview', 'get_hotpotatoes_exercise_results', 'get_work_teacher', diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 21668f62bb..8c69256ffb 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1508,9 +1508,12 @@ HOTSPOT; * Gets count of exam results * @param int $exerciseId * @param array $conditions + * @param string $courseCode + * @param bool $showSession + * * @return array */ - public static function get_count_exam_results($exerciseId, $conditions) + public static function get_count_exam_results($exerciseId, $conditions, $courseCode = '', $showSession = false) { $count = self::get_exam_results_data( null, @@ -1519,8 +1522,11 @@ HOTSPOT; null, $exerciseId, $conditions, - true + true, + $courseCode, + $showSession ); + return $count; } @@ -1680,7 +1686,9 @@ HOTSPOT; $exercise_id, $extra_where_conditions = null, $get_count = false, - $courseCode = null + $courseCode = null, + $showSessionField = false, + $showExerciseCategories = false ) { //@todo replace all this globals global $documentPath, $filter; @@ -1688,9 +1696,7 @@ HOTSPOT; $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode; $courseInfo = api_get_course_info($courseCode); $course_id = $courseInfo['real_id']; - $sessionId = api_get_session_id(); $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh() || api_is_student_boss(); - $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); @@ -1698,10 +1704,14 @@ HOTSPOT; $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); - - $session_id_and = ' AND te.session_id = '.$sessionId.' '; + $sessionId = api_get_session_id(); + $session_id_and = ''; + $sessionCondition = ''; + if (!$showSessionField) { + $session_id_and = " AND te.session_id = '.$sessionId "; + $sessionCondition = " AND ttte.session_id = $sessionId"; + } $exercise_id = intval($exercise_id); - $exercise_where = ''; if (!empty($exercise_id)) { $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.' '; @@ -1717,12 +1727,13 @@ HOTSPOT; $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 + FROM $TBL_TRACK_EXERCICES ttte + LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr ON (ttte.exe_id = tr.exe_id) WHERE c_id = $course_id AND - exe_exo_id = $exercise_id AND - ttte.session_id = ".$sessionId." + exe_exo_id = $exercise_id + $sessionCondition )"; if ($is_allowedToEdit) { @@ -1841,6 +1852,7 @@ HOTSPOT; te.exe_weighting, te.exe_date, te.exe_id, + te.session_id, email as exemail, te.start_date, ce.expired_time, @@ -1947,7 +1959,6 @@ HOTSPOT; $lp_list_obj = new LearnpathList(api_get_user_id()); $lp_list = $lp_list_obj->get_flat_list(); - $oldIds = array_column($lp_list, 'lp_old_id', 'iid'); if (is_array($results)) { @@ -2108,12 +2119,12 @@ HOTSPOT; break; case 2: //finished but not marked as such $actions .= ''. + .api_get_cidreq() + .'&exerciseId=' + .$exercise_id + .'&a=close&id=' + .$id + .'">'. Display:: return_icon( 'lock.png', get_lang('MarkAttemptAsClosed'), @@ -2127,13 +2138,12 @@ HOTSPOT; ); break; case 3: //still ongoing - $actions .= "". - Display:: return_icon( - 'clock.png', - get_lang('AttemptStillOngoingPleaseWait'), - array(), - ICON_SIZE_SMALL - ); + $actions .= Display:: return_icon( + 'clock.png', + get_lang('AttemptStillOngoingPleaseWait'), + array(), + ICON_SIZE_SMALL + ); $actions .= ''; $revisedLabel = Display::label( get_lang('Ongoing'), @@ -2158,9 +2168,8 @@ HOTSPOT; false ); $actions .= '' - . Display::return_icon('info.png', $ip) - .''; - + .Display::return_icon('info.png', $ip) + .''; $recalculateUrl = api_get_path(WEB_CODE_PATH).'exercise/recalculate.php?'. api_get_cidreq().'&'. @@ -2180,7 +2189,8 @@ HOTSPOT; ] ); - $delete_link = '"+cellvalue+""; + }'; + $tableId = 'results'; + ?> + + $(function() { + jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true}); + jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{ + caption:"", + title:"' . get_lang('ExportExcel').'", + onClickButton : function () { + jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"}); + } + }); + });'; + + echo Display::grid_html('results'); +} + +Display::display_footer(); +