Cleaning exercise report + fixing exercise result exports (partial)

skala
Julio Montoya 14 years ago
parent 8247e20dfa
commit 09121a6463
  1. 2
      main/admin/user_edit.php
  2. 37
      main/exercice/exercise.lib.php
  3. 145
      main/exercice/exercise_report.php
  4. 53
      main/exercice/exercise_result.class.php

@ -234,7 +234,7 @@ if (!$user_data['platform_admin']) {
// EXTRA FIELDS
$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC', true, true);
foreach ($extra as $id => $field_details) {
if ($field_details[6] == 0) {
continue;

@ -959,11 +959,10 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$user_list_id = array ();
$duration_list = '';
$date_list = '';
$more_details_list = '';
for ($i = 0; $i < $sizeof; $i++) {
for ($i = 0; $i < $sizeof; $i++) {
$revised = $results[$i]['revised'];
if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
if (in_array($results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'], $users_array_id)) {
continue;
@ -971,19 +970,16 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$users_array_id[] = $results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'];
}
if ($is_allowedToEdit || $is_tutor) {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
//$test = $results[$i]['col3'];
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
$user_groups = displayGroupsForUser('<br/>', $results[$i]['user_id']);
} else {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
//$test = $results[$i]['col0'];
}
$user_list_id[] = $results[$i]['exe_user_id'];
$id = $results[$i]['exe_id'];
//$quiz_name_list = $test;
$dt = api_convert_and_format_date($results[$i]['exe_weighting']);
$res = $results[$i]['exe_result'];
$dt = api_convert_and_format_date($results[$i]['exe_weighting']);
// we filter the results if we have the permission to
if (isset ($results[$i]['results_disabled']))
@ -991,8 +987,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
else
$result_disabled = 0;
if ($result_disabled == 0) {
$add_start_date = $lang_nostartdate;
if ($result_disabled == 0) {
if ($is_allowedToEdit || $is_tutor) {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
@ -1015,14 +1010,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
if ($results[$i]['exstep'] > 1) {
$duration_list = ' ( ' . $results[$i]['steps_counter'] . ' ' . get_lang('Steps') . ' )';
}
//$add_start_date = api_convert_and_format_date($start_date) . ' / ';
} else {
$duration_list = get_lang('NoLogOfDuration');
//echo get_lang('NoLogOfDuration');
$duration_list = get_lang('NoLogOfDuration');
}
// Date conversion
$date_list = api_get_local_time($results[$i]['start_date']). ' / ' . api_get_local_time($results[$i]['exe_date']);
// there are already a duration test period calculated??
//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
@ -1031,6 +1024,10 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$my_res = $results[$i]['exe_result'];
$my_total = $results[$i]['exe_weighting'];
$results[$i]['start_date'] = api_get_local_time($results[$i]['start_date']);
$results[$i]['exe_date'] = api_get_local_time($results[$i]['exe_date']);
if (!$results[$i]['propagate_neg'] && $my_res < 0) {
$my_res = 0;
}
@ -1071,13 +1068,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
}
if ($is_allowedToEdit || $is_tutor) {
$results[$i]['status'] = $revised;
$results[$i]['score'] = $score;
$results[$i]['status'] = $revised;
$results[$i]['score'] = $score;
$results[$i]['actions'] = $actions;
$list_info[] = $results[$i];
} else {
$results[$i]['status'] = $revised;
$results[$i]['score'] = $score;
$results[$i]['status'] = $revised;
$results[$i]['score'] = $score;
$results[$i]['actions'] = $actions;
$list_info[] = $results[$i];
}

@ -32,12 +32,12 @@ require_once 'exercise.class.php';
require_once 'exercise.lib.php';
require_once 'question.class.php';
require_once 'answer.class.php';
require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once 'hotpotatoes.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH) . "groupmanager.lib.php"; // for group filtering
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH)."groupmanager.lib.php"; // for group filtering
// need functions of statsutils lib to display previous exercices scores
require_once api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php';
@ -45,7 +45,6 @@ require_once api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php';
// document path
$documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
/* Constants and variables */
$is_allowedToEdit = api_is_allowed_to_edit(null,true);
$is_tutor = api_is_allowed_to_edit(true);
@ -69,36 +68,24 @@ if (!empty($_GET['path'])) {
$parameters['path'] = Security::remove_XSS($_GET['path']);
}
if (!empty ($_GET['extra_data'])) {
switch ($_GET['extra_data']) {
case 'on' :
$_SESSION['export_user_fields'] = true;
break;
default :
$_SESSION['export_user_fields'] = false;
break;
}
}
if (!empty($_GET['export_report']) && $_GET['export_report'] == '1') {
if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
$user_id = null;
if (empty($_SESSION['export_user_fields']))
$_SESSION['export_user_fields'] = false;
if (!$is_allowedToEdit and !$is_tutor) {
$user_id = api_get_user_id();
}
$load_extra_data = false;
if (isset($_REQUEST['extra_data'])) {
$load_extra_data = true;
}
require_once 'exercise_result.class.php';
switch ($_GET['export_format']) {
case 'xls' :
$export = new ExerciseResult();
$export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_GET['export_filter'], $_GET['exerciseId'], $_GET['hotpotato_name']);
$export->exportCompleteReportXLS($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']);
exit;
break;
case 'csv' :
default :
$export = new ExerciseResult();
$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_GET['export_filter'], $_GET['exerciseId'], $_GET['hotpotato_name']);
$export->exportCompleteReportCSV($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']);
exit;
break;
}
@ -195,7 +182,7 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
$message .= '<p>'.get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />';
}
$message .= '<p>'.get_lang('Regards') . ' </p>';
$message .= '<p>'.get_lang('Regards').'</p>';
$message .= $from_name;
$message = str_replace("#test#", Security::remove_XSS($test), $message);
@ -219,17 +206,10 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
}
}
if ($is_allowedToEdit && $origin != 'learnpath') {
// the form
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
if ($_SESSION['export_user_fields']) {
$alt = get_lang('ExportWithUserFields');
$extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
} else {
$alt = get_lang('ExportWithoutUserFields');
$extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
}
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
$actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'','32').'</a>';
$actions .='<a href="live_stats.php?' . api_get_cidreq() . '&exerciseId='.$exercise_id.'">'.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'),'',32).'</a>';
@ -241,13 +221,16 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
}
//Deleting an attempt
if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty ($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) {
$sql = 'DELETE FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . intval($_GET['did']);
Database::query($sql);
$sql = 'DELETE FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = ' . intval($_GET['did']);
Database::query($sql);
header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId='.$exercise_id);
exit;
if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did'])) {
$exe_id = intval($_GET['did']);
if (!empty($exe_id)) {
$sql = 'DELETE FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$exe_id;
Database::query($sql);
$sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
Database::query($sql);
header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId='.$exercise_id);
exit;
}
}
if ($is_allowedToEdit || $is_tutor) {
@ -270,7 +253,7 @@ Display :: display_header($nameTools);
$actions = Display::div($actions, array('class'=> 'actions'));
$extra = '<script type="text/javascript">
$extra = '<script type="text/javascript">
$(document).ready(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
@ -326,6 +309,8 @@ $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerci
//$activeurl = '?sidx=session_active';
$action_links = '';
//Generating group list
$group_list = GroupManager::get_group_list();
$group_parameters = array(':'.get_lang('All'));
foreach ($group_list as $group) {
@ -382,7 +367,9 @@ if ($is_allowedToEdit || $is_tutor) {
return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
}';
} else {
api_not_allowed(); //view not available for students
//
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions'));
@ -409,7 +396,7 @@ $extra_params['rowList'] = array(10, 20 ,30);
<script>
function setSearchSelect(columnName) {
$("#results").jqGrid('setColProp', columnName,
$("#results").jqGrid('setColProp', columnName,
{
searchoptions:{
dataInit:function(el){
@ -422,31 +409,59 @@ function setSearchSelect(columnName) {
});
}
function exportExcel() {
var mya=new Array();
mya=$("#results").getDataIDs(); // Get All IDs
var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
var colNames=new Array();
var ii=0;
for (var i in data){colNames[ii++]=i;} // capture col names
var html="";
for(i=0;i<mya.length;i++) {
data=$("#results").getRowData(mya[i]); // get each row
for(j=0;j<colNames.length;j++) {
html=html+data[colNames[j]]+","; // output each column as tab delimited
}
html=html+"\n"; // output each row with end of line
}
html = html+"\n"; // end of line at the end
var form = $("#export_report_form");
$("#csvBuffer").attr('value', html);
form.target='_blank';
form.submit();
}
$(function() {
<?php
echo Display::grid_js('results', $url,$columns,$column_model, $extra_params, array(), $action_links, true);
?>
<?php if ($is_allowedToEdit || $is_tutor) { ?>
//setSearchSelect("status");
<?php if ($is_allowedToEdit || $is_tutor) { ?>
$("#results").jqGrid('navGrid','#results_pager', {edit:false,add:false,del:false},
{height:280,reloadAfterSubmit:false}, // edit options
{height:280,reloadAfterSubmit:false}, // add options
{reloadAfterSubmit:false}, // del options
//setSearchSelect("status");
//
//view:true, del:false, add:false, edit:false, excel:true}
$("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
{height:280, reloadAfterSubmit:false}, // view options
{height:280, reloadAfterSubmit:false}, // edit options
{height:280, reloadAfterSubmit:false}, // add options
{reloadAfterSubmit: false}, // del options
{width:500} // search options
);
/*
/*
// add custom button to export the data to excel
jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
caption:"",
jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
caption:"",
onClickButton : function () {
jQuery("#sessions").excelExport();
//exportExcel();
}
});
});*/
/*
jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
{
try {
@ -466,15 +481,17 @@ $(function() {
}
jQuery("#results").jqGrid('filterToolbar',options);
var sgrid = $("#results")[0];
sgrid.triggerToolbar();
sgrid.triggerToolbar();
<?php } ?>
});
</script>
<form id="export_report_form" method="post" action="exercise_report.php">
<input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
<input type="hidden" name="export_report" id="export_report" value="1" />
<input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" />
</form>
<?php
echo Display::grid_html('results');

@ -24,20 +24,7 @@ class ExerciseResult
/**
* constructor of the class
*/
public function ExerciseResult($get_questions=false,$get_answers=false)
{
//nothing to do
/*
$this->exercise_list = array();
$this->readExercisesList();
if($get_questions)
{
foreach($this->exercises_list as $exe)
{
$this->exercises_list['questions'] = $this->getExerciseQuestionList($exe['id']);
}
}
*/
public function ExerciseResult($get_questions=false,$get_answers=false) {
}
/**
@ -90,6 +77,7 @@ class ExerciseResult
}
return true;
}
/**
* Gets the results of all students (or just one student if access is limited)
* @param string The document path (for HotPotatoes retrieval)
@ -97,13 +85,14 @@ class ExerciseResult
*/
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);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$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 = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
@ -215,9 +204,10 @@ class ExerciseResult
$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]['time'] = api_convert_and_format_date($results[$i]['exdate']);
$return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight'];
$return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
}
}
@ -233,10 +223,9 @@ class ExerciseResult
$return[$i]['email'] = $hpresults[$i]['email'];
$return[$i]['first_name'] = $hpresults[$i]['userpart1'];
$return[$i]['last_name'] = $hpresults[$i]['userpart2'];
//$return[$i]['user_id'] = $results[$i]['userid'];
}
$return[$i]['title'] = $title;
$return[$i]['time'] = api_convert_and_format_date($hpresults[$i]['exdate'], null, date_default_timezone_get());
$return[$i]['time'] = api_convert_and_format_date($hpresults[$i]['exdate']);
$return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting'];
}
@ -283,13 +272,14 @@ class ExerciseResult
$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)).'";';
}
$display_extra_user_fields = true;
}
}
$data .= get_lang('Title').';';
$data .= get_lang('Date').';';
$data .= get_lang('StartDate').';';
$data .= get_lang('Score').';';
$data .= get_lang('Total').';';
$data .= get_lang('Status').';';
$data .= "\n";
//results
@ -322,6 +312,7 @@ class ExerciseResult
$data .= str_replace("\r\n",' ',$row['time']).';';
$data .= str_replace("\r\n",' ',$row['result']).';';
$data .= str_replace("\r\n",' ',$row['max']).';';
$data .= str_replace("\r\n",' ',$row['status']).';';
$data .= "\n";
}
@ -352,7 +343,7 @@ class ExerciseResult
*/
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';
@ -383,17 +374,14 @@ class ExerciseResult
$worksheet->write($line,$column,get_lang('Email'));
$column++;
if (api_is_western_name_order()) {
if (api_is_western_name_order()) {
$worksheet->write($line,$column,get_lang('FirstName'));
$column++;
$column++;
$worksheet->write($line,$column,get_lang('LastName'));
$column++;
} else {
$worksheet->write($line,$column,get_lang('LastName'));
$column++;
$column++;
$worksheet->write($line,$column,get_lang('FirstName'));
$column++;
}
@ -412,11 +400,13 @@ class ExerciseResult
$worksheet->write($line,$column,get_lang('Title'));
$column++;
$worksheet->write($line,$column,get_lang('Date'));
$worksheet->write($line,$column,get_lang('StartDate'));
$column++;
$worksheet->write($line,$column,get_lang('Score'));
$column++;
$worksheet->write($line,$column,get_lang('Total'));
$column++;
$worksheet->write($line,$column,get_lang('Status'));
$line++;
foreach($this->results as $row) {
@ -432,8 +422,7 @@ class ExerciseResult
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);
$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++;
@ -446,6 +435,8 @@ class ExerciseResult
$worksheet->write($line,$column,$row['result']);
$column++;
$worksheet->write($line,$column,$row['max']);
$column++;
$worksheet->write($line,$column,$row['status']);
$line++;
}
//output the results

Loading…
Cancel
Save