|
|
|
|
@ -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 |
|
|
|
|
@ -83,7 +75,8 @@ class ExerciseResult |
|
|
|
|
* @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); |
|
|
|
|
@ -105,7 +98,9 @@ class ExerciseResult |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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, |
|
|
|
|
@ -118,8 +113,8 @@ class ExerciseResult |
|
|
|
|
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 |
|
|
|
|
@ -127,6 +122,7 @@ class ExerciseResult |
|
|
|
|
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, |
|
|
|
|
@ -142,6 +138,7 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
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 @@ class ExerciseResult |
|
|
|
|
$hpresults[] = $rowx; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$filter_by_not_revised = false; |
|
|
|
|
$filter_by_revised = false; |
|
|
|
|
|
|
|
|
|
if ($filter) { |
|
|
|
|
switch ($filter) { |
|
|
|
|
case 1 : |
|
|
|
|
@ -218,6 +220,7 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
* @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 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
} |
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
|
|
|
|
|
$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 @@ class ExerciseResult |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
endif; |