From fc3508ec07069da7e41e183e490cc60db15e8dcf Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 6 Oct 2014 15:03:37 +0200 Subject: [PATCH] Adding $_configuration['show_official_code_exercise_result_list'] see BT#8746 --- main/exercice/exercise.class.php | 22 ++++++- main/exercice/exercise.lib.php | 14 ++--- main/exercice/exercise_report.php | 12 ++++ main/exercice/exercise_result.class.php | 83 +++++++++++++++---------- main/exercice/exercise_show.php | 29 +++++---- main/inc/ajax/model.ajax.php | 4 ++ main/inc/lib/main_api.lib.php | 1 + main/install/configuration.dist.php | 2 + 8 files changed, 109 insertions(+), 58 deletions(-) diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 7891454d619..493cc0f89ca 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -3659,11 +3659,25 @@ function send_notification_for_oral_questions($question_list_answers, $origin, $ } } - function show_exercise_result_header($user_data, $start_date = null, $duration = null) { + /** + * @param array $user_data result of api_get_user_info() + * @param null $start_date + * @param null $duration + * @return string + */ + public function show_exercise_result_header($user_data, $start_date = null, $duration = null) + { $array = array(); if (!empty($user_data)) { - $array[] = array('title' => get_lang("User"), 'content' => $user_data); + $array[] = array('title' => get_lang("Name"), 'content' => $user_data['complete_name']); + $array[] = array('title' => get_lang("Username"), 'content' => $user_data['username']); + if (!empty($user_data['official_code'])) { + $array[] = array( + 'title' => get_lang("OfficialCode"), + 'content' => $user_data['official_code'] + ); + } } // Description can be very long and is generally meant to explain // rules *before* the exam. Leaving here to make display easier if @@ -3681,7 +3695,9 @@ function show_exercise_result_header($user_data, $start_date = null, $duration = $array[] = array('title' => get_lang("Duration"), 'content' => $duration); } - $html = Display::page_header(Display::return_icon('quiz_big.png', get_lang('Result')).' '.$this->exercise.' : '.get_lang('Result')); + $html = Display::page_header( + Display::return_icon('quiz_big.png', get_lang('Result')).' '.$this->exercise.' : '.get_lang('Result') + ); $html .= Display::description($array); return $html; } diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 91a61d0fde0..3428222ebdb 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -999,8 +999,8 @@ function get_exam_results_hotpotatoes_data($in_from, $in_number_of_items, $in_co * 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) { - +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; @@ -1099,12 +1099,11 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex $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 + SELECT u.user_id, firstname, lastname, email, username, ' ' as group_name, '' as group_id, official_code 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 "; @@ -1116,6 +1115,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex $sql_select = "SELECT DISTINCT user_id, $first_and_last_name, + official_code, ce.title, username, te.exe_result, @@ -1154,6 +1154,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex $hpsql_select = "SELECT $first_and_last_name , username, + official_code, tth.exe_name, tth.exe_result , tth.exe_weighting, @@ -1348,7 +1349,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex } } } else { - //echo $hpsql; var_dump($hpsql); $hpresults = getManyResultsXCol($hpsql, 6); // Print HotPotatoes test results. @@ -2325,10 +2325,10 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu } if ($show_results || $show_only_score) { - $user_info = api_get_user_info($exercise_stat_info['exe_user_id']); + $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'], + $user_info, api_convert_and_format_date($exercise_stat_info['start_date'], DATE_TIME_FORMAT_LONG), $exercise_stat_info['duration'] ); diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 1edddc09427..ddab02fe254 100755 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -378,9 +378,12 @@ $group_parameters = implode(';', $group_parameters); } +$officialCodeInList = api_get_configuration_value('show_official_code_exercise_result_list'); + if ($is_allowedToEdit || $is_tutor) { //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'), @@ -395,6 +398,10 @@ get_lang('Actions') ); + if ($officialCodeInList == true) { + $columns = array_merge(array(get_lang('OfficialCode')), $columns); + } + //Column config $column_model = array( array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'), @@ -422,6 +429,11 @@ array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false') ); + if ($officialCodeInList == true) { + $officialCodeRow = array('name' => 'official_code', 'index' => 'official_code', 'width' => '50', 'align' => 'left', 'search' => 'true'); + $column_model = array_merge(array($officialCodeRow), $column_model); + } + $action_links = ' // add username as title in lastname filed - ref 4226 function action_formatter(cellvalue, options, rowObject) { diff --git a/main/exercice/exercise_result.class.php b/main/exercice/exercise_result.class.php index 3cc9cbe7e72..0db083ef45a 100755 --- a/main/exercice/exercise_result.class.php +++ b/main/exercice/exercise_result.class.php @@ -1,21 +1,13 @@ -1"; $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", + official_code, email, tth.exe_name, tth.exe_result, @@ -142,6 +138,7 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; // get only this user's results $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", + official_code, ce.title as extitle, te.exe_result as exresult, te.exe_weighting as exweight, @@ -155,22 +152,24 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe ce.results_disabled as exdisabled, te.orig_lp_id as orig_lp_id, tlm.name as lp_name - FROM $TBL_EXERCISES AS ce - INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) + FROM $TBL_EXERCISES AS ce + INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) LEFT JOIN $TBL_TABLE_LP_MAIN AS tlm ON tlm.id = te.orig_lp_id AND tlm.c_id = ce.c_id - WHERE ce.c_id = $course_id AND - te.status != 'incomplete' AND - te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND - ce.active <>-1 AND + WHERE + ce.c_id = $course_id AND + te.status != 'incomplete' AND + te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND + ce.active <>-1 AND ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC"; $hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date - FROM $TBL_TRACK_HOTPOTATOES - WHERE exe_user_id = '" . $user_id . "' AND - exe_cours_id = '" . Database :: escape_string($cid) . "' AND - tth.exe_name = '$hotpotato_name' - ORDER BY exe_cours_id ASC, exe_date DESC"; + FROM $TBL_TRACK_HOTPOTATOES + WHERE + exe_user_id = '" . $user_id . "' AND + exe_cours_id = '" . Database :: escape_string($cid) . "' AND + tth.exe_name = '$hotpotato_name' + ORDER BY exe_cours_id ASC, exe_date DESC"; } $results = array(); @@ -186,6 +185,9 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe $hpresults[] = $rowx; } + $filter_by_not_revised = false; + $filter_by_revised = false; + if ($filter) { switch ($filter) { case 1 : @@ -218,6 +220,7 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe $return[$i] = array(); if (empty($user_id)) { + $return[$i]['official_code'] = $results[$i]['official_code']; $return[$i]['first_name'] = $results[$i]['userpart1']; $return[$i]['last_name'] = $results[$i]['userpart2']; $return[$i]['user_id'] = $results[$i]['excruid']; @@ -232,7 +235,7 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated'); $return[$i]['lp_id'] = $results[$i]['orig_lp_id']; $return[$i]['lp_name'] = $results[$i]['lp_name']; - + } } @@ -268,16 +271,22 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe * @param boolean Whether to include user fields or not * @return boolean False on error */ - public function exportCompleteReportCSV($document_path='',$user_id=null, $export_user_fields = false, $export_filter = 0, $exercise_id = 0, $hotpotato_name = null) { + public function exportCompleteReportCSV( + $document_path = '', + $user_id = null, + $export_user_fields = false, + $export_filter = 0, + $exercise_id = 0, + $hotpotato_name = null + ) { global $charset; - $this->_getExercisesReporting($document_path,$user_id, $export_filter, $exercise_id, $hotpotato_name); - + $this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); + $filename = 'exercise_results_'.date('YmdGis').'.csv'; if(!empty($user_id)) { $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv'; } $data = ''; - if (api_is_western_name_order()) { if(!empty($this->results[0]['first_name'])) { $data .= get_lang('FirstName').';'; @@ -293,6 +302,11 @@ public function exportCompleteReportCSV($document_path='',$user_id=null, $export $data .= get_lang('FirstName').';'; } } + $officialCodeInList = api_get_configuration_value('show_official_code_exercise_result_list'); + if ($officialCodeInList) { + $data .= get_lang('OfficialCode').';'; + } + $data .= get_lang('Email').';'; $data .= get_lang('Groups').';'; @@ -316,7 +330,7 @@ public function exportCompleteReportCSV($document_path='',$user_id=null, $export $data .= "\n"; //results - foreach($this->results as $row) { + foreach ($this->results as $row) { if (api_is_western_name_order()) { $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; @@ -326,6 +340,10 @@ public function exportCompleteReportCSV($document_path='',$user_id=null, $export $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; } + if ($officialCodeInList) { + $data .= $row['official_code'].';'; + } + $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',implode(", ", GroupManager :: get_user_group_name($row['user_id']))).';'; @@ -418,7 +436,7 @@ public function exportCompleteReportXLS($document_path='',$user_id = null, $expo } $worksheet->write($line,$column,get_lang('Groups')); $column++; - + if ($export_user_fields) { //show user fields section with a big th colspan that spans over all fields $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); @@ -468,7 +486,7 @@ public function exportCompleteReportXLS($document_path='',$user_id = null, $expo $worksheet->write($line,$column,api_html_entity_decode(strip_tags(implode(", ", GroupManager :: get_user_group_name($row['user_id']))), ENT_QUOTES, $charset)); $column++; - + if ($export_user_fields) { //show user fields data, if any, for this user $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); @@ -500,4 +518,3 @@ public function exportCompleteReportXLS($document_path='',$user_id = null, $expo return true; } } -endif; \ No newline at end of file diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index 7594e50a5fa..a4e7cd69572 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -10,9 +10,7 @@ * @todo small letters for table variables * */ -/** - * Code - */ + // name of the language file that needs to be included use \ChamiloSession as Session; @@ -47,16 +45,17 @@ // General parameters passed via POST/GET if ($debug) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); } -if ( empty ( $formSent ) ) { $formSent = $_REQUEST['formSent']; } -if ( empty ( $exerciseResult ) ) { $exerciseResult = $_SESSION['exerciseResult'];} -if ( empty ( $questionId ) ) { $questionId = $_REQUEST['questionId'];} -if ( empty ( $choice ) ) { $choice = $_REQUEST['choice'];} -if ( empty ( $questionNum ) ) { $questionNum = $_REQUEST['num'];} -if ( empty ( $nbrQuestions ) ) { $nbrQuestions = $_REQUEST['nbrQuestions'];} -if ( empty ( $questionList ) ) { $questionList = $_SESSION['questionList'];} -if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];} -if ( empty ( $exeId ) ) { $exeId = $_REQUEST['id'];} -if ( empty ( $action ) ) { $action = $_REQUEST['action']; } +if (empty($formSent)) { $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null; } +if (empty($exerciseResult)) { $exerciseResult = isset($_SESSION['exerciseResult']) ? $_SESSION['exerciseResult'] : null; } +if (empty($questionId)) { $questionId = isset($_REQUEST['questionId']) ? $_REQUEST['questionId'] : null;} +if (empty($choice)) { $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;} +if (empty($questionNum)) { $questionNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;} +if (empty($nbrQuestions)) { $nbrQuestions = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null;} +if (empty($questionList)) { $questionList = isset($_SESSION['questionList']) ? $_SESSION['questionList'] : null;} +if (empty($objExercise)) { $objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;} +if (empty($exeId)) { $exeId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;} +if (empty($action)) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;} + $id = intval($_REQUEST['id']); //exe id @@ -204,9 +203,9 @@ function getFCK(vals,marksid) { } if ($show_results || $show_only_total_score) { - $user_info = api_get_user_info($student_id); + $user_info = api_get_user_info($student_id); //Shows exercise header - echo $objExercise->show_exercise_result_header($user_info['complete_name'], api_convert_and_format_date($exercise_date)); + echo $objExercise->show_exercise_result_header($user_info, api_convert_and_format_date($exercise_date)); } $i = $totalScore = $totalWeighting = 0; diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index d561846018e..e2e89a78f52 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -614,6 +614,10 @@ function getWhereClause($col, $oper, $val) $columns = array( 'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions' ); + $officialCodeInList = api_get_configuration_value('show_official_code_exercise_result_list'); + if ($officialCodeInList == true) { + $columns = array_merge(array('official_code'), $columns); + } } $result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition); break; diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 749f32bf389..db629456ca0 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -2097,6 +2097,7 @@ function api_get_session_visibility( } } + // If the end date was set. if (!empty($row['date_end']) && $row['date_end'] != '0000-00-00') { // End date finish at midnight. diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index c35041105c8..e8470052920 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -232,3 +232,5 @@ //); // Define the frequency to which the data must be stored in the database //$_configuration['session_stored_after_n_times'] = 10; +// Show official code in exercise report list. +//$_configuration['show_official_code_exercise_result_list'] = false;