Loading base session results see BT#8199

1.9.x
Julio Montoya 12 years ago
parent bd0320a441
commit d2ddee1767
  1. 456
      main/tracking/exams.php

@ -14,7 +14,6 @@ require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.ph
$toolTable = Database::get_course_table(TABLE_TOOL_LIST); $toolTable = Database::get_course_table(TABLE_TOOL_LIST);
$quizTable = Database::get_course_table(TABLE_QUIZ_TEST); $quizTable = Database::get_course_table(TABLE_QUIZ_TEST);
$exerciseStatsTable = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$this_section = SECTION_TRACKING; $this_section = SECTION_TRACKING;
$is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin; $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
@ -47,6 +46,12 @@ if ($global) {
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
if (empty($sessionId)) {
$sessionCondition = ' AND session_id = 0';
} else {
$sessionCondition = api_get_session_condition($sessionId, true, true);
}
$form = new FormValidator('search_simple', 'POST', '', '', null, false); $form = new FormValidator('search_simple', 'POST', '', '', null, false);
$form->addElement('text', 'score', get_lang('Percentage')); $form->addElement('text', 'score', get_lang('Percentage'));
if ($global) { if ($global) {
@ -54,11 +59,12 @@ if ($global) {
} else { } else {
// Get exam lists // Get exam lists
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$sql = "SELECT quiz.title, id FROM $quizTable AS quiz $sql = "SELECT quiz.title, id FROM $quizTable AS quiz
WHERE WHERE
c_id = $courseId AND c_id = $courseId AND
active='1' AND active='1'
session_id = $sessionId $sessionCondition
ORDER BY quiz.title ASC"; ORDER BY quiz.title ASC";
$result = Database::query($sql); $result = Database::query($sql);
@ -169,8 +175,8 @@ $s_css_class = null;
if (!empty($courseList) && is_array($courseList)) { if (!empty($courseList) && is_array($courseList)) {
foreach ($courseList as $courseInfo) { foreach ($courseList as $courseInfo) {
$global_row = $row_not_global = array();
$sessionList = SessionManager::get_session_by_course($courseInfo['code']); $sessionList = SessionManager::get_session_by_course($courseInfo['code']);
$newSessionList = array(); $newSessionList = array();
if (!empty($sessionList)) { if (!empty($sessionList)) {
foreach ($sessionList as $session) { foreach ($sessionList as $session) {
@ -183,10 +189,20 @@ if (!empty($courseList) && is_array($courseList)) {
if ($global) { if ($global) {
$sql = "SELECT count(id) as count $sql = "SELECT count(id) as count
FROM $quizTable AS quiz FROM $quizTable AS quiz
WHERE active='1' AND c_id = $courseId"; WHERE active='1' AND c_id = $courseId AND session_id = 0";
$result = Database::query($sql); $result = Database::query($sql);
$countExercises = Database::store_result($result); $countExercises = Database::store_result($result);
$exerciseCount = $countExercises[0]['count']; $exerciseCount = $countExercises[0]['count'];
$sql = "SELECT count(id) as count
FROM $quizTable AS quiz
WHERE active='1' AND c_id = $courseId AND session_id <> 0";
$result = Database::query($sql);
$countExercises = Database::store_result($result);
$exerciseSessionCount = $countExercises[0]['count'];
$exerciseCount = $exerciseCount + $exerciseCount *count($newSessionList) + $exerciseSessionCount;
// Add course and session list. // Add course and session list.
if ($exerciseCount == 0) { if ($exerciseCount == 0) {
$exerciseCount = 2; $exerciseCount = 2;
@ -210,32 +226,249 @@ if (!empty($courseList) && is_array($courseList)) {
WHERE c_id = $courseId AND active='1' WHERE c_id = $courseId AND active='1'
ORDER BY session_id, quiz.title ASC"; ORDER BY session_id, quiz.title ASC";
} else { } else {
//$sessionCondition = api_get_session_condition($sessionId, true, false);
if (!empty($exerciseId)) { if (!empty($exerciseId)) {
$sql = "SELECT quiz.title, id, session_id $sql = "SELECT quiz.title, id, session_id
FROM $quizTable AS quiz FROM $quizTable AS quiz
WHERE WHERE
c_id = $courseId AND c_id = $courseId AND
active='1' AND active = '1' AND
id = $exerciseId AND id = $exerciseId
session_id = $sessionId $sessionCondition
ORDER BY session_id, quiz.title ASC"; ORDER BY session_id, quiz.title ASC";
} else { } else {
$sql = "SELECT quiz.title, id, session_id $sql = "SELECT quiz.title, id, session_id
FROM $quizTable AS quiz FROM $quizTable AS quiz
WHERE WHERE
c_id = $courseId AND c_id = $courseId AND
active='1' AND active='1'
session_id = $sessionId $sessionCondition
ORDER BY session_id, quiz.title ASC"; ORDER BY session_id, quiz.title ASC";
} }
} }
$resultExercises = Database::query($sql); $resultExercises = Database::query($sql);
$i = 0;
if (Database::num_rows($resultExercises) > 0) { if (Database::num_rows($resultExercises) > 0) {
$export_array_global = array();
while ($exercise = Database::fetch_array($resultExercises)) { while ($exercise = Database::fetch_array($resultExercises)) {
$sessionId = $exercise['session_id']; $exerciseSessionId = $exercise['session_id'];
if (empty($exerciseSessionId)) {
if ($global) {
// If the exercise was created in the base course.
// Load all sessions.
foreach ($newSessionList as $currentSessionId => $sessionName) {
$result = processStudentList(
$filter_score,
$global,
$exercise,
$courseInfo,
$currentSessionId,
$newSessionList
);
$html .= $result['html'];
$export_array_global = array_merge($export_array_global, $result['export_array_global']);
}
// Load base course.
$result = processStudentList(
$filter_score,
$global,
$exercise,
$courseInfo,
0,
$newSessionList
);
$html .= $result['html'];
$export_array_global = array_merge($export_array_global, $result['export_array_global']);
} else {
if (empty($sessionId)) {
// Load base course.
$result = processStudentList(
$filter_score,
$global,
$exercise,
$courseInfo,
0,
$newSessionList
);
$html .= $result['html'];
$export_array_global = array_merge(
$export_array_global,
$result['export_array_global']
);
} else {
$result = processStudentList(
$filter_score,
$global,
$exercise,
$courseInfo,
$sessionId,
$newSessionList
);
$html .= $result['html'];
$export_array_global = array_merge(
$export_array_global,
$result['export_array_global']
);
}
}
} else {
// If the exercise only exists in this session.
$result = processStudentList(
$filter_score,
$global,
$exercise,
$courseInfo,
$exerciseSessionId,
$newSessionList
);
$html .= $result['html'];
$export_array_global = array_merge($export_array_global, $result['export_array_global']);
}
}
} else {
$html .= "<tr>
<td colspan='6'>
".get_lang('NoExercise')."
</td>
</tr>
";
}
} else {
$html .= "<tr>
<td colspan='6'>
".get_lang('NoExercise')."
</td>
</tr>
";
}
}
}
$html .= '</table>';
if (!$exportToXLS) {
echo $html;
}
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($exportToXLS) {
if ($global) {
export_complete_report_xls($filename, $export_array_global);
} else {
export_complete_report_xls($filename, $export_array);
}
exit;
}
/**
* @param $a
* @param $b
* @return int
*/
function sort_user($a, $b) {
if (is_numeric($a['score']) && is_numeric($b['score'])) {
if ($a['score'] < $b['score']) {
return 1;
}
return 0;
}
return 1;
}
/**
* @param string $filename
* @param array $array
*/
function export_complete_report_xls($filename, $array)
{
global $charset, $global, $filter_score;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
$line = 0;
$column = 0; //skip the first column (row titles)
if ($global) {
$worksheet->write($line, $column, get_lang('Courses'));
$column++;
$worksheet->write($line, $column, get_lang('Exercises'));
$column++;
$worksheet->write($line, $column, get_lang('ExamTaken'));
$column++;
$worksheet->write($line, $column, get_lang('ExamNotTaken'));
$column++;
$worksheet->write($line, $column, sprintf(get_lang('ExamPassX'), $filter_score) . '%');
$column++;
$worksheet->write($line, $column, get_lang('ExamFail'));
$column++;
$worksheet->write($line, $column, get_lang('TotalStudents'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
$column++;
}
$line++;
}
$line++;
} else {
$worksheet->write($line,$column,get_lang('Exercises'));
$column++;
$worksheet->write($line,$column,get_lang('User'));
$column++;
$worksheet->write($line,$column,get_lang('Percentage'));
$column++;
$worksheet->write($line,$column,get_lang('Status'));
$column++;
$worksheet->write($line,$column,get_lang('Attempts'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
$worksheet->write($line,$column,html_entity_decode(strip_tags($row['exercise'])));
$column++;
foreach ($row['users'] as $key=>$user) {
$column = 1;
$worksheet->write($line,$column,html_entity_decode(strip_tags($user)));
$column++;
foreach ($row['results'][$key] as $result_item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($result_item)));
$column++;
}
$line++;
}
}
$line++;
}
$workbook->close();
exit;
}
function processStudentList($filter_score, $global, $exercise, $courseInfo, $sessionId, $newSessionList)
{
$exerciseStatsTable = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
if (empty($sessionId)) { if (empty($sessionId)) {
$students = CourseManager::get_student_list_from_course_code( $students = CourseManager::get_student_list_from_course_code(
@ -250,12 +483,12 @@ if (!empty($courseList) && is_array($courseList)) {
); );
} }
$totalStudents = count($students); $html = null;
$global_row[]= $courseInfo['title']; $totalStudents = count($students);
if (!$global) { if (!$global) {
$html .= "<tr class='".$s_css_class."'>"; $html .= "<tr>";
} }
if (!$global) { if (!$global) {
@ -273,18 +506,16 @@ if (!empty($courseList) && is_array($courseList)) {
$html .= '</td>'; $html .= '</td>';
$global_row[] = $exercise['title']; $globalRow = array(
$row_not_global['exercise'] = $exercise['title']; $courseInfo['title'],
$exercise['title']
$taken = 0; );
$total_with_parameter = 0;
$fail = 0;
$not_taken = 0;
$total_with_parameter_score = 0; $total_with_parameter_score = 0;
$total_with_parameter_porcentage = 0; $taken = 0;
$export_array_global = array();
$studentResult = array();
$student_result = array();
foreach ($students as $student) { foreach ($students as $student) {
$studentId = isset($student['user_id']) ? $student['user_id'] : $student['id_user']; $studentId = isset($student['user_id']) ? $student['user_id'] : $student['id_user'];
$sql = "SELECT COUNT(ex.exe_id) as count $sql = "SELECT COUNT(ex.exe_id) as count
@ -316,19 +547,11 @@ if (!empty($courseList) && is_array($courseList)) {
} }
$percentageScore = 0; $percentageScore = 0;
if ($weighting != 0) { if ($weighting != 0) {
$percentageScore = round(($score*100)/$weighting); $percentageScore = round(($score*100)/$weighting);
} }
$weighting = 0;
if ($i % 2 == 0) {
$s_css_class = "row_odd";
} else {
$s_css_class = "row_even";
}
$i++;
if ($attempts['count'] > 0 ) { if ($attempts['count'] > 0 ) {
$taken++; $taken++;
} }
@ -387,7 +610,7 @@ if (!empty($courseList) && is_array($courseList)) {
} }
$userRow .= '</tr>'; $userRow .= '</tr>';
$student_result[$studentId] = array( $studentResult[$studentId] = array(
'html' => $userRow, 'html' => $userRow,
'score' => $score, 'score' => $score,
'array' => $tempArray, 'array' => $tempArray,
@ -396,42 +619,44 @@ if (!empty($courseList) && is_array($courseList)) {
} }
} }
$row_not_global['exercise'] = $exercise['title'];
if (!$global) { if (!$global) {
if (!empty($student_result)) { if (!empty($studentResult)) {
$student_result_empty = $student_result_content = array(); $studentResultEmpty = $studentResultContent = array();
foreach ($student_result as $row) { foreach ($studentResult as $row) {
if ($row['score'] == '-') { if ($row['score'] == '-') {
$student_result_empty[] = $row; $studentResultEmpty[] = $row;
} else { } else {
$student_result_content[] = $row; $studentResultContent[] = $row;
} }
} }
// Sort only users with content // Sort only users with content
usort($student_result_content, 'sort_user'); usort($studentResultContent, 'sort_user');
$student_result = array_merge($student_result_content, $student_result_empty); $studentResult = array_merge($studentResultContent, $studentResultEmpty);
foreach ($student_result as $row) { foreach ($studentResult as $row) {
$html .= $row['html']; $html .= $row['html'];
$row_not_global['results'][]= $row['array']; $row_not_global['results'][] = $row['array'];
$row_not_global['users'][] = $row['user']; $row_not_global['users'][] = $row['user'];
} }
$export_array[] = $row_not_global; $export_array[] = $row_not_global;
$row_not_global = array();
} }
} }
if ($global) { if ($global) {
// Exam taken // Exam taken
$html .= '<td>'; $html .= '<td>';
$html .= $taken; $html .= $taken;
$global_row[]= $taken; $globalRow[]= $taken;
$html .= '</td>'; $html .= '</td>';
// Exam NOT taken // Exam NOT taken
$html .= '<td>'; $html .= '<td>';
$html .= $not_taken = $totalStudents - $taken; $html .= $not_taken = $totalStudents - $taken;
$global_row[]= $not_taken; $globalRow[]= $not_taken;
$html .= '</td>'; $html .= '</td>';
// Exam pass // Exam pass
@ -442,149 +667,30 @@ if (!empty($courseList) && is_array($courseList)) {
} }
$html .= $total_with_parameter_score; $html .= $total_with_parameter_score;
$global_row[]= $total_with_parameter_score; $globalRow[]= $total_with_parameter_score;
$html .= '</td>'; $html .= '</td>';
// Exam fail // Exam fail
$html .= '<td>'; $html .= '<td>';
$html .= $fail = $taken - $total_with_parameter_score; $html .= $fail = $taken - $total_with_parameter_score;
$global_row[]= $fail; $globalRow[]= $fail;
$html .= '</td>'; $html .= '</td>';
$html .= '<td>'; $html .= '<td>';
$html .= $totalStudents; $html .= $totalStudents;
$global_row[]= $totalStudents; $globalRow[]= $totalStudents;
$html .= '</td>'; $html .= '</td>';
$html .= '</tr>'; $html .= '</tr>';
$export_array_global[] = $global_row; $export_array_global[] = $globalRow;
$global_row = array();
}
} }
} else {
$html .= "<tr>
<td colspan='6'>
".get_lang('NoExercise')."
</td>
</tr>
";
}
} else {
$html .= "<tr>
<td colspan='6'>
".get_lang('NoExercise')."
</td>
</tr>
";
}
}
}
$html .= '</table>';
if (!$exportToXLS) {
echo $html;
}
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls'; return array(
if ($exportToXLS) { 'html' => $html,
if ($global) { 'export_array_global' => $export_array_global,
export_complete_report_xls($filename, $export_array_global); 'total_students' => $totalStudents
} else { );
export_complete_report_xls($filename, $export_array);
}
exit;
}
/**
* @param $a
* @param $b
* @return int
*/
function sort_user($a, $b) {
if (is_numeric($a['score']) && is_numeric($b['score'])) {
if ($a['score'] < $b['score']) {
return 1;
}
return 0;
}
return 1;
}
/**
* @param string $filename
* @param array $array
*/
function export_complete_report_xls($filename, $array)
{
global $charset, $global, $filter_score;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
$line = 0;
$column = 0; //skip the first column (row titles)
if ($global) {
$worksheet->write($line, $column, get_lang('Courses'));
$column++;
$worksheet->write($line, $column, get_lang('Exercises'));
$column++;
$worksheet->write($line, $column, get_lang('ExamTaken'));
$column++;
$worksheet->write($line, $column, get_lang('ExamNotTaken'));
$column++;
$worksheet->write($line, $column, sprintf(get_lang('ExamPassX'), $filter_score) . '%');
$column++;
$worksheet->write($line, $column, get_lang('ExamFail'));
$column++;
$worksheet->write($line, $column, get_lang('TotalStudents'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
$column++;
}
$line++;
}
$line++;
} else {
$worksheet->write($line,$column,get_lang('Exercises'));
$column++;
$worksheet->write($line,$column,get_lang('User'));
$column++;
$worksheet->write($line,$column,get_lang('Percentage'));
$column++;
$worksheet->write($line,$column,get_lang('Status'));
$column++;
$worksheet->write($line,$column,get_lang('Attempts'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
$worksheet->write($line,$column,html_entity_decode(strip_tags($row['exercise'])));
$column++;
foreach ($row['users'] as $key=>$user) {
$column = 1;
$worksheet->write($line,$column,html_entity_decode(strip_tags($user)));
$column++;
foreach ($row['results'][$key] as $result_item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($result_item)));
$column++;
}
$line++;
}
}
$line++;
}
$workbook->close();
exit;
} }
Display :: display_footer(); Display :: display_footer();

Loading…
Cancel
Save