Source for file exercise_result.class.php
Documentation is available at exercise_result.class.php
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
B-1030 Brussels - Belgium
* ExerciseResult class: This class allows to instantiate an object of type ExerciseResult
* which allows you to export exercises results in multiple presentation forms
* @package dokeos.exercise
* @author Yannick Warnier
private $results = array(); //stores the results
* constructor of the class
public function ExerciseResult($get_questions= false,$get_answers= false)
$this->exercise_list = array();
$this->readExercisesList();
foreach($this->exercises_list as $exe)
$this->exercises_list['questions'] = $this->getExerciseQuestionList($exe['id']);
* Reads exercises information (minimal) from the data base
* @param boolean Whether to get only visible exercises (true) or all of them (false). Defaults to false.
* @return array A list of exercises available
$sql= "SELECT id,title,type,random,active FROM $TBL_EXERCISES";
$sql.= ' WHERE active=1';
$sql .= ' ORDER BY title';
// if the exercise has been found
* Gets the questions related to one exercise
* @param integer Exercise ID
$sql= "SELECT q.id, q.question, q.ponderation, q.position, q.type, q.picture " .
" FROM $TBL_EXERCISE_QUESTION eq, $TBL_QUESTIONS q " .
" WHERE eq.question_id=q.id AND eq.exercice_id='$e_id' " .
// fills the array with the question ID for this exercise
// the key of the array is the question position
* Gets the results of all students (or just one student if access is limited)
* @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
//get all results (ourself and the others) as an admin should see them
//AND exe_user_id <> $_user['user_id'] clause has been removed
$sql= "SELECT CONCAT(lastname,' ',firstname),ce.title, te.exe_result ,
te.exe_weighting, UNIX_TIMESTAMP(te.exe_date),te.exe_id, user.email, user.user_id
FROM $TBL_EXERCISES ce , $TBL_TRACK_EXERCISES te, $TBL_USER user
WHERE te.exe_exo_id = ce.id AND user_id=te.exe_user_id AND te.exe_cours_id='$cid'
ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC";
$hpsql= "SELECT CONCAT(tu.lastname,' ',tu.firstname), tth.exe_name,
tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date), tu.email, tu.user_id
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '". $cid. "'
ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC";
{ // get only this user's results
$sql= "SELECT '',ce.title, te.exe_result , te.exe_weighting, " .
"UNIX_TIMESTAMP(te.exe_date),te.exe_id
FROM $TBL_EXERCISES ce , $TBL_TRACK_EXERCISES te
WHERE te.exe_exo_id = ce.id AND te.exe_user_id='". $user_id. "' AND te.exe_cours_id='$cid'
ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC";
$hpsql= "SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '". $user_id. "' AND exe_cours_id = '". $cid. "'
ORDER BY exe_cours_id ASC, exe_date ASC";
//Print the results of tests
for($i = 0; $i < sizeof($results); $i++ )
$mailid = $results[$i][6];
$return[$i]['user'] = $user;
$return[$i]['user_id'] = $results[$i][7];
$return[$i]['title'] = $test;
$return[$i]['result'] = $res;
$return[$i]['max'] = $results[$i][3];
// Print the Result of Hotpotatoes Tests
for($i = 0; $i < sizeof($hpresults); $i++ )
$return[$j+ $i] = array();
$title = GetQuizName($hpresults[$i][1],$document_path);
$return[$j+ $i]['user'] = $hpresults[$i][0];
$return[$j+ $i]['user_id'] = $results[$i][6];
$return[$j+ $i]['title'] = $title;
$return[$j+ $i]['time'] = strftime(get_lang('dateTimeFormatLong'),$hpresults[$i][4]);
$return[$j+ $i]['result'] = $hpresults[$i][2];
$return[$j+ $i]['max'] = $hpresults[$i][3];
* Exports the complete report as a CSV file
* @param string Document path inside the document tool
* @param integer Optional user ID
* @param boolean Whether to include user fields or not
* @return boolean False on error
$filename = 'exercise_results_'. date('YmdGis'). '.csv';
$filename = 'exercise_results_user_'. $user_id. '_'. date('YmdGis'). '.csv';
if(!empty($this->results[0]['user']))
//show user fields section with a big th colspan that spans over all fields
$num = count($extra_user_fields);
foreach($extra_user_fields as $field)
$display_extra_user_fields = true;
//show user fields data, if any, for this user
foreach($user_fields_values as $value)
header('Content-type: application/octet-stream');
header('Content-Type: application/force-download');
header('Content-length: '. $len);
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT']))
header('Content-Disposition: filename= '. $filename);
header('Content-Disposition: attachment; filename= '. $filename);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
header('Cache-Control: public'); // IE cannot download from sessions without a cache
header('Content-Description: '. $filename);
header('Content-transfer-encoding: binary');
* Exports the complete report as an XLS file
* @return boolean False on error
$filename = 'exercise_results_'. date('YmdGis'). '.xls';
$filename = 'exercise_results_user_'. $user_id. '_'. date('YmdGis'). '.xls';
$workbook->send($filename);
$worksheet = & $workbook->addWorksheet('Report '. date('YmdGis'));
$column = 0; //skip the first column (row titles)
if(!empty($this->results[0]['user']))
$worksheet->write($line,$column,get_lang('User'));
//show user fields section with a big th colspan that spans over all fields
//show the fields names for user fields
foreach($extra_user_fields as $field)
$worksheet->write($line,$column,get_lang('Title'));
$worksheet->write($line,$column,get_lang('Date'));
$worksheet->write($line,$column,get_lang('Results'));
$worksheet->write($line,$column,get_lang('Weighting'));
//show user fields data, if any, for this user
foreach($user_fields_values as $value)
$worksheet->write($line,$column,$row['time']);
$worksheet->write($line,$column,$row['result']);
$worksheet->write($line,$column,$row['max']);
|