Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

quiz overview MDL-23377 whitespace cleanup, before doing the real fix.

  • Loading branch information...
commit bed436f084ba083c567a24074789dd5ceac5d340 1 parent e9686d7
@timhunt timhunt authored
Showing with 83 additions and 93 deletions.
  1. +83 −93 mod/quiz/report/overview/report.php
View
176 mod/quiz/report/overview/report.php
@@ -19,7 +19,7 @@ class quiz_report extends quiz_default_report {
function display($quiz, $cm, $course) {
global $CFG, $db;
// Define some strings
- $strreallydel = addslashes(get_string('deleteattemptcheck','quiz'));
+ $strreallydel = addslashes(get_string('deleteattemptcheck','quiz'));
$strtimeformat = get_string('strftimedatetime');
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -48,11 +48,11 @@ function display($quiz, $cm, $course) {
$reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions);
$qmsubselect = quiz_report_qm_filter_select($quiz);
$mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz', 'currentgroup'));
- if ($fromform = $mform->get_data()){
+ if ($fromform = $mform->get_data()) {
$attemptsmode = $fromform->attemptsmode;
- if ($qmsubselect){
+ if ($qmsubselect) {
//control is not on the form if
- //the grading method is not set
+ //the grading method is not set
//to grade one attempt per user eg. for average attempt grade.
$qmfilter = $fromform->qmfilter;
} else {
@@ -68,11 +68,11 @@ function display($quiz, $cm, $course) {
$detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
}
-
- if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup){
+
+ if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup) {
$attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
}
-
+
if (!$reviewoptions->scores) {
$detailedmarks = 0;
}
@@ -81,16 +81,14 @@ function display($quiz, $cm, $course) {
}
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
- $candelete = has_capability('mod/quiz:deleteattempts', $context)
- && ($attemptsmode!= QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
-
+ $candelete = has_capability('mod/quiz:deleteattempts', $context)
+ && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions + $displayoptions);
-
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
if (!$download) {
groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
@@ -104,14 +102,14 @@ function display($quiz, $cm, $course) {
}
}
$nostudents = false;
- if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)){
+ if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)) {
notify(get_string('nostudentsyet'));
$nostudents = true;
$studentslist = '';
} else {
$studentslist = join(',',array_keys($students));
}
-
+
if (empty($currentgroup)) {
// all users who can attempt quizzes
$groupstudentslist = '';
@@ -119,7 +117,7 @@ function display($quiz, $cm, $course) {
$allowedlist = $studentslist;
} else {
// all users who can attempt quizzes and who are in the currently selected group
- if (!$groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','',$currentgroup,'',false)){
+ if (!$groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','',$currentgroup,'',false)) {
notify(get_string('nostudentsingroup'));
$nostudents = true;
$groupstudents = array();
@@ -145,58 +143,55 @@ function display($quiz, $cm, $course) {
//twice.
}
- if (!$nostudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)){
-
+ if (!$nostudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
// Print information on the grading method and whether we are displaying
- //
if (!$download) { //do not print notices when downloading
if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
}
}
-
+
// Now check if asked download of data
if ($download) {
$filename = clean_filename("$course->shortname ".format_string($quiz->name,true));
}
-
+
// Define table columns
$columns = array();
$headers = array();
-
-
+
if (!$download && $candelete) {
$columns[]= 'checkbox';
$headers[]= NULL;
}
-
+
if (!$download && $CFG->grade_report_showuserimage) {
$columns[]= 'picture';
$headers[]= '';
}
-
+
$columns[]= 'fullname';
$headers[]= get_string('name');
-
+
if ($CFG->grade_report_showuseridnumber) {
$columns[]= 'idnumber';
$headers[]= get_string('idnumber');
}
-
+
$columns[]= 'timestart';
$headers[]= get_string('startedon', 'quiz');
-
+
$columns[]= 'timefinish';
$headers[]= get_string('timecompleted','quiz');
-
+
$columns[]= 'duration';
$headers[]= get_string('attemptduration', 'quiz');
-
+
if ($showgrades) {
$columns[] = 'sumgrades';
$headers[] = get_string('grade', 'quiz').'/'.$quiz->grade;
}
-
+
if ($detailedmarks) {
// we want to display marks for all questions
$questions = quiz_report_load_questions($quiz);
@@ -207,43 +202,43 @@ function display($quiz, $cm, $course) {
$question->formattedname = strip_tags(format_string($question->name));
}
}
-
+
if ($hasfeedback) {
$columns[] = 'feedbacktext';
$headers[] = get_string('feedback', 'quiz');
}
-
+
if (!$download) {
// Set up the table
-
+
$table = new flexible_table('mod-quiz-report-overview-report');
-
+
$table->define_columns($columns);
$table->define_headers($headers);
$table->define_baseurl($reporturlwithdisplayoptions->out());
-
+
$table->sortable(true);
$table->collapsible(true);
-
+
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_suppress('idnumber');
-
+
$table->no_sorting('feedbacktext');
-
+
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'bold');
$table->column_class('sumgrades', 'bold');
-
+
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
-
+
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
} else if ($download =='ODS') {
require_once("$CFG->libdir/odslib.class.php");
-
+
$filename .= ".ods";
// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
@@ -273,7 +268,7 @@ function display($quiz, $cm, $course) {
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers
-
+
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc);
@@ -282,7 +277,7 @@ function display($quiz, $cm, $course) {
$rownum=1;
} else if ($download =='Excel') {
require_once("$CFG->libdir/excellib.class.php");
-
+
$filename .= ".xls";
// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
@@ -311,7 +306,7 @@ function display($quiz, $cm, $course) {
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
-
+
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc);
@@ -320,17 +315,16 @@ function display($quiz, $cm, $course) {
$rownum=1;
} else if ($download=='CSV') {
$filename .= ".txt";
-
+
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
-
+
echo implode("\t", $headers)." \n";
}
-
-
+
// Construct the SQL
$select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, ';
if ($qmsubselect) {
@@ -340,18 +334,18 @@ function display($quiz, $cm, $course) {
" ELSE 0 " .
"END) AS gradedattempt, ";
}
-
- $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' .
+
+ $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' .
'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, ' .
'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
-
+
// This part is the same for all cases - join users and quiz_attempts tables
$from = 'FROM '.$CFG->prefix.'user u ';
$from .= 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = '.$quiz->id;
- if ($qmsubselect && $qmfilter){
+ if ($qmsubselect && $qmfilter) {
$from .= ' AND '.$qmsubselect;
}
- switch ($attemptsmode){
+ switch ($attemptsmode) {
case QUIZ_REPORT_ATTEMPTS_ALL:
// Show all attempts, including students who are no longer in the course
$where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0';
@@ -369,10 +363,9 @@ function display($quiz, $cm, $course) {
$where = ' WHERE u.id IN (' .$allowedlist. ') AND (qa.preview = 0 OR qa.preview IS NULL)';
break;
}
-
+
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)').')) '.$from.$where;
-
-
+
// Add table joins so we can sort by question grade
// unfortunately can't join all tables necessary to fetch all grades
// to get the state for one question per attempt row we must join two tables
@@ -386,7 +379,7 @@ function display($quiz, $cm, $course) {
$matches = array();
foreach($sortparts as $sortpart) {
$sortpart = trim($sortpart);
- if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)){
+ if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)) {
$qid = intval($matches[1]);
$select .= ", qs$qid.grade AS qsgrade$qid, qs$qid.event AS qsevent$qid, qs$qid.id AS qsid$qid";
$from .= "LEFT JOIN {$CFG->prefix}question_sessions qns$qid ON qns$qid.attemptid = qa.uniqueid AND qns$qid.questionid = $qid ";
@@ -398,9 +391,8 @@ function display($quiz, $cm, $course) {
$select .= ' ';
}
}
-
-
- if ($download){
+
+ if ($download) {
$sort = '';
}
// Fix some wired sorting
@@ -409,25 +401,25 @@ function display($quiz, $cm, $course) {
} else {
$sort = ' ORDER BY '.$sort;
}
-
+
if (!$download) {
// Add extra limits due to initials bar
if($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
}
-
+
if (!empty($countsql)) {
$totalinitials = count_records_sql($countsql);
if ($table->get_sql_where()) {
$countsql .= ' AND '.$table->get_sql_where();
}
$total = count_records_sql($countsql);
-
+
}
-
+
$table->pagesize($pagesize, $total);
}
-
+
// Fetch the attempts
if (!$download) {
$attempts = get_records_sql($select.$from.$where.$sort,
@@ -435,7 +427,7 @@ function display($quiz, $cm, $course) {
} else {
$attempts = get_records_sql($select.$from.$where.$sort);
}
-
+
// Build table rows
if (!$download) {
$table->initialbars($totalinitials>20);
@@ -445,41 +437,41 @@ function display($quiz, $cm, $course) {
//get all the attempt ids we want to display on this page
//or to export for download.
$attemptids = array();
- foreach ($attempts as $attempt){
- if ($attempt->attemptuniqueid > 0){
+ foreach ($attempts as $attempt) {
+ if ($attempt->attemptuniqueid > 0) {
$attemptids[] = $attempt->attemptuniqueid;
}
}
$gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
}
foreach ($attempts as $attempt) {
-
+
// Username columns.
$row = array();
- if (in_array('checkbox', $columns)){
- if ($attempt->attempt){
+ if (in_array('checkbox', $columns)) {
+ if ($attempt->attempt) {
$row[] = '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />';
} else {
$row[] = '';
}
}
- if (in_array('picture', $columns)){
+ if (in_array('picture', $columns)) {
$attempt->id = $attempt->userid;
$picture = print_user_picture($attempt, $course->id, NULL, false, true);
$row[] = $picture;
}
- if (!$download){
+ if (!$download) {
$userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.
'&amp;course='.$course->id.'">'.fullname($attempt,has_capability('moodle/site:viewfullnames', $context)).'</a>';
$row[] = $userlink;
} else {
$row[] = fullname($attempt, has_capability('moodle/site:viewfullnames', $context));
}
-
- if (in_array('idnumber', $columns)){
+
+ if (in_array('idnumber', $columns)) {
$row[] = $attempt->idnumber;
}
-
+
// Timing columns.
if ($attempt->attempt) {
$startdate = userdate($attempt->timestart, $strtimeformat);
@@ -506,14 +498,14 @@ function display($quiz, $cm, $course) {
$row[] = '-';
$row[] = '-';
}
-
+
// Grades columns.
if ($showgrades) {
if ($attempt->timefinish) {
$grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
if (!$download) {
$gradehtml = '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$grade.'</a>';
- if ($qmsubselect && $attempt->gradedattempt){
+ if ($qmsubselect && $attempt->gradedattempt) {
$gradehtml = '<div class="highlight">'.$gradehtml.'</div>';
}
$row[] = $gradehtml;
@@ -523,9 +515,9 @@ function display($quiz, $cm, $course) {
} else {
$row[] = '-';
}
-
+
}
-
+
if($detailedmarks) {
if(empty($attempt->attempt)) {
foreach($questions as $question) {
@@ -550,7 +542,7 @@ function display($quiz, $cm, $course) {
}
}
}
-
+
// Feedback column.
if ($hasfeedback) {
if ($attempt->timefinish) {
@@ -563,7 +555,7 @@ function display($quiz, $cm, $course) {
$table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
- foreach($row as $item){
+ foreach ($row as $item) {
$myxls->write($rownum,$colnum,$item,$format);
$colnum++;
}
@@ -575,14 +567,14 @@ function display($quiz, $cm, $course) {
}
//end of adding data from attempts data to table / download
//now add averages :
- if (!$download && $attempts){
-
+ if (!$download && $attempts) {
+
$averagesql = "SELECT AVG(qg.grade) AS grade " .
"FROM {$CFG->prefix}quiz_grades qg " .
"WHERE quiz=".$quiz->id;
-
+
$table->add_separator();
- if ($groupstudentslist){
+ if ($groupstudentslist) {
$groupaveragesql = $averagesql." AND qg.userid IN ($groupstudentslist)";
$groupaverage = get_record_sql($groupaveragesql);
$groupaveragerow = array('fullname' => get_string('groupavg', 'grades'),
@@ -603,7 +595,7 @@ function display($quiz, $cm, $course) {
$overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
}
$table->add_data_keyed($overallaveragerow);
- }
+ }
if (!$download) {
// Start form
echo '<div id="tablecontainer">';
@@ -614,10 +606,10 @@ function display($quiz, $cm, $course) {
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '">';
echo '</div>';
echo '<div>';
-
+
// Print table
$table->print_html();
-
+
// Print "Select all" etc.
if (!empty($attempts) && $candelete) {
echo '<table id="commands">';
@@ -633,7 +625,7 @@ function display($quiz, $cm, $course) {
// Close form
echo '</div>';
echo '</form></div>';
-
+
if (!empty($attempts)) {
echo '<table class="boxaligncenter"><tr>';
echo '<td>';
@@ -668,10 +660,10 @@ function display($quiz, $cm, $course) {
}
if (!$download) {
// Print display options
- $mform->set_data($displayoptions +compact('detailedmarks', 'pagesize'));
+ $mform->set_data($displayoptions + compact('detailedmarks', 'pagesize'));
$mform->display();
//should be quicker than a COUNT to test if there is at least one record :
- if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)){
+ if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)) {
$imageurl = $CFG->wwwroot.'/mod/quiz/report/overview/overviewgraph.php?id='.$quiz->id;
print_heading(get_string('overviewreportgraph', 'quiz_overview'));
echo '<div class="mdl-align"><img src="'.$imageurl.'" alt="'.get_string('overviewreportgraph', 'quiz_overview').'" /></div>';
@@ -680,5 +672,3 @@ function display($quiz, $cm, $course) {
return true;
}
}
-
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.