[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This script renders the quiz statistics graph. 19 * 20 * It takes one parameter, the quiz_statistics.id. This is enough to identify the 21 * quiz etc. 22 * 23 * It plots a bar graph showing certain question statistics plotted against 24 * question number. 25 * 26 * @package quiz_statistics 27 * @copyright 2008 Jamie Pratt 28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 */ 30 31 require_once(dirname(__FILE__) . '/../../../../config.php'); 32 require_once($CFG->libdir . '/graphlib.php'); 33 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 34 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); 35 require_once($CFG->dirroot . '/mod/quiz/report/statistics/statisticslib.php'); 36 37 // Get the parameters. 38 $quizid = required_param('quizid', PARAM_INT); 39 $currentgroup = required_param('currentgroup', PARAM_INT); 40 $whichattempts = required_param('whichattempts', PARAM_INT); 41 42 $quiz = $DB->get_record('quiz', array('id' => $quizid), '*', MUST_EXIST); 43 $cm = get_coursemodule_from_instance('quiz', $quiz->id); 44 45 // Check access. 46 require_login($quiz->course, false, $cm); 47 $modcontext = context_module::instance($cm->id); 48 require_capability('quiz/statistics:view', $modcontext); 49 50 if (groups_get_activity_groupmode($cm)) { 51 $groups = groups_get_activity_allowed_groups($cm); 52 } else { 53 $groups = array(); 54 } 55 if ($currentgroup && !in_array($currentgroup, array_keys($groups))) { 56 print_error('groupnotamember', 'group'); 57 } 58 59 if (empty($currentgroup)) { 60 $groupstudents = array(); 61 } else { 62 $groupstudents = get_users_by_capability($modcontext, array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), 63 '', '', '', '', $currentgroup, '', false); 64 } 65 $qubaids = quiz_statistics_qubaids_condition($quizid, $groupstudents, $whichattempts); 66 67 // Load the rest of the required data. 68 $questions = quiz_report_get_significant_questions($quiz); 69 70 // Only load main question not sub questions. 71 $questionstatistics = $DB->get_records_select('question_statistics', 'hashcode = ? AND slot IS NOT NULL', 72 array($qubaids->get_hash_code())); 73 74 // Create the graph, and set the basic options. 75 $graph = new graph(800, 600); 76 $graph->parameter['title'] = ''; 77 78 $graph->parameter['y_label_left'] = '%'; 79 $graph->parameter['x_label'] = get_string('position', 'quiz_statistics'); 80 $graph->parameter['y_label_angle'] = 90; 81 $graph->parameter['x_label_angle'] = 0; 82 $graph->parameter['x_axis_angle'] = 60; 83 84 $graph->parameter['legend'] = 'outside-right'; 85 $graph->parameter['legend_border'] = 'black'; 86 $graph->parameter['legend_offset'] = 4; 87 88 $graph->parameter['bar_size'] = 1; 89 90 $graph->parameter['zero_axis'] = 'grayEE'; 91 92 // Configure what to display. 93 $fieldstoplot = array( 94 'facility' => get_string('facility', 'quiz_statistics'), 95 'discriminativeefficiency' => get_string('discriminative_efficiency', 'quiz_statistics') 96 ); 97 $fieldstoplotfactor = array('facility' => 100, 'discriminativeefficiency' => 1); 98 99 // Prepare the arrays to hold the data. 100 $xdata = array(); 101 foreach (array_keys($fieldstoplot) as $fieldtoplot) { 102 $ydata[$fieldtoplot] = array(); 103 $graph->y_format[$fieldtoplot] = array( 104 'colour' => quiz_statistics_graph_get_new_colour(), 105 'bar' => 'fill', 106 'shadow_offset' => 1, 107 'legend' => $fieldstoplot[$fieldtoplot] 108 ); 109 } 110 111 // Fill in the data for each question. 112 foreach ($questionstatistics as $questionstatistic) { 113 $number = $questions[$questionstatistic->slot]->number; 114 $xdata[$number] = $number; 115 116 foreach ($fieldstoplot as $fieldtoplot => $notused) { 117 $value = $questionstatistic->$fieldtoplot; 118 if (is_null($value)) { 119 $value = 0; 120 } 121 $value *= $fieldstoplotfactor[$fieldtoplot]; 122 123 $ydata[$fieldtoplot][$number] = $value; 124 } 125 } 126 127 // Sort the fields into order. 128 sort($xdata); 129 $graph->x_data = array_values($xdata); 130 131 foreach ($fieldstoplot as $fieldtoplot => $notused) { 132 ksort($ydata[$fieldtoplot]); 133 $graph->y_data[$fieldtoplot] = array_values($ydata[$fieldtoplot]); 134 } 135 $graph->y_order = array_keys($fieldstoplot); 136 137 // Find appropriate axis limits. 138 $max = 0; 139 $min = 0; 140 foreach ($fieldstoplot as $fieldtoplot => $notused) { 141 $max = max($max, max($graph->y_data[$fieldtoplot])); 142 $min = min($min, min($graph->y_data[$fieldtoplot])); 143 } 144 145 // Set the remaining graph options that depend on the data. 146 $gridresolution = 10; 147 $max = ceil($max / $gridresolution) * $gridresolution; 148 $min = floor($min / $gridresolution) * $gridresolution; 149 150 if ($max == $min) { 151 // Make sure there is some difference between min and max y values. 152 $max = $min + $gridresolution; 153 } 154 155 $gridlines = ceil(($max - $min) / $gridresolution) + 1; 156 157 $graph->parameter['y_axis_gridlines'] = $gridlines; 158 159 $graph->parameter['y_min_left'] = $min; 160 $graph->parameter['y_max_left'] = $max; 161 $graph->parameter['y_decimal_left'] = 0; 162 163 // Output the graph. 164 $graph->draw();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |