Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/report/overview/overviewgraph.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 require_once(dirname(__FILE__) . '/../../../../config.php');
00028 require_once($CFG->libdir . '/graphlib.php');
00029 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
00030 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
00031 
00032 $quizid = required_param('id', PARAM_INT);
00033 $groupid = optional_param('groupid', 0, PARAM_INT);
00034 
00035 $quiz = $DB->get_record('quiz', array('id' => $quizid));
00036 $course = $DB->get_record('course', array('id' => $quiz->course));
00037 $cm = get_coursemodule_from_instance('quiz', $quizid);
00038 
00039 require_login($course, false, $cm);
00040 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00041 require_capability('mod/quiz:viewreports', $modcontext);
00042 
00043 if ($groupid && $groupmode = groups_get_activity_groupmode($cm)) {
00044     // Groups are being used
00045     $groups = groups_get_activity_allowed_groups($cm);
00046     if (!array_key_exists($groupid, $groups)) {
00047         print_error('errorinvalidgroup', 'group', null, $groupid);
00048     }
00049     $group = $groups[$groupid];
00050     $groupusers = get_users_by_capability($modcontext,
00051             array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),
00052             '', '', '', '', $group->id, '', false);
00053     if (!$groupusers) {
00054         print_error('nostudentsingroup');
00055     }
00056     $groupusers = array_keys($groupusers);
00057 } else {
00058     $groupusers = array();
00059 }
00060 
00061 $line = new graph(800, 600);
00062 $line->parameter['title'] = '';
00063 $line->parameter['y_label_left'] = get_string('participants');
00064 $line->parameter['x_label'] = get_string('grade');
00065 $line->parameter['y_label_angle'] = 90;
00066 $line->parameter['x_label_angle'] = 0;
00067 $line->parameter['x_axis_angle'] = 60;
00068 
00069 //following two lines seem to silence notice warnings from graphlib.php
00070 $line->y_tick_labels = null;
00071 $line->offset_relation = null;
00072 
00073 // will make size > 1 to get overlap effect when showing groups
00074 $line->parameter['bar_size'] = 1;
00075 // don't forget to increase spacing so that graph doesn't become one big block of colour
00076 $line->parameter['bar_spacing'] = 10;
00077 
00078 //pick a sensible number of bands depending on quiz maximum grade.
00079 $bands = $quiz->grade;
00080 while ($bands > 20 || $bands <= 10) {
00081     if ($bands > 50) {
00082         $bands /= 5;
00083     } else if ($bands > 20) {
00084         $bands /= 2;
00085     }
00086     if ($bands < 4) {
00087         $bands *= 5;
00088     } else if ($bands <= 10) {
00089         $bands *= 2;
00090     }
00091 }
00092 
00093 $bands = ceil($bands);
00094 $bandwidth = $quiz->grade / $bands;
00095 $bandlabels = array();
00096 for ($i = 1; $i <= $bands; $i++) {
00097     $bandlabels[] = quiz_format_grade($quiz, ($i - 1) * $bandwidth) . ' - ' .
00098             quiz_format_grade($quiz, $i * $bandwidth);
00099 }
00100 $line->x_data = $bandlabels;
00101 
00102 $line->y_format['allusers'] = array(
00103     'colour' => 'red',
00104     'bar' => 'fill',
00105     'shadow_offset' => 1,
00106     'legend' => get_string('allparticipants')
00107 );
00108 $line->y_data['allusers'] = quiz_report_grade_bands($bandwidth, $bands, $quizid, $groupusers);
00109 
00110 $line->y_order = array('allusers');
00111 
00112 $ymax = max($line->y_data['allusers']);
00113 $line->parameter['y_min_left'] = 0;  // start at 0
00114 $line->parameter['y_max_left'] = $ymax;
00115 $line->parameter['y_decimal_left'] = 0; // 2 decimal places for y axis.
00116 
00117 //pick a sensible number of gridlines depending on max value on graph.
00118 $gridlines = $ymax;
00119 while ($gridlines >= 10) {
00120     if ($gridlines >= 50) {
00121         $gridlines /= 5;
00122     } else {
00123         $gridlines /= 2;
00124     }
00125 }
00126 
00127 $line->parameter['y_axis_gridlines'] = $gridlines + 1;
00128 $line->draw();
 All Data Structures Namespaces Files Functions Variables Enumerations