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

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7