Adding export option "include all users" see BT#8746

1.9.x
Julio Montoya 10 years ago
parent 6cd7a3f969
commit 0d131f9e4e
  1. 47
      main/exercice/exercise_report.php
  2. 226
      main/exercice/exercise_result.class.php
  3. 96
      main/exercice/hotpotatoes_exercise_result.class.php

@ -83,10 +83,19 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
$load_extra_data = true;
}
$includeAllUsers = false;
if (isset($_REQUEST['include_all_users']) &&
$_REQUEST['include_all_users'] == 1
) {
$includeAllUsers = true;
}
require_once 'exercise_result.class.php';
$export = new ExerciseResult();
$export->setIncludeAllUsers($includeAllUsers);
switch ($_GET['export_format']) {
case 'xls' :
$export = new ExerciseResult();
$export->exportCompleteReportXLS(
$documentPath,
null,
@ -99,7 +108,6 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
break;
case 'csv' :
default :
$export = new ExerciseResult();
$export->exportCompleteReportCSV(
$documentPath,
null,
@ -190,15 +198,18 @@ if (isset($_REQUEST['comments']) &&
Database::query($sql);
}
$qry = 'SELECT DISTINCT question_id, marks FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.' GROUP BY question_id';
$qry = 'SELECT DISTINCT question_id, marks
FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.'
GROUP BY question_id';
$res = Database::query($qry);
$tot = 0;
while ($row = Database :: fetch_array($res, 'ASSOC')) {
$tot += $row['marks'];
}
$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id;
Database::query($totquery);
$sql = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."'
WHERE exe_id = ".$id;
Database::query($sql);
if (isset($_POST['send_notification'])) {
//@todo move this somewhere else
@ -337,7 +348,8 @@ $extra = '<script>
"'.addslashes(get_lang('Download')).'": function() {
var export_format = $("input[name=export_format]:checked").val();
var extra_data = $("input[name=load_extra_data]:checked").val();
location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
var includeAllUsers = $("input[name=include_all_users]:checked").val();
location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers;
$( this ).dialog( "close" );
},
}
@ -353,6 +365,7 @@ $form = new FormValidator('report', 'post', null, null, array('class' => 'form-v
$form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
$form->setDefaults(array('export_format' => 'csv'));
$extra .= $form->return_form();
$extra .= '</div>';
@ -382,7 +395,7 @@ $officialCodeInList = api_get_configuration_value('show_official_code_exercise_r
if ($is_allowedToEdit || $is_tutor) {
//The order is important you need to check the the $column variable in the model.ajax.php file
// The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(
get_lang('FirstName'),
@ -454,17 +467,19 @@ $extra_params['height'] = 'auto';
?>
<script>
function setSearchSelect(columnName) {
$("#results").jqGrid('setColProp', columnName,
{
searchoptions:{
dataInit:function(el){
$("option[value='1']",el).attr("selected", "selected");
setTimeout(function(){
$(el).trigger('change');
},1000);
$("#results").jqGrid(
'setColProp',
columnName, {
searchoptions:{
dataInit:function(el) {
$("option[value='1']",el).attr("selected", "selected");
setTimeout(function(){
$(el).trigger('change');
},1000);
}
}
}
});
);
}
function exportExcel() {

@ -12,87 +12,50 @@ class ExerciseResult
{
private $exercises_list = array(); //stores the list of exercises
private $results = array(); //stores the results
public $includeAllUsers = false;
/**
* constructor of the class
*/
public function ExerciseResult($get_questions = false, $get_answers = false)
{
}
/**
* 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
*/
private function _readExercisesList($only_visible = false)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql="SELECT id,title,type,random,active FROM $TBL_EXERCISES";
if($only_visible)
{
$sql.= ' WHERE active=1';
}
$sql .= ' ORDER BY title';
$result=Database::query($sql);
// if the exercise has been found
while($row=Database::fetch_array($result,'ASSOC'))
{
$return[] = $row;
}
// exercise not found
return $return;
}
/**
* Gets the questions related to one exercise
* @param integer Exercise ID
*/
private function _readExerciseQuestionsList($e_id)
{
$return = array();
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql="SELECT q.id, q.question, q.ponderation, eq.question_order, q.type, q.picture " .
" FROM $TBL_EXERCISE_QUESTION eq, $TBL_QUESTIONS q " .
" WHERE eq.question_id=q.id AND eq.exercice_id='".Database::escape_string($e_id)."' " .
" ORDER BY eq.question_order";
$result=Database::query($sql);
// fills the array with the question ID for this exercise
// the key of the array is the question position
while($row=Database::fetch_array($result,'ASSOC'))
{
$return[] = $row;
}
return true;
}
/**
* 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
*/
public function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exercise_id = 0, $hotpotato_name = null)
/**
* @param bool $includeAllUsers
*/
public function setIncludeAllUsers($includeAllUsers)
{
$this->includeAllUsers = $includeAllUsers;
}
/**
* Gets the results of all students (or just one student if access is limited)
*
* @param string $document_path The document path (for HotPotatoes retrieval)
* @param int $user_id User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
* @param int $filter
* @param int $exercise_id
* @param null $hotpotato_name
* @return bool
*/
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);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_TABLE_LP_MAIN = Database::get_course_table(TABLE_LP_MAIN);
$cid = api_get_course_id();
$course_id = api_get_course_int_id();
$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);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT_RECORDING = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$cid = api_get_course_id();
$course_id = api_get_course_int_id();
$user_id = intval($user_id);
$sessionId = api_get_session_id();
$session_id_and = ' AND te.session_id = ' . $sessionId . ' ';
$exercise_id = intval($exercise_id);
$hotpotato_name = Database::escape_string($hotpotato_name);
if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id ";
@ -128,7 +91,8 @@ class ExerciseResult
tth.exe_name,
tth.exe_result,
tth.exe_weighting,
tth.exe_date
tth.exe_date,
tth.exe_user_id as excruid
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND
tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND
@ -164,7 +128,7 @@ class ExerciseResult
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
$hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date, exe_user_id as excruid
FROM $TBL_TRACK_HOTPOTATOES
WHERE
exe_user_id = '" . $user_id . "' AND
@ -174,7 +138,6 @@ class ExerciseResult
}
$results = array();
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx;
@ -203,6 +166,7 @@ class ExerciseResult
}
//Print the results of tests
$userWithResults = array();
if (is_array($results) && empty($hotpotato_name)) {
for ($i = 0; $i < sizeof($results); $i++) {
$revised = false;
@ -215,8 +179,13 @@ class ExerciseResult
if (Database :: num_rows($query) > 0)
$revised = true;
if ($filter_by_not_revised && $revised) continue;
if ($filter_by_revised && !$revised) continue;
if ($filter_by_not_revised && $revised) {
continue;
}
if ($filter_by_revised && !$revised) {
continue;
}
$return[$i] = array();
@ -227,28 +196,33 @@ class ExerciseResult
$return[$i]['user_id'] = $results[$i]['excruid'];
$return[$i]['email'] = $results[$i]['exemail'];
}
$return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight'];
$return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
$return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight'];
$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'];
$userWithResults[$results[$i]['excruid']] = 1;
}
}
$isHotPotato = false;
// Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) {
for($i = 0; $i < sizeof($hpresults); $i++) {
if (is_array($hpresults) && !empty($hpresults)) {
$isHotPotato = true;
for ($i = 0; $i < sizeof($hpresults); $i++) {
$return[$i] = array();
$title = GetQuizName($hpresults[$i]['exe_name'], $document_path);
if ($title =='') {
$title = basename($hpresults[$i]['exe_name']);
}
if(empty($user_id)) {
if (empty($user_id)) {
$return[$i]['email'] = $hpresults[$i]['email'];
$return[$i]['first_name'] = $hpresults[$i]['userpart1'];
$return[$i]['last_name'] = $hpresults[$i]['userpart2'];
@ -260,9 +234,77 @@ class ExerciseResult
$return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting'];
$userWithResults[$results[$i]['excruid']] = 1;
}
}
if ($this->includeAllUsers) {
$latestId = count($return);
$userWithResults = array_keys($userWithResults);
if (empty($sessionId)) {
$students = CourseManager::get_user_list_from_course_code($cid);
} else {
$students = CourseManager::get_user_list_from_course_code($cid, $sessionId);
}
if (!empty($students)) {
foreach ($students as $student) {
if (!in_array($student['user_id'], $userWithResults)) {
$i = $latestId;
$isWestern = api_is_western_name_order();
if ($isHotPotato) {
$return[$i] = array();
if (empty($user_id)) {
$return[$i]['email'] = $student['email'];
if ($isWestern) {
$return[$i]['first_name'] = $student['firstname'];
$return[$i]['last_name'] = $student['lastname'];
} else {
$return[$i]['first_name'] = $student['lastname'];
$return[$i]['last_name'] = $student['firstname'];
}
}
$return[$i]['title'] = null;
$return[$i]['start_date'] = null;
$return[$i]['end_date'] = null;
$return[$i]['duration'] = null;
$return[$i]['result'] = null;
$return[$i]['max'] = null;
} else {
if (empty($user_id)) {
$return[$i]['official_code'] = $student['official_code'];
if ($isWestern) {
$return[$i]['first_name'] = $student['firstname'];
$return[$i]['last_name'] = $student['lastname'];
} else {
$return[$i]['first_name'] = $student['lastname'];
$return[$i]['last_name'] = $student['firstname'];
}
$return[$i]['user_id'] = $student['user_id'];
$return[$i]['email'] = $student['email'];
}
$return[$i]['title'] = null;
$return[$i]['start_date'] = null;
$return[$i]['end_date'] = null;
$return[$i]['duration'] = null;
$return[$i]['result'] = null;
$return[$i]['max'] = null;
$return[$i]['status'] = get_lang('NotAttempted');
$return[$i]['lp_id'] = null;
$return[$i]['lp_name'] = null;
}
$latestId++;
}
}
}
}
$this->results = $return;
return true;
}
@ -282,7 +324,7 @@ class ExerciseResult
$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)) {
@ -402,7 +444,7 @@ class ExerciseResult
$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').'.xls';
if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls';

@ -2,9 +2,8 @@
/* For licensing terms, see /license.txt */
/**
* HotpotatoesExerciseResult class: This class allows to instantiate an object
* of type HotpotatoesExerciseResult
* which allows you to export exercises results in multiple presentation forms
* Class HotpotatoesExerciseResult
* Allows you to export exercises results in multiple presentation forms
* @package chamilo.exercise
*/
class HotpotatoesExerciseResult
@ -15,62 +14,24 @@ class HotpotatoesExerciseResult
//stores the results
private $results = array();
/**
* constructor of the class
*/
public function ExerciseResult($get_questions = false, $get_answers = false)
{
}
/**
* 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
*/
private function _readExercisesList($only_visible = false)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql="SELECT id,title,type,random,active FROM $TBL_EXERCISES";
if ($only_visible) {
$sql.= ' WHERE active=1';
}
$sql .= ' ORDER BY title';
$result=Database::query($sql);
// if the exercise has been found
while($row=Database::fetch_array($result,'ASSOC'))
{
$return[] = $row;
}
// exercise not found
return $return;
}
/**
* 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
*/
// function _getExercisesReporting($document_path, $user_id = null, $filter = 0, $hotpotato_name = null) {
function _getExercisesReporting($document_path, $hotpotato_name)
public function getExercisesReporting($document_path, $hotpotato_name)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$cid = api_get_course_id();
$course_id = api_get_course_int_id();
$user_id = intval($user_id);
//$user_id = intval($user_id);
$user_id = null;
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
$hotpotato_name = Database::escape_string($hotpotato_name);
if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id ";
}
@ -92,11 +53,12 @@ class HotpotatoesExerciseResult
// get only this user's results
$sql = "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 ASC";
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 ASC";
}
$results = array();
@ -112,7 +74,7 @@ class HotpotatoesExerciseResult
$hpresults[] = $rowx;
}
if ($filter) {
/*if ($filter) {
switch ($filter) {
case 1 :
$filter_by_not_revised = true;
@ -123,7 +85,7 @@ class HotpotatoesExerciseResult
default :
null;
}
}
}*/
// Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) {
@ -146,9 +108,11 @@ class HotpotatoesExerciseResult
}
}
$this->results = $return;
return true;
}
/**
* Exports the complete report as a CSV file
* @param string Document path inside the document tool
@ -159,9 +123,9 @@ class HotpotatoesExerciseResult
public function exportCompleteReportCSV($document_path='', $hotpotato_name)
{
global $charset;
$this->_getExercisesReporting($document_path, $hotpotato_name);
$this->getExercisesReporting($document_path, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.csv';
if(!empty($user_id)) {
if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
}
$data = '';
@ -183,14 +147,14 @@ class HotpotatoesExerciseResult
}
$data .= get_lang('Email').';';
if ($export_user_fields) {
/*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);
$num = count($extra_user_fields);
foreach($extra_user_fields as $field) {
$data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
}
}
}*/
$data .= get_lang('Title').';';
$data .= get_lang('StartDate').';';
@ -210,13 +174,13 @@ class HotpotatoesExerciseResult
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
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($row['user_id'],false,false, false, true);
foreach($user_fields_values as $value) {
$data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
}
}
}*/
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',$row['exe_date']).';';
@ -252,9 +216,16 @@ class HotpotatoesExerciseResult
* Exports the complete report as an XLS file
* @return boolean False on error
*/
public function exportCompleteReportXLS($document_path='',$user_id = null, $export_user_fields= false, $export_filter = 0, $exercise_id=0, $hotpotato_name = null) {
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);
$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';
@ -279,7 +250,6 @@ class HotpotatoesExerciseResult
}
if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email'));
$column++;
@ -302,7 +272,7 @@ class HotpotatoesExerciseResult
//show the fields names for user fields
foreach ($extra_user_fields as $field) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$worksheet->write($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++;
}
}
@ -366,7 +336,7 @@ class HotpotatoesExerciseResult
$worksheet->write($line,$column,$row['status']);
$line++;
}
//output the results
$workbook->close();
return true;
}

Loading…
Cancel
Save