Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit bed436f084ba083c567a24074789dd5ceac5d340 1 parent e9686d7
Tim Hunt timhunt authored

Showing 1 changed file with 83 additions and 93 deletions. Show diff stats Hide diff stats

  1. +83 93 mod/quiz/report/overview/report.php
176 mod/quiz/report/overview/report.php
@@ -19,7 +19,7 @@ class quiz_report extends quiz_default_report {
19 19 function display($quiz, $cm, $course) {
20 20 global $CFG, $db;
21 21 // Define some strings
22   - $strreallydel = addslashes(get_string('deleteattemptcheck','quiz'));
  22 + $strreallydel = addslashes(get_string('deleteattemptcheck','quiz'));
23 23 $strtimeformat = get_string('strftimedatetime');
24 24
25 25 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -48,11 +48,11 @@ function display($quiz, $cm, $course) {
48 48 $reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions);
49 49 $qmsubselect = quiz_report_qm_filter_select($quiz);
50 50 $mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz', 'currentgroup'));
51   - if ($fromform = $mform->get_data()){
  51 + if ($fromform = $mform->get_data()) {
52 52 $attemptsmode = $fromform->attemptsmode;
53   - if ($qmsubselect){
  53 + if ($qmsubselect) {
54 54 //control is not on the form if
55   - //the grading method is not set
  55 + //the grading method is not set
56 56 //to grade one attempt per user eg. for average attempt grade.
57 57 $qmfilter = $fromform->qmfilter;
58 58 } else {
@@ -68,11 +68,11 @@ function display($quiz, $cm, $course) {
68 68 $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
69 69 $pagesize = get_user_preferences('quiz_report_pagesize', 0);
70 70 }
71   -
72   - if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup){
  71 +
  72 + if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL && $currentgroup) {
73 73 $attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
74 74 }
75   -
  75 +
76 76 if (!$reviewoptions->scores) {
77 77 $detailedmarks = 0;
78 78 }
@@ -81,16 +81,14 @@ function display($quiz, $cm, $course) {
81 81 }
82 82 // We only want to show the checkbox to delete attempts
83 83 // if the user has permissions and if the report mode is showing attempts.
84   - $candelete = has_capability('mod/quiz:deleteattempts', $context)
85   - && ($attemptsmode!= QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
86   -
  84 + $candelete = has_capability('mod/quiz:deleteattempts', $context)
  85 + && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
87 86
88 87 $displayoptions = array();
89 88 $displayoptions['attemptsmode'] = $attemptsmode;
90 89 $displayoptions['qmfilter'] = $qmfilter;
91 90 $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions + $displayoptions);
92 91
93   -
94 92 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
95 93 if (!$download) {
96 94 groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
@@ -104,14 +102,14 @@ function display($quiz, $cm, $course) {
104 102 }
105 103 }
106 104 $nostudents = false;
107   - if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)){
  105 + if (!$students = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','','','',false)) {
108 106 notify(get_string('nostudentsyet'));
109 107 $nostudents = true;
110 108 $studentslist = '';
111 109 } else {
112 110 $studentslist = join(',',array_keys($students));
113 111 }
114   -
  112 +
115 113 if (empty($currentgroup)) {
116 114 // all users who can attempt quizzes
117 115 $groupstudentslist = '';
@@ -119,7 +117,7 @@ function display($quiz, $cm, $course) {
119 117 $allowedlist = $studentslist;
120 118 } else {
121 119 // all users who can attempt quizzes and who are in the currently selected group
122   - if (!$groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','',$currentgroup,'',false)){
  120 + if (!$groupstudents = get_users_by_capability($context, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),'u.id,1','','','',$currentgroup,'',false)) {
123 121 notify(get_string('nostudentsingroup'));
124 122 $nostudents = true;
125 123 $groupstudents = array();
@@ -145,58 +143,55 @@ function display($quiz, $cm, $course) {
145 143 //twice.
146 144 }
147 145
148   - if (!$nostudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)){
149   -
  146 + if (!$nostudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
150 147 // Print information on the grading method and whether we are displaying
151   - //
152 148 if (!$download) { //do not print notices when downloading
153 149 if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
154 150 echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
155 151 }
156 152 }
157   -
  153 +
158 154 // Now check if asked download of data
159 155 if ($download) {
160 156 $filename = clean_filename("$course->shortname ".format_string($quiz->name,true));
161 157 }
162   -
  158 +
163 159 // Define table columns
164 160 $columns = array();
165 161 $headers = array();
166   -
167   -
  162 +
168 163 if (!$download && $candelete) {
169 164 $columns[]= 'checkbox';
170 165 $headers[]= NULL;
171 166 }
172   -
  167 +
173 168 if (!$download && $CFG->grade_report_showuserimage) {
174 169 $columns[]= 'picture';
175 170 $headers[]= '';
176 171 }
177   -
  172 +
178 173 $columns[]= 'fullname';
179 174 $headers[]= get_string('name');
180   -
  175 +
181 176 if ($CFG->grade_report_showuseridnumber) {
182 177 $columns[]= 'idnumber';
183 178 $headers[]= get_string('idnumber');
184 179 }
185   -
  180 +
186 181 $columns[]= 'timestart';
187 182 $headers[]= get_string('startedon', 'quiz');
188   -
  183 +
189 184 $columns[]= 'timefinish';
190 185 $headers[]= get_string('timecompleted','quiz');
191   -
  186 +
192 187 $columns[]= 'duration';
193 188 $headers[]= get_string('attemptduration', 'quiz');
194   -
  189 +
195 190 if ($showgrades) {
196 191 $columns[] = 'sumgrades';
197 192 $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade;
198 193 }
199   -
  194 +
200 195 if ($detailedmarks) {
201 196 // we want to display marks for all questions
202 197 $questions = quiz_report_load_questions($quiz);
@@ -207,43 +202,43 @@ function display($quiz, $cm, $course) {
207 202 $question->formattedname = strip_tags(format_string($question->name));
208 203 }
209 204 }
210   -
  205 +
211 206 if ($hasfeedback) {
212 207 $columns[] = 'feedbacktext';
213 208 $headers[] = get_string('feedback', 'quiz');
214 209 }
215   -
  210 +
216 211 if (!$download) {
217 212 // Set up the table
218   -
  213 +
219 214 $table = new flexible_table('mod-quiz-report-overview-report');
220   -
  215 +
221 216 $table->define_columns($columns);
222 217 $table->define_headers($headers);
223 218 $table->define_baseurl($reporturlwithdisplayoptions->out());
224   -
  219 +
225 220 $table->sortable(true);
226 221 $table->collapsible(true);
227   -
  222 +
228 223 $table->column_suppress('picture');
229 224 $table->column_suppress('fullname');
230 225 $table->column_suppress('idnumber');
231   -
  226 +
232 227 $table->no_sorting('feedbacktext');
233   -
  228 +
234 229 $table->column_class('picture', 'picture');
235 230 $table->column_class('fullname', 'bold');
236 231 $table->column_class('sumgrades', 'bold');
237   -
  232 +
238 233 $table->set_attribute('cellspacing', '0');
239 234 $table->set_attribute('id', 'attempts');
240 235 $table->set_attribute('class', 'generaltable generalbox');
241   -
  236 +
242 237 // Start working -- this is necessary as soon as the niceties are over
243 238 $table->setup();
244 239 } else if ($download =='ODS') {
245 240 require_once("$CFG->libdir/odslib.class.php");
246   -
  241 +
247 242 $filename .= ".ods";
248 243 // Creating a workbook
249 244 $workbook = new MoodleODSWorkbook("-");
@@ -273,7 +268,7 @@ function display($quiz, $cm, $course) {
273 268 $formatg->set_color('green');
274 269 $formatg->set_align('center');
275 270 // Here starts workshhet headers
276   -
  271 +
277 272 $colnum = 0;
278 273 foreach ($headers as $item) {
279 274 $myxls->write(0,$colnum,$item,$formatbc);
@@ -282,7 +277,7 @@ function display($quiz, $cm, $course) {
282 277 $rownum=1;
283 278 } else if ($download =='Excel') {
284 279 require_once("$CFG->libdir/excellib.class.php");
285   -
  280 +
286 281 $filename .= ".xls";
287 282 // Creating a workbook
288 283 $workbook = new MoodleExcelWorkbook("-");
@@ -311,7 +306,7 @@ function display($quiz, $cm, $course) {
311 306 $formatg->set_bold(1);
312 307 $formatg->set_color('green');
313 308 $formatg->set_align('center');
314   -
  309 +
315 310 $colnum = 0;
316 311 foreach ($headers as $item) {
317 312 $myxls->write(0,$colnum,$item,$formatbc);
@@ -320,17 +315,16 @@ function display($quiz, $cm, $course) {
320 315 $rownum=1;
321 316 } else if ($download=='CSV') {
322 317 $filename .= ".txt";
323   -
  318 +
324 319 header("Content-Type: application/download\n");
325 320 header("Content-Disposition: attachment; filename=\"$filename\"");
326 321 header("Expires: 0");
327 322 header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
328 323 header("Pragma: public");
329   -
  324 +
330 325 echo implode("\t", $headers)." \n";
331 326 }
332   -
333   -
  327 +
334 328 // Construct the SQL
335 329 $select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, ';
336 330 if ($qmsubselect) {
@@ -340,18 +334,18 @@ function display($quiz, $cm, $course) {
340 334 " ELSE 0 " .
341 335 "END) AS gradedattempt, ";
342 336 }
343   -
344   - $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' .
  337 +
  338 + $select .= 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, ' .
345 339 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, ' .
346 340 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
347   -
  341 +
348 342 // This part is the same for all cases - join users and quiz_attempts tables
349 343 $from = 'FROM '.$CFG->prefix.'user u ';
350 344 $from .= 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = '.$quiz->id;
351   - if ($qmsubselect && $qmfilter){
  345 + if ($qmsubselect && $qmfilter) {
352 346 $from .= ' AND '.$qmsubselect;
353 347 }
354   - switch ($attemptsmode){
  348 + switch ($attemptsmode) {
355 349 case QUIZ_REPORT_ATTEMPTS_ALL:
356 350 // Show all attempts, including students who are no longer in the course
357 351 $where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0';
@@ -369,10 +363,9 @@ function display($quiz, $cm, $course) {
369 363 $where = ' WHERE u.id IN (' .$allowedlist. ') AND (qa.preview = 0 OR qa.preview IS NULL)';
370 364 break;
371 365 }
372   -
  366 +
373 367 $countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)').')) '.$from.$where;
374   -
375   -
  368 +
376 369 // Add table joins so we can sort by question grade
377 370 // unfortunately can't join all tables necessary to fetch all grades
378 371 // to get the state for one question per attempt row we must join two tables
@@ -386,7 +379,7 @@ function display($quiz, $cm, $course) {
386 379 $matches = array();
387 380 foreach($sortparts as $sortpart) {
388 381 $sortpart = trim($sortpart);
389   - if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)){
  382 + if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)) {
390 383 $qid = intval($matches[1]);
391 384 $select .= ", qs$qid.grade AS qsgrade$qid, qs$qid.event AS qsevent$qid, qs$qid.id AS qsid$qid";
392 385 $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) {
398 391 $select .= ' ';
399 392 }
400 393 }
401   -
402   -
403   - if ($download){
  394 +
  395 + if ($download) {
404 396 $sort = '';
405 397 }
406 398 // Fix some wired sorting
@@ -409,25 +401,25 @@ function display($quiz, $cm, $course) {
409 401 } else {
410 402 $sort = ' ORDER BY '.$sort;
411 403 }
412   -
  404 +
413 405 if (!$download) {
414 406 // Add extra limits due to initials bar
415 407 if($table->get_sql_where()) {
416 408 $where .= ' AND '.$table->get_sql_where();
417 409 }
418   -
  410 +
419 411 if (!empty($countsql)) {
420 412 $totalinitials = count_records_sql($countsql);
421 413 if ($table->get_sql_where()) {
422 414 $countsql .= ' AND '.$table->get_sql_where();
423 415 }
424 416 $total = count_records_sql($countsql);
425   -
  417 +
426 418 }
427   -
  419 +
428 420 $table->pagesize($pagesize, $total);
429 421 }
430   -
  422 +
431 423 // Fetch the attempts
432 424 if (!$download) {
433 425 $attempts = get_records_sql($select.$from.$where.$sort,
@@ -435,7 +427,7 @@ function display($quiz, $cm, $course) {
435 427 } else {
436 428 $attempts = get_records_sql($select.$from.$where.$sort);
437 429 }
438   -
  430 +
439 431 // Build table rows
440 432 if (!$download) {
441 433 $table->initialbars($totalinitials>20);
@@ -445,41 +437,41 @@ function display($quiz, $cm, $course) {
445 437 //get all the attempt ids we want to display on this page
446 438 //or to export for download.
447 439 $attemptids = array();
448   - foreach ($attempts as $attempt){
449   - if ($attempt->attemptuniqueid > 0){
  440 + foreach ($attempts as $attempt) {
  441 + if ($attempt->attemptuniqueid > 0) {
450 442 $attemptids[] = $attempt->attemptuniqueid;
451 443 }
452 444 }
453 445 $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
454 446 }
455 447 foreach ($attempts as $attempt) {
456   -
  448 +
457 449 // Username columns.
458 450 $row = array();
459   - if (in_array('checkbox', $columns)){
460   - if ($attempt->attempt){
  451 + if (in_array('checkbox', $columns)) {
  452 + if ($attempt->attempt) {
461 453 $row[] = '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />';
462 454 } else {
463 455 $row[] = '';
464 456 }
465 457 }
466   - if (in_array('picture', $columns)){
  458 + if (in_array('picture', $columns)) {
467 459 $attempt->id = $attempt->userid;
468 460 $picture = print_user_picture($attempt, $course->id, NULL, false, true);
469 461 $row[] = $picture;
470 462 }
471   - if (!$download){
  463 + if (!$download) {
472 464 $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.
473 465 '&amp;course='.$course->id.'">'.fullname($attempt,has_capability('moodle/site:viewfullnames', $context)).'</a>';
474 466 $row[] = $userlink;
475 467 } else {
476 468 $row[] = fullname($attempt, has_capability('moodle/site:viewfullnames', $context));
477 469 }
478   -
479   - if (in_array('idnumber', $columns)){
  470 +
  471 + if (in_array('idnumber', $columns)) {
480 472 $row[] = $attempt->idnumber;
481 473 }
482   -
  474 +
483 475 // Timing columns.
484 476 if ($attempt->attempt) {
485 477 $startdate = userdate($attempt->timestart, $strtimeformat);
@@ -506,14 +498,14 @@ function display($quiz, $cm, $course) {
506 498 $row[] = '-';
507 499 $row[] = '-';
508 500 }
509   -
  501 +
510 502 // Grades columns.
511 503 if ($showgrades) {
512 504 if ($attempt->timefinish) {
513 505 $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
514 506 if (!$download) {
515 507 $gradehtml = '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$grade.'</a>';
516   - if ($qmsubselect && $attempt->gradedattempt){
  508 + if ($qmsubselect && $attempt->gradedattempt) {
517 509 $gradehtml = '<div class="highlight">'.$gradehtml.'</div>';
518 510 }
519 511 $row[] = $gradehtml;
@@ -523,9 +515,9 @@ function display($quiz, $cm, $course) {
523 515 } else {
524 516 $row[] = '-';
525 517 }
526   -
  518 +
527 519 }
528   -
  520 +
529 521 if($detailedmarks) {
530 522 if(empty($attempt->attempt)) {
531 523 foreach($questions as $question) {
@@ -550,7 +542,7 @@ function display($quiz, $cm, $course) {
550 542 }
551 543 }
552 544 }
553   -
  545 +
554 546 // Feedback column.
555 547 if ($hasfeedback) {
556 548 if ($attempt->timefinish) {
@@ -563,7 +555,7 @@ function display($quiz, $cm, $course) {
563 555 $table->add_data($row);
564 556 } else if ($download == 'Excel' or $download == 'ODS') {
565 557 $colnum = 0;
566   - foreach($row as $item){
  558 + foreach ($row as $item) {
567 559 $myxls->write($rownum,$colnum,$item,$format);
568 560 $colnum++;
569 561 }
@@ -575,14 +567,14 @@ function display($quiz, $cm, $course) {
575 567 }
576 568 //end of adding data from attempts data to table / download
577 569 //now add averages :
578   - if (!$download && $attempts){
579   -
  570 + if (!$download && $attempts) {
  571 +
580 572 $averagesql = "SELECT AVG(qg.grade) AS grade " .
581 573 "FROM {$CFG->prefix}quiz_grades qg " .
582 574 "WHERE quiz=".$quiz->id;
583   -
  575 +
584 576 $table->add_separator();
585   - if ($groupstudentslist){
  577 + if ($groupstudentslist) {
586 578 $groupaveragesql = $averagesql." AND qg.userid IN ($groupstudentslist)";
587 579 $groupaverage = get_record_sql($groupaveragesql);
588 580 $groupaveragerow = array('fullname' => get_string('groupavg', 'grades'),
@@ -603,7 +595,7 @@ function display($quiz, $cm, $course) {
603 595 $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
604 596 }
605 597 $table->add_data_keyed($overallaveragerow);
606   - }
  598 + }
607 599 if (!$download) {
608 600 // Start form
609 601 echo '<div id="tablecontainer">';
@@ -614,10 +606,10 @@ function display($quiz, $cm, $course) {
614 606 echo '<input type="hidden" name="sesskey" value="' . sesskey() . '">';
615 607 echo '</div>';
616 608 echo '<div>';
617   -
  609 +
618 610 // Print table
619 611 $table->print_html();
620   -
  612 +
621 613 // Print "Select all" etc.
622 614 if (!empty($attempts) && $candelete) {
623 615 echo '<table id="commands">';
@@ -633,7 +625,7 @@ function display($quiz, $cm, $course) {
633 625 // Close form
634 626 echo '</div>';
635 627 echo '</form></div>';
636   -
  628 +
637 629 if (!empty($attempts)) {
638 630 echo '<table class="boxaligncenter"><tr>';
639 631 echo '<td>';
@@ -668,10 +660,10 @@ function display($quiz, $cm, $course) {
668 660 }
669 661 if (!$download) {
670 662 // Print display options
671   - $mform->set_data($displayoptions +compact('detailedmarks', 'pagesize'));
  663 + $mform->set_data($displayoptions + compact('detailedmarks', 'pagesize'));
672 664 $mform->display();
673 665 //should be quicker than a COUNT to test if there is at least one record :
674   - if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)){
  666 + if ($showgrades && record_exists('quiz_grades', 'quiz', $quiz->id)) {
675 667 $imageurl = $CFG->wwwroot.'/mod/quiz/report/overview/overviewgraph.php?id='.$quiz->id;
676 668 print_heading(get_string('overviewreportgraph', 'quiz_overview'));
677 669 echo '<div class="mdl-align"><img src="'.$imageurl.'" alt="'.get_string('overviewreportgraph', 'quiz_overview').'" /></div>';
@@ -680,5 +672,3 @@ function display($quiz, $cm, $course) {
680 672 return true;
681 673 }
682 674 }
683   -
684   -?>

0 comments on commit bed436f

Please sign in to comment.
Something went wrong with that request. Please try again.