esthetic typo fix (merge from 1.9)
[moodle.git] / mod / quiz / report / reportlib.php
CommitLineData
f33c438e 1<?php
2define('QUIZ_REPORT_DEFAULT_PAGE_SIZE', 30);
2badf2e6 3/**
4 * Get newest graded state or newest state for a number of attempts. Pass in the
5 * uniqueid field from quiz_attempt table not the id. Use question_state_is_graded
6 * function to check that the question is actually graded.
7 */
8function quiz_get_newgraded_states($attemptids, $idxattemptq = true){
9 global $CFG;
10 $attemptidlist = join($attemptids, ',');
11 $gradedstatesql = "SELECT qs.* FROM " .
12 "{$CFG->prefix}question_sessions qns, " .
13 "{$CFG->prefix}question_states qs " .
14 "WHERE qns.attemptid IN ($attemptidlist) AND " .
15 "qns.newgraded = qs.id";
16 $gradedstates = get_records_sql($gradedstatesql);
17 if ($idxattemptq){
18 $gradedstatesbyattempt = array();
19 foreach ($gradedstates as $gradedstate){
20 if (!isset($gradedstatesbyattempt[$gradedstate->attempt])){
21 $gradedstatesbyattempt[$gradedstate->attempt] = array();
22 }
23 $gradedstatesbyattempt[$gradedstate->attempt][$gradedstate->question] = $gradedstate;
24 }
25 return $gradedstatesbyattempt;
26 } else {
27 return $gradedstates;
28 }
29}
30/**
31 * Load the question data necessary in the reports.
32 * - Remove description questions.
33 * - Order questions in order that they are in the quiz
34 * - Add question numbers.
35 * - Add grade from quiz_questions_instance
36 */
37function quiz_report_load_questions($quiz){
38 global $CFG;
39 $questionlist = quiz_questions_in_quiz($quiz->questions);
40 //In fact in most cases the id IN $questionlist below is redundant
41 //since we are also doing a JOIN on the qqi table. But will leave it in
42 //since this double check will probably do no harm.
43 if (!$questions = get_records_sql("SELECT q.*, qqi.grade " .
44 "FROM {$CFG->prefix}question q, " .
45 "{$CFG->prefix}quiz_question_instances qqi " .
46 "WHERE q.id IN ($questionlist) AND " .
47 "qqi.question = q.id AND " .
48 "qqi.quiz =".$quiz->id)) {
49 print_error('No questions found');
50 }
51 //Now we have an array of questions from a quiz we work out there question nos and remove
52 //questions with zero length ie. description questions etc.
53 //also put questions in order.
54 $number = 1;
55 $realquestions = array();
56 $questionids = explode(',', $questionlist);
57 foreach ($questionids as $id) {
58 if ($questions[$id]->length) {
59 // Ignore questions of zero length
60 $realquestions[$id] = $questions[$id];
61 $realquestions[$id]->number = $number;
62 $number += $questions[$id]->length;
63 }
64 }
65 return $realquestions;
66}
f33c438e 67?>