item analysis report contributed by Enrique Castro
[moodle.git] / mod / quiz / report / analysis / report.php
Content-type: text/html Official Moodle git projects - moodle.git/blame - mod/quiz/report/analysis/report.php


500 - Internal Server Error

Malformed UTF-8 character (fatal) at (eval 5) line 1, <$fd> line 250.
CommitLineData
0fc59399 1<?php // $Id$
2
3/// Item analysis displays a table of quiz questions and their performance
4
5 require_once("locallib.php");
6 require_once($CFG->libdir.'/tablelib.php');
7
8
9function stats_sumx($sum, $data){
10 $sum[0] += $data[0];
11 $sum[1] += $data[1];
12 return $sum;
13}
14
15function stats_sumx2($sum, $data){
16 $sum[0] += $data[0]*$data[0];
17 $sum[1] += $data[1]*$data[1];
18 return $sum;
19}
20
21function stats_sumxy($sum, $data){
22 $sum[0] += $data[0]*$data[1];
23 return $sum;
24}
25
26
27/// Item analysis displays a table of quiz questions and their performance
28
29class quiz_report extends quiz_default_report {
30
31 function display($quiz, $cm, $course) { /// This function just displays the report
32
33 global $CFG, $SESSION, $db, $QUIZ_QTYPES;
34 define(QUIZ_ALLATTEMPTS, 0);
35 define(QUIZ_HIGHESTATTEMPT, 1);
36 define(QUIZ_FIRSTATTEMPT, 2);
37 define(QUIZ_LASTATTEMPT, 3);
38
39 $strnoquiz = get_string('noquiz','quiz');
40 $strnoattempts = get_string('noattempts','quiz');
41 $strtimeformat = get_string('strftimedatetime');
42
43 if (!$quiz->questions) {
44 print_heading($strnoattempts);
45 return true;
46 }
47
48 /// Check to see if groups are being used in this quiz
49 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
50 $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&amp;mode=overview");
51 } else {
52 $currentgroup = false;
53 }
54
55 /// Get all users: teachers and students
56 if ($currentgroup) {
57 $users = get_group_users($currentgroup);
58 }
59 else {
60 $users = get_course_users($course->id);
61 }
62
63 /// Remove teachers
64 $teachers = get_course_teachers($course->id);
65 if(!empty($teachers)) {
66 $keys = array_keys($teachers);
67 }
68 foreach($keys as $key) {
69 unset($users[$key]);
70 }
71
72 if(empty($users)) {
73 print_heading($strnoattempts);
74 return true;
75 }
76
77 // set tTable and Analysis stats options
78 if(!isset($SESSION->quiz_analysis_table)) {
79 $SESSION->quiz_analysis_table = array('attemptselection' => 0, 'lowmarklimit' => 0);
80 }
81
82 foreach($SESSION->quiz_analysis_table as $option => $value) {
83 $urlparam = optional_param($option, NULL);
84 if($urlparam === NULL) {
85 $$option = $value;
86 }
87 else {
88 $$option = $SESSION->quiz_analysis_table[$option] = $urlparam;
89 }
90 }
91
92 $scorelimit = $quiz->grade * $lowmarklimit/ 100;
93
94 // ULPGC ecastro DEBUG this is here to allow for differnt SQL to select attempts
95 switch ($attemptselection) {
96 case QUIZ_ALLATTEMPTS :
97 $limit = '';
98 $group = '';
99 break;
100 case QUIZ_HIGHESTATTEMPT :
101 $limit = ', max(qa.sumgrades) ';
102 $group = ' GROUP BY qa.userid ';
103 break;
104 case QUIZ_FIRSTATTEMPT :
105 $limit = ', min(qa.timemodified) ';
106 $group = ' GROUP BY qa.userid ';
107 break;
108 case QUIZ_LASTATTEMPT :
109 $limit = ', max(qa.timemodified) ';
110 $group = ' GROUP BY qa.userid ';
111 break;
112 }
113
114 $select = 'SELECT qa.* '.$limit;
115 $sql = 'FROM '.$CFG->prefix.'user u '.
116 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid '.
117 'LEFT JOIN '.$CFG->prefix.'quiz_states qr ON qr.attempt = qa.id '. // es posible
118 'WHERE u.id IN ('.implode(',', array_keys($users)).') AND ( qa.quiz = '.$quiz->id.') '. // ULPGC ecastro
119 ' AND ( qa.sumgrades >= '.$scorelimit.' ) ';
120