@ -90,7 +90,7 @@ 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) {
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);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -108,7 +108,7 @@ class ExerciseResult
$user_id = intval($user_id);
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
$exercise_id = intval($exercise_id);
$hotpotato_name = Database::escape_string($hotpotato_name);
$hotpotato_name = Database::escape_string($hotpotato_name);
if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id ";
@ -116,7 +116,7 @@ class ExerciseResult
if (empty($user_id)) {
$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult , te.exe_weighting as exweight,
te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration
te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration
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)
WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND ce.active < >-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0";
@ -135,7 +135,7 @@ class ExerciseResult
WHERE te.status != 'incomplete' AND te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND ce.active < >-1 AND" .
" orig_lp_id = 0 AND orig_lp_item_id = 0 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
$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";
@ -156,18 +156,18 @@ class ExerciseResult
if ($filter) {
switch ($filter) {
case 1 :
$filter_by_not_revised = true;
break;
$filter_by_not_revised = true;
break;
case 2 :
$filter_by_revised = true;
break;
$filter_by_revised = true;
break;
default :
null;
null;
}
}
//Print the results of tests
if(is_array($results) & & empty($hotpotato_name)) {
if (is_array($results) & & empty($hotpotato_name)) {
for($i = 0; $i < sizeof ( $ results ) ; $ i + + ) {
$revised = false;
@ -187,16 +187,16 @@ class ExerciseResult
if (empty($user_id)) {
$return[$i]['last_name'] = $results[$i]['userpart1'];
$return[$i]['first_name'] = $results[$i]['userpart2'];
$return[$i]['user_id'] = $results[$i]['us erid'];
$return[$i]['user_id'] = $results[$i]['exc ru id'];
$return[$i]['email'] = $results[$i]['exemail'];
}
$return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['time'] = api_convert_and_format_date($results[$i]['exdate'], null, date_default_timezone_get());
$return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight'];
$return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['time'] = api_convert_and_format_date($results[$i]['exdate'], null, date_default_timezone_get());
$return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight'];
}
}
// Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) {
@ -228,9 +228,9 @@ 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 = array() , $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';
@ -248,10 +248,10 @@ class ExerciseResult
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,0,5,'ASC',false);
$num = count($extra_user_fields);
$extra_user_fields = UserManager::get_extra_fields(0,100 0,5,'ASC',false, 1 );
$num = count($extra_user_fields);
foreach($extra_user_fields as $field) {
$data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[4 ]), ENT_QUOTES, $charset)).'";';
$data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[3 ]), ENT_QUOTES, $charset)).'";';
}
$display_extra_user_fields = true;
}
@ -274,7 +274,7 @@ class ExerciseResult
}
if($export_user_fields) {
//show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data(intval($row['user_id']),false,fals e);
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, tru e);
foreach($user_fields_values as $value) {
$data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
}
@ -309,14 +309,15 @@ class ExerciseResult
* Exports the complete report as an XLS file
* @return boolean False on error
*/
public function exportCompleteReportXLS($document_path='',$user_id=null, $export_user_fields=array() , $export_filter = 0, $exercise_id=0, $hotpotato_name = null) {
global $charset;
$this->_getExercisesReporting($document_path,$user_id,$export_filter, $exercise_id,$hotpotato_name);
public function exportCompleteReportXLS($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);
$filename = 'exercise_results_'.date('YmdGis').'.xls';
if(!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls';
} //build the results
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php');
}
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8
@ -337,24 +338,26 @@ class ExerciseResult
}
if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email'));
$column++;
$column++;
$worksheet->write($line,$column,get_lang('LastName'));
$column++;
$column++;
$worksheet->write($line,$column,get_lang('FirstName'));
$column++;
$column++;
}
$export_user_fields = true;
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,0,5,'ASC',false, 1);
$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
//show the fields names for user fields
foreach($extra_user_fields as $field) {
foreach($extra_user_fields as $field) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++;
}
}
$worksheet->write($line,$column,get_lang('Title'));
$column++;
$worksheet->write($line,$column,get_lang('Date'));
@ -367,18 +370,20 @@ class ExerciseResult
foreach($this->results as $row) {
$column = 0;
if(!empty($row['last_name']) & & !empty($row['first_name'])) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++;
}
if ($export_user_fields) {
if ($export_user_fields) {
//show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data(intval($row['user_id']),false,false, false, true);
foreach($user_fields_values as $value) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
foreach($user_fields_values as $value) {
$worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
$column++;
}
}