Skip to content

Commit

Permalink
Adding $_configuration['show_official_code_exercise_result_list'] see
Browse files Browse the repository at this point in the history
BT#8746
  • Loading branch information
jmontoyaa committed Oct 6, 2014
1 parent 78fd127 commit fc3508e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 58 deletions.
22 changes: 19 additions & 3 deletions main/exercice/exercise.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions main/exercice/exercise.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ";

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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']
);
Expand Down
12 changes: 12 additions & 0 deletions main/exercice/exercise_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down Expand Up @@ -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) {
Expand Down
83 changes: 50 additions & 33 deletions main/exercice/exercise_result.class.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
<?php
/* For licensing terms, see /license.txt */

/**
* ExerciseResult class: This class allows to instantiate an object
* of type ExerciseResult
* which allows you to export exercises results in multiple presentation forms
* @package chamilo.exercise
* @author Yannick Warnier
* @version $Id: $
*/
/**
* Code
*/
if(!class_exists('ExerciseResult')):
/**
* Exercise results class
* @package chamilo.exercise
*/
*/
class ExerciseResult
{
private $exercises_list = array(); //stores the list of exercises
Expand Down Expand Up @@ -83,7 +75,8 @@ private function _readExerciseQuestionsList($e_id)
* @param string The document path (for HotPotatoes retrieval)
* @param integer User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
*/
function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exercise_id = 0, $hotpotato_name = null) {
public function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exercise_id = 0, $hotpotato_name = null)
{
$return = array();

$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
Expand All @@ -105,7 +98,9 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe
}

if (empty($user_id)) {
$user_id_and = null;
$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,
Expand All @@ -118,15 +113,16 @@ function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exe
te.exe_duration as duration,
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";
$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,
Expand All @@ -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,
Expand All @@ -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();
Expand All @@ -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 :
Expand Down Expand Up @@ -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'];
Expand All @@ -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'];

}
}

Expand Down Expand Up @@ -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').';';
Expand All @@ -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').';';

Expand All @@ -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)).';';
Expand All @@ -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']))).';';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -500,4 +518,3 @@ public function exportCompleteReportXLS($document_path='',$user_id = null, $expo
return true;
}
}
endif;
Loading

0 comments on commit fc3508e

Please sign in to comment.