[moodle] / contrib / plugins / grade / report / stats / lib.php Repository:

Annotation of /contrib/plugins/grade/report/stats/lib.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (view) (download)

1 : dservos 1.1 <?php
2 : dservos 1.2 ///////////////////////////////////////////////////////////////////////////
3 :     // //
4 :     // NOTICE OF COPYRIGHT //
5 :     // //
6 :     // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 :     // http://moodle.org //
8 :     // //
9 :     // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
10 :     // //
11 :     // This program is free software; you can redistribute it and/or modify //
12 :     // it under the terms of the GNU General Public License as published by //
13 :     // the Free Software Foundation; either version 2 of the License, or //
14 :     // (at your option) any later version. //
15 :     // //
16 :     // This program is distributed in the hope that it will be useful, //
17 :     // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 :     // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 :     // GNU General Public License for more details: //
20 :     // //
21 :     // http://www.gnu.org/copyleft/gpl.html //
22 :     // //
23 :     ///////////////////////////////////////////////////////////////////////////
24 : dservos 1.1
25 :     /**
26 :     * File in which the grade_report_stats class is defined.
27 : dservos 1.2 * @package gradebook
28 : dservos 1.1 */
29 :    
30 :     require_once($CFG->dirroot . '/grade/report/lib.php');
31 :     require_once($CFG->libdir.'/tablelib.php');
32 : dservos 1.2
33 :     foreach (glob($CFG->dirroot . '/grade/report/stats/statistics/stat_*.php') as $filename) {
34 :     require_once($filename);
35 :     }
36 : dservos 1.1
37 :     /**
38 :     * Class providing the API for the stats report, including harvesters,
39 :     * reports, and adaptor methods for turing grades in to statistics.
40 :     * @uses grade_report
41 :     * @package gradebook
42 :     */
43 :     class grade_report_stats extends grade_report {
44 :     /**
45 :     * Capability to view hidden items.
46 : dservos 1.2 * @var bool $canviewhidden
47 : dservos 1.1 */
48 :     private $canviewhidden;
49 :    
50 :     /**
51 :     * Grade objects of users in the course
52 :     * @var array $grades
53 :     */
54 : dservos 1.2 private $grades = array();
55 : dservos 1.1
56 :     /**
57 :     * Array of users final grades affter filtered based on
58 :     * settings.
59 :     * @var array $finalgrades
60 :     */
61 : dservos 1.2 private $finalgrades = array();
62 : dservos 1.1
63 :     /**
64 :     * The value returned from each statistic.
65 :     * @var array $reportedstats
66 :     */
67 : dservos 1.2 private $reportedstats = array();
68 : dservos 1.1
69 :     /**
70 :     * The html of the report to output.
71 :     * @var string $html
72 :     */
73 :     public $html;
74 :    
75 :     /**
76 :     * The table class used to make the html of the report.
77 :     * @var object $table
78 :     */
79 :     private $table;
80 : dservos 1.2
81 :     /**
82 :     * Array of clases that extend stats witch have the logic to
83 :     * generate the statstics.
84 :     * @var array $stats
85 :     */
86 : dservos 1.5 private static $stats = array();
87 : dservos 1.1
88 :     /**
89 :     * Constructor. Initialises grade_tree, sets up group, baseurl
90 :     * and pbarurl.
91 :     * @param int $courseid the coures id for the report
92 :     * @param object $gpr grade plugin tracking object
93 :     * @context string $context
94 :     */
95 :     public function __construct($courseid, $gpr, $context) {
96 :     global $CFG;
97 :     parent::__construct($courseid, $gpr, $context, null);
98 :    
99 :     $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
100 :    
101 :     /// Set up urls
102 :     $this->baseurl = 'index.php?id=' . $this->courseid;
103 :     $this->pbarurl = 'index.php?id=' . $this->courseid;
104 :    
105 :     /// Set the position of the aggregation categorie based on pref
106 :     $switch = $this->get_pref('stats', 'aggregationposition');
107 :     if ($switch == '' && isset($CFG->grade_aggregationposition)) {
108 :     $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
109 :     }
110 :    
111 :     /// Build grade tree
112 :     $this->gtree = new grade_tree($this->courseid, false, $switch);
113 :    
114 :     /// Set up Groups
115 :     if ($this->get_pref('stats', 'showgroups') || is_null($this->get_pref('stats', 'showgroups'))) {
116 : dservos 1.6 $this->setup_groups();
117 : dservos 1.1 }
118 : dservos 1.2
119 : dservos 1.6 /// Load stats classes from ./statistics
120 : dservos 1.2 $this->load_stats();
121 : dservos 1.1 }
122 :    
123 : dservos 1.2 /**
124 :     * Load all the stats classes into $stats.
125 :     * Looks in /statistics and trys to make an instence of any
126 :     * class that is in a file that starts with stats_ and extends
127 :     * stats directly.
128 :     * @param bool $return if true return stats array, else store in $this->stats
129 :     * @returns array array of clases that extend stats
130 :     */
131 :     private function load_stats($return=false) {
132 :     global $CFG;
133 :    
134 :     $stats = array();
135 :    
136 :     foreach (glob($CFG->dirroot . '/grade/report/stats/statistics/stat_*.php') as $path) {
137 :     $filename = substr(basename($path, '.php'), 5);
138 :    
139 :     if(class_exists($filename) && get_parent_class($class = new $filename) == 'stats' ) {
140 :     $stats[$filename] = $class;
141 :     }
142 :     }
143 :    
144 :     if($return) {
145 :     return $stats;
146 :     } else {
147 : dservos 1.5 grade_report_stats::$stats = $stats;
148 : dservos 1.2 }
149 :     }
150 :    
151 :     /**
152 :     * Returns the current stats being used in the report or if no stats are
153 :     * set, it returns the stats as whould be loaded by load_stats.
154 :     * @returns array array of classes that extend stats
155 :     */
156 :     public function get_stats() {
157 : dservos 1.5 if(!isset(grade_report_stats::$stats) || is_null(grade_report_stats::$stats) || empty(grade_report_stats::$stats)) {
158 : dservos 1.2 return grade_report_stats::load_stats(true);
159 :     } else {
160 : dservos 1.5 return grade_report_stats::$stats;
161 : dservos 1.2 }
162 :     }
163 :    
164 :     /// Added to keep grade_report happy
165 : dservos 1.1 public function process_data($data){}
166 :     public function process_action($target, $action){}
167 :    
168 :     /**
169 :     * Based on load user function from grader report.
170 :     * Pulls out the userids of the users to be used in the stats.
171 :     * @return array array of user ids to use in stats
172 :     */
173 :     public function load_users() {
174 :     global $CFG, $DB;
175 :    
176 :     if(isset($DB) && !is_null($DB)) {
177 :     $params = array();
178 :     list($usql, $gbr_params) = $DB->get_in_or_equal(explode(',', $this->gradebookroles));
179 :    
180 :     $sql = "SELECT u.id
181 :     FROM {user} u
182 :     JOIN {role_assignments} ra ON u.id = ra.userid
183 :     $this->groupsql
184 :     WHERE ra.roleid $usql
185 :     $this->groupwheresql
186 :     AND ra.contextid ".get_related_contexts_string($this->context);
187 :    
188 :     $params = array_merge($gbr_params, $this->groupwheresql_params);
189 :     $this->users = $DB->get_records_sql($sql, $params);
190 :     } else {
191 :     $sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
192 :     FROM {$CFG->prefix}user u
193 :     JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
194 :     $this->groupsql
195 :     WHERE ra.roleid in ($this->gradebookroles)
196 :     $this->groupwheresql
197 :     AND ra.contextid ".get_related_contexts_string($this->context);
198 :    
199 :     $this->users = get_records_sql($sql);
200 :     }
201 :    
202 :     if (empty($this->users)) {
203 :     $this->userselect = '';
204 :     $this->users = array();
205 : dservos 1.3 $this->userselect_params = array();
206 : dservos 1.1 } else {
207 :     if(isset($DB) && !is_null($DB)) {
208 :     list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users));
209 :     $this->userselect = "AND g.userid $usql";
210 :     $this->userselect_params = $params;
211 :     }else{
212 :     $this->userselect = 'AND g.userid in ('.implode(',', array_keys($this->users)).')';
213 :     }
214 :     }
215 :    
216 :     return $this->users;
217 :     }
218 :    
219 :     /**
220 :     * Encode an array of stat's data in to a stirng so it can
221 :     * be put in the get part of a url.
222 :     * @param arrray $array array of data to encode
223 :     * @param object $item grade_item to use to fromat stats
224 :     * @param object $stat stats object to use to format stats
225 :     * @return string encoded string
226 :     */
227 : dservos 1.2 private function encode_array(array $array, $item, $stat) {
228 : dservos 1.1 $string = '';
229 :    
230 :     /// Encode each elment by puting a delimiter and base64 encoding it.
231 :     foreach($array as $id=>$data) {
232 :     $string .= addslashes(grade_format_gradevalue($data, $item, true, $stat->displaytype, $stat->decimals)) . '"';
233 :     }
234 :     return strtr(base64_encode($string), '+/=', '-_,');
235 :     }
236 :    
237 :     /**
238 :     * Harvest the grades from the data base and build the finalgrades array.
239 :     * Filters out hidden, locked and null grades based on users settings.
240 :     * Partly based on grader reports load_final_grades function.
241 :     */
242 :     public function harvest_data() {
243 :     global $CFG, $DB;
244 :    
245 : dservos 1.2 $params = array();
246 :    
247 : dservos 1.1 if(isset($DB) && !is_null($DB)) {
248 :     $params = array_merge(array($this->courseid), $this->userselect_params);
249 :    
250 :     /// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
251 :     $sql = "SELECT g.*
252 :     FROM {grade_items} gi,
253 :     {grade_grades} g
254 :     WHERE g.itemid = gi.id AND gi.courseid = ? {$this->userselect}";
255 :    
256 :     $grades = $DB->get_records_sql($sql, $params);
257 :     } else {
258 :     /// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
259 :     $sql = "SELECT g.*
260 :     FROM {$CFG->prefix}grade_items gi,
261 :     {$CFG->prefix}grade_grades g
262 :     WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}";
263 :    
264 :     $grades = get_records_sql($sql);
265 :     }
266 :    
267 :     $userids = array_keys($this->users);
268 :    
269 :     if ($grades) {
270 :     foreach ($grades as $graderec) {
271 :     if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->items)) { // some items may not be present!!
272 :     $this->grades[$graderec->itemid][$graderec->userid] = new grade_grade($graderec, false);
273 :     $this->grades[$graderec->itemid][$graderec->userid]->grade_item =& $this->gtree->items[$graderec->itemid]; // db caching
274 :     }
275 :     }
276 :     }
277 :    
278 :     /// prefil grades that do not exist yet
279 :     foreach ($userids as $userid) {
280 :     foreach ($this->gtree->items as $itemid=>$unused) {
281 :     if (!isset($this->grades[$itemid][$userid])) {
282 :     $this->grades[$itemid][$userid] = new grade_grade();
283 :     $this->grades[$itemid][$userid]->itemid = $itemid;
284 :     $this->grades[$itemid][$userid]->userid = $userid;
285 :     $this->grades[$itemid][$userid]->grade_item =& $this->gtree->items[$itemid]; // db caching
286 :     }
287 :     }
288 :     }
289 :    
290 :     $this->finalgrades = array();
291 :    
292 :     /// Build finalgrades array and filliter out unwanted grades.
293 :     foreach ($this->gtree->items as $id=>$item) {
294 :     if(($item->gradetype == GRADE_TYPE_SCALE && ($this->get_pref('stats', 'showscaleitems') || is_null($this->get_pref('stats', 'showscaleitems'))))
295 :     || ($item->gradetype == GRADE_TYPE_VALUE && ($this->get_pref('stats', 'showvalueitems') || is_null($this->get_pref('stats', 'showvalueitems'))))) {
296 :     $this->finalgrades[$id] = array();
297 :     $i = 0;
298 :    
299 :     if(isset($this->grades[$id]) && !is_null($this->grades[$id])) {
300 :     foreach ($this->grades[$id] as $grade) {
301 : dservos 1.6 if( (($grade->is_hidden() && $this->canviewhidden && ($this->get_pref('stats', 'usehidden') || is_null($this->get_pref('stats', 'usehidden')))) || !$grade->is_hidden())
302 : dservos 1.1 && (($grade->is_locked() && ($this->get_pref('stats', 'uselocked') || is_null($this->get_pref('stats', 'uselocked')))) || !$grade->is_locked())) {
303 :     if($this->get_pref('stats', 'incompleasmin') && is_null($grade->finalgrade)) {
304 :     $this->finalgrades[$id][$i] = $item->grademin;
305 :     $i++;
306 :     } elseif(!is_null($grade->finalgrade)) {
307 :     $this->finalgrades[$id][$i] = $grade->finalgrade;
308 :     $i++;
309 :     }
310 :     }
311 :     }
312 :     }
313 :     }
314 :     }
315 :     }
316 :    
317 :     /**
318 :     * Runs grades for each item threw the report functions
319 :     * of each stats class in $stats and stores the values in
320 :     * reportedstats.
321 :     */
322 :     public function report_data() {
323 :     $this->reportedstats = array();
324 :    
325 : dservos 1.5 foreach(grade_report_stats::$stats as $name=>$stat) {
326 : dservos 1.6 if(($stat->capability == null || has_capability($stat->capability, $this->context)) && ($this->get_pref('stats', $name) || is_null($this->get_pref('stats', $name)))) {
327 : dservos 1.1 $this->reportedstats[$name] = array();
328 :    
329 :     foreach($this->finalgrades as $itemid=>$item) {
330 :     sort($item);
331 :     if(count($item) > 0) {
332 :     $this->reportedstats[$name][$itemid] = $stat->report_data($item, $this->gtree->items[$itemid]);
333 :     } else {
334 :     $this->reportedstats[$name][$itemid] = null;
335 :     }
336 :     }
337 :     }
338 :     }
339 :     }
340 :    
341 :     /**
342 :     * Take the reported data and adapt it in to HTML to output.
343 :     * HTML is stored in html.
344 :     * TODO: Deal with tables growing to wide.
345 :     * TODO: Make it look nice.
346 :     */
347 : dservos 1.3 public function adapt_data($printerversion = false) {
348 : dservos 1.2 global $CFG;
349 : dservos 1.1
350 : dservos 1.3 $inverted = $this->get_pref('stats', 'showinverted');
351 :    
352 : dservos 1.1 /// Set up table arrays
353 :     $tablecolumns = array('statistic');
354 :     $tableheaders = array($this->get_lang_string('statistic', 'gradereport_stats'));
355 :    
356 :     /// Loop threw items and build arrays
357 : dservos 1.3 if ($inverted) {
358 :     if($this->get_pref('stats', 'showranges')) {
359 :     array_push($tablecolumns, 'range');
360 :     array_push($tableheaders, $this->get_lang_string('range', 'gradereport_stats'));
361 :     }
362 :    
363 :     foreach($this->reportedstats as $name=>$data) {
364 :     array_push($tablecolumns, $name);
365 : dservos 1.5 array_push($tableheaders, grade_report_stats::$stats[$name]->name);
366 : dservos 1.3 }
367 :    
368 :     if($this->get_pref('stats', 'shownumgrades')) {
369 :     array_push($tablecolumns, 'num_grades');
370 :     array_push($tableheaders, $this->get_lang_string('num_grades', 'gradereport_stats'));
371 :     }
372 :     } else {
373 :     /// Set up range column and number of grades column
374 :     $ranges = array(format_text('<strong>' . $this->get_lang_string('range', 'gradereport_stats') . '</strong>', FORMAT_HTML));
375 :     $numgrades = array(format_text('<strong>' . $this->get_lang_string('num_grades', 'gradereport_stats') . '</strong>', FORMAT_HTML));
376 :    
377 :     foreach($this->finalgrades as $itemid=>$grades) {
378 :     array_push($tablecolumns, $itemid);
379 :     array_push($tableheaders, format_text($this->gtree->items[$itemid]->get_name(), FORMAT_HTML));
380 :     array_push($ranges, format_text('<strong>' . grade_format_gradevalue($this->gtree->items[$itemid]->grademin, $this->gtree->items[$itemid], true) . '-' . grade_format_gradevalue($this->gtree->items[$itemid]->grademax, $this->gtree->items[$itemid], true) . '</strong>' , FORMAT_HTML));
381 :     array_push($numgrades, format_text(count($grades), FORMAT_HTML));
382 :     }
383 : dservos 1.1 }
384 :    
385 :     /// Set up flexible table
386 :     $this->table = new flexible_table('grade-report-stats-' . $this->courseid);
387 :     $this->table->define_columns($tablecolumns);
388 : dservos 1.3 $this->table->define_headers($tableheaders);
389 :     if ($printerversion) {
390 :     $this->table->collapsible(false);
391 :     $this->table->set_attribute('cellspacing', '1');
392 :     $this->table->set_attribute('border', '1');
393 :     } else {
394 :     $this->table->define_baseurl($this->baseurl);
395 :     $this->table->collapsible(true);
396 :     $this->table->set_attribute('cellspacing', '1');
397 :     $this->table->set_attribute('id', 'stats-grade');
398 :     $this->table->set_attribute('class', 'grade-report-stats gradestable flexible');
399 :     }
400 : dservos 1.1 $this->table->setup();
401 :    
402 :     /// If ranges are being shown add them to the table
403 : dservos 1.3 if(!$inverted){
404 :     if ($this->get_pref('stats', 'showranges')){
405 :     $this->table->add_data($ranges);
406 :     $this->table->add_separator();
407 :     }
408 : dservos 1.1 }
409 :    
410 :     /// Loop threw all the reported data and format it in to cells
411 :     /// If stat retured an array of values display the elements or
412 :     /// make a link to a popup with the data in it.
413 : dservos 1.3 if($inverted) {
414 :     foreach($this->finalgrades as $itemid=>$grades) {
415 :     $item = $this->gtree->items[$itemid];
416 :     $row = array(format_text('<strong>' . $item->get_name() . '</strong>' , FORMAT_HTML));
417 :    
418 :     if($this->get_pref('stats', 'showranges')) {
419 :     array_push($row, format_text('<strong>' . grade_format_gradevalue($item->grademin, $item, true) . '-' . grade_format_gradevalue($item->grademax, $item, true) . '</strong>' , FORMAT_HTML));
420 :     }
421 : dservos 1.1
422 : dservos 1.3 foreach($this->reportedstats as $name=>$data) {
423 :     $stat = $data[$itemid];
424 :    
425 :     if(!is_array($stat)) {
426 : dservos 1.5 array_push($row, format_text(grade_format_gradevalue($stat, $item, true, grade_report_stats::$stats[$name]->displaytype, grade_report_stats::$stats[$name]->decimals), FORMAT_HTML));
427 : dservos 1.3 } else {
428 :     $statstring = "";
429 : dservos 1.1
430 : dservos 1.3 for($i = 0; $i < 2; $i++) {
431 :     if($i >= count($stat)) {
432 :     break;
433 :     }
434 : dservos 1.5 $statstring .= grade_format_gradevalue($stat[$i], $item, true, grade_report_stats::$stats[$name]->displaytype, grade_report_stats::$stats[$name]->decimals) . ', ';
435 : dservos 1.3 }
436 :    
437 :     if($i < count($stat)) {
438 :     if(!$printerversion) {
439 : dservos 1.5 $statstring = "<a href=\"#\" onClick=\"javascript:window.open('{$CFG->wwwroot}/grade/report/stats/arrayview.php?id={$this->courseid}&data={$this->encode_array($stat, $item, grade_report_stats::$stats[$name])}','{$this->get_lang_string('moredata', 'gradereport_stats')}','width=300,height=500,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes');\">". format_text($statstring, FORMAT_HTML) . '....</a>';
440 : dservos 1.3 } else {
441 :     $statstring .= '...';
442 :     }
443 :     } else {
444 :     $statstring = substr($statstring, 0, strlen($statstring) - 2);
445 : dservos 1.1 }
446 : dservos 1.3 array_push($row, $statstring);
447 : dservos 1.1 }
448 : dservos 1.3 }
449 :    
450 :     if($this->get_pref('stats', 'shownumgrades')) {
451 :     array_push($row, format_text(count($grades), FORMAT_HTML));
452 :     }
453 :    
454 :     $this->table->add_data($row);
455 :     }
456 :     } else {
457 :     foreach($this->reportedstats as $name=>$data) {
458 : dservos 1.5 $row = array(format_text('<strong>' . grade_report_stats::$stats[$name]->name . '</strong>', FORMAT_HTML));
459 : dservos 1.3
460 :     foreach($data as $itemid=>$stat) {
461 :     if(!is_array($stat)) {
462 : dservos 1.5 array_push($row, format_text(grade_format_gradevalue($stat, $this->gtree->items[$itemid], true, grade_report_stats::$stats[$name]->displaytype, grade_report_stats::$stats[$name]->decimals), FORMAT_HTML));
463 : dservos 1.3 } else {
464 :     $statstring = "";
465 :    
466 :     for($i = 0; $i < 2; $i++) {
467 :     if($i >= count($stat)) {
468 :     break;
469 :     }
470 : dservos 1.5 $statstring .= grade_format_gradevalue($stat[$i], $this->gtree->items[$itemid], true, grade_report_stats::$stats[$name]->displaytype, grade_report_stats::$stats[$name]->decimals) . ', ';
471 : dservos 1.3 }
472 : dservos 1.1
473 : dservos 1.3 if($i < count($stat)) {
474 :     if(!$printerversion) {
475 : dservos 1.5 $statstring = "<a href=\"#\" onClick=\"javascript:window.open('{$CFG->wwwroot}/grade/report/stats/arrayview.php?id={$this->courseid}&data={$this->encode_array($stat, $this->gtree->items[$itemid], grade_report_stats::$stats[$name])}','{$this->get_lang_string('moredata', 'gradereport_stats')}','width=300,height=500,menubar=no,status=no,location=no,directories=no,toolbar=no,scrollbars=yes');\">". format_text($statstring, FORMAT_HTML) . '....</a>';
476 : dservos 1.3 } else {
477 :     $statstring .= '...';
478 :     }
479 :     } else {
480 :     $statstring = substr($statstring, 0, strlen($statstring) - 2);
481 :     }
482 :     array_push($row, $statstring);
483 : dservos 1.1 }
484 :     }
485 : dservos 1.3 $this->table->add_data($row);
486 : dservos 1.1 }
487 :     }
488 :    
489 :     /// If the number of grades is being shown add it to the table.
490 : dservos 1.3 if(!$inverted) {
491 :     if ($this->get_pref('stats', 'shownumgrades')){
492 :     $this->table->add_separator();
493 :     $this->table->add_data($numgrades);
494 :     }
495 : dservos 1.1 }
496 :    
497 :     /// Build html
498 :     ob_start();
499 :     if($this->currentgroup == 0) {
500 : dservos 1.2 echo format_text('<strong>Group:</strong> All participants', FORMAT_HTML);
501 : dservos 1.1 } else {
502 : dservos 1.2 echo format_text('<strong>Group:</strong> ' . groups_get_group_name($this->currentgroup), FORMAT_HTML);
503 : dservos 1.1 }
504 :     $this->table->print_html();
505 :     $this->html = ob_get_clean();
506 :     }
507 :    
508 :     /**
509 :     * Builds HTML for toggles on top of report.
510 :     * Based on grader report get_toggles_html
511 :     * @return string html code for toggles.
512 :     */
513 :     public function get_toggles_html() {
514 :     global $CFG, $USER;
515 :    
516 :     $html = '<div id="stats-report-toggles" style="vertical-align: text-top; text-align: center;">';
517 :     $html .= $this->print_toggle('numgrades', true);
518 :     $html .= $this->print_toggle('groups', true);
519 :     $html .= $this->print_toggle('ranges', true);
520 : dservos 1.3 $html .= $this->print_toggle('inverted', true);
521 : dservos 1.1 $html .= '</div>';
522 :    
523 :     return $html;
524 :     }
525 :    
526 :     /**
527 :     * Builds HTML for each individual toggle.
528 :     * Based on grader report print_toggle
529 :     * @param string $type The toggle type.
530 :     * @param bool $return Wheather ro return the HTML or print it.
531 :     */
532 :     private function print_toggle($type, $return=false) {
533 :     global $CFG;
534 :    
535 :     $icons = array('eyecons' => 't/hide.gif',
536 :     'numgrades' => 't/grades.gif',
537 :     'calculations' => 't/calc.gif',
538 :     'locks' => 't/lock.gif',
539 :     'averages' => 't/mean.gif',
540 : dservos 1.3 'inverted' => 't/switch_whole.gif',
541 : dservos 1.1 'nooutcomes' => 't/outcomes.gif');
542 :    
543 :     $pref_name = 'grade_report_statsshow' . $type;
544 :    
545 :     if (array_key_exists($pref_name, $CFG)) {
546 :     $show_pref = get_user_preferences($pref_name, $CFG->$pref_name);
547 :     } else {
548 :     $show_pref = get_user_preferences($pref_name);
549 :     }
550 :    
551 :     $strshow = $this->get_lang_string('show' . $type, 'gradereport_stats');
552 :     $strhide = $this->get_lang_string('hide' . $type, 'gradereport_stats');
553 :    
554 :     $show_hide = 'show';
555 :     $toggle_action = 1;
556 :    
557 :     if ($show_pref) {
558 :     $show_hide = 'hide';
559 :     $toggle_action = 0;
560 :     }
561 :    
562 :     if (array_key_exists($type, $icons)) {
563 :     $image_name = $icons[$type];
564 :     } else {
565 :     $image_name = "t/$type.gif";
566 :     }
567 :    
568 :     $string = ${'str' . $show_hide};
569 :    
570 :     $img = '<img src="'.$CFG->pixpath.'/'.$image_name.'" class="iconsmall" alt="'
571 :     .$string.'" title="'.$string.'" />'. "\n";
572 :    
573 :     $retval = $img . '<a href="' . $this->baseurl . "&amp;toggle=$toggle_action&amp;toggle_type=$type\">"
574 : dservos 1.2 . format_text($string, FORMAT_HTML) . '</a> ';
575 : dservos 1.1
576 :     if ($return) {
577 :     return $retval;
578 :     } else {
579 :     echo $retval;
580 :     }
581 :     }
582 :     }
583 :     ?>

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7