OU Bug 2867 - Overview report keeps forgetting the 'Display options' settings. Merged...
[moodle.git] / grade / lib.php
CommitLineData
3af29899 1<?php //$Id$
cbff94ba 2
7a6b7acf 3require_once $CFG->libdir.'/gradelib.php';
4
0610812a 5/**
6 * Print grading plugin selection popup form.
7 *
8 * @param int $courseid id of course
9 * @param string $active_type type of plugin on current page - import, export, report or edit
10 * @param string $active_plugin active plugin type - grader, user, cvs, ...
11 * @param boolean $return return as string
12 * @return nothing or string if $return true
13 */
3af29899 14function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $return=false) {
cbff94ba 15 global $CFG;
cbff94ba 16
3af29899 17 $context = get_context_instance(CONTEXT_COURSE, $courseid);
cbff94ba 18
3af29899 19 $menu = array();
cbff94ba 20
3af29899 21 $active = '';
cbff94ba 22
3af29899 23/// report plugins with its special structure
24 if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
25 foreach ($reports as $key => $plugin) { // Remove ones we can't see
26 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
27 unset($reports[$key]);
cbff94ba 28 }
29 }
04678d8e 30 }
3af29899 31 $reportnames = array();
32 if (!empty($reports)) {
33 foreach ($reports as $plugin) {
65dd61bd 34 $url = 'report/'.$plugin.'/index.php?id='.$courseid;
3af29899 35 if ($active_type == 'report' and $active_plugin == $plugin ) {
36 $active = $url;
cbff94ba 37 }
e2008be2 38 $reportnames[$url] = get_string('modulename', 'gradereport_'.$plugin, NULL, $CFG->dirroot.'/grade/report/'.$plugin.'lang/');
cbff94ba 39 }
3af29899 40 asort($reportnames);
cbff94ba 41 }
3af29899 42 if (!empty($reportnames)) {
43 $menu['reportgroup']='--'.get_string('reportplugins', 'grades');
44 $menu = $menu+$reportnames;
cbff94ba 45 }
cbff94ba 46
3af29899 47/// standard import plugins
e2008be2 48 if ($imports = get_list_of_plugins('grade/import', 'CVS')) { // Get all installed import plugins
3af29899 49 foreach ($imports as $key => $plugin) { // Remove ones we can't see
50 if (!has_capability('gradeimport/'.$plugin.':view', $context)) {
51 unset($imports[$key]);
cbff94ba 52 }
53 }
54 }
3af29899 55 $importnames = array();
56 if (!empty($imports)) {
57 foreach ($imports as $plugin) {
58 $url = 'import/'.$plugin.'/index.php?id='.$courseid;
65dd61bd 59 if ($active_type == 'import' and $active_plugin == $plugin ) {
3af29899 60 $active = $url;
61 }
e2008be2 62 $importnames[$url] = get_string('modulename', 'gradeimport_'.$plugin, NULL, $CFG->dirroot.'/grade/import/'.$plugin.'lang/');
281ffa4a 63 }
3af29899 64 asort($importnames);
281ffa4a 65 }
3af29899 66 if (!empty($importnames)) {
67 $menu['importgroup']='--'.get_string('importplugins', 'grades');
68 $menu = $menu+$importnames;
281ffa4a 69 }
281ffa4a 70
3af29899 71/// standard export plugins
e2008be2 72 if ($exports = get_list_of_plugins('grade/export', 'CVS')) { // Get all installed export plugins
3af29899 73 foreach ($exports as $key => $plugin) { // Remove ones we can't see
74 if (!has_capability('gradeexport/'.$plugin.':view', $context)) {
75 unset($exports[$key]);
281ffa4a 76 }
77 }
cbff94ba 78 }
3af29899 79 $exportnames = array();
80 if (!empty($exports)) {
81 foreach ($exports as $plugin) {
82 $url = 'export/'.$plugin.'/index.php?id='.$courseid;
65dd61bd 83 if ($active_type == 'export' and $active_plugin == $plugin ) {
3af29899 84 $active = $url;
85 }
e2008be2 86 $exportnames[$url] = get_string('modulename', 'gradeexport_'.$plugin, NULL, $CFG->dirroot.'/grade/export/'.$plugin.'lang/');
281ffa4a 87 }
3af29899 88 asort($exportnames);
cbff94ba 89 }
3af29899 90 if (!empty($exportnames)) {
91 $menu['exportgroup']='--'.get_string('exportplugins', 'grades');
92 $menu = $menu+$exportnames;
281ffa4a 93 }
cbff94ba 94
3af29899 95/// editing scripts - not real plugins
0a89e2a0 96 if (has_capability('moodle/grade:manage', $context)) {
3af29899 97 $menu['edit']='--'.get_string('edit');
98 $url = 'edit/tree.php?id='.$courseid;
99 if ($active_type == 'edit' and $active_plugin == 'tree' ) {
100 $active = $url;
cbff94ba 101 }
3af29899 102 $menu[$url] = get_string('edittree', 'grades');
281ffa4a 103 }
104
3af29899 105/// finally print/return the popup form
0c811aa7 106 return popup_form($CFG->wwwroot.'/grade/', $menu, 'choosepluginreport', $active, 'choose', '', '', $return, 'self', get_string('view'));
cbff94ba 107}
108
0610812a 109/**
7a6b7acf 110 * Utility class used for return tracking when using edit and other forms in grade plugins
0610812a 111 */
3af29899 112class grade_plugin_return {
113 var $type;
114 var $plugin;
115 var $courseid;
116 var $userid;
117 var $page;
281ffa4a 118
0610812a 119 /**
120 * Constructor
121 * @param array $params - associative array with return parameters, if null parameter are taken from _GET or _POST
122 */
3af29899 123 function grade_plugin_return ($params=null) {
124 if (empty($params)) {
125 $this->type = optional_param('gpr_type', null, PARAM_SAFEDIR);
126 $this->plugin = optional_param('gpr_plugin', null, PARAM_SAFEDIR);
127 $this->courseid = optional_param('gpr_courseid', null, PARAM_INT);
128 $this->userid = optional_param('gpr_userid', null, PARAM_INT);
129 $this->page = optional_param('gpr_page', null, PARAM_INT);
a983b6ec 130
a983b6ec 131 } else {
3af29899 132 foreach ($params as $key=>$value) {
133 if (array_key_exists($key, $this)) {
134 $this->$key = $value;
135 }
cbff94ba 136 }
137 }
6cd8c592 138 }
139
0610812a 140 /**
141 * Returns return parameters as options array suitable for buttons.
142 * @return array options
143 */
3af29899 144 function get_options() {
7a6b7acf 145 if (empty($this->type)) {
3af29899 146 return array();
865e9a82 147 }
6cd8c592 148
3af29899 149 $params = array();
6cd8c592 150
7a6b7acf 151 if (!empty($this->plugin)) {
152 $params['plugin'] = $this->plugin;
153 }
6cd8c592 154
3af29899 155 if (!empty($this->courseid)) {
156 $params['id'] = $this->courseid;
6cd8c592 157 }
9c61ba4d 158
3af29899 159 if (!empty($this->userid)) {
160 $params['userid'] = $this->userid;
9c61ba4d 161 }
9c61ba4d 162
3af29899 163 if (!empty($this->page)) {
164 $params['page'] = $this->page;
cbff94ba 165 }
865e9a82 166
3af29899 167 return $params;
cbff94ba 168 }
cbff94ba 169
0610812a 170 /**
171 * Returns return url
172 * @param string $default default url when params not set
173 * @return string url
174 */
65dd61bd 175 function get_return_url($default, $extras=null) {
3af29899 176 global $CFG;
cbff94ba 177
7a6b7acf 178 if ($this->type == 'edit') {
179 return $CFG->wwwroot.'/grade/edit/tree.php?id='.$this->courseid;
180 }
181
3af29899 182 if (empty($this->type) or empty($this->plugin)) {
183 return $default;
cbff94ba 184 }
185
65dd61bd 186 $url = $CFG->wwwroot.'/grade/'.$this->type.'/'.$this->plugin.'/index.php';
187 $glue = '?';
cbff94ba 188
3af29899 189 if (!empty($this->courseid)) {
190 $url .= $glue.'id='.$this->courseid;
191 $glue = '&amp;';
cbff94ba 192 }
cbff94ba 193
3af29899 194 if (!empty($this->userid)) {
195 $url .= $glue.'userid='.$this->userid;
196 $glue = '&amp;';
cbff94ba 197 }
7e2d7c92 198
3af29899 199 if (!empty($this->page)) {
200 $url .= $glue.'page='.$this->page;
65dd61bd 201 $glue = '&amp;';
202 }
203
204 if (!empty($extras)) {
205 foreach($extras as $key=>$value) {
206 $url .= $glue.$key.'='.$value;
207 $glue = '&amp;';
7a6b7acf 208 }
cbff94ba 209 }
cbff94ba 210
3af29899 211 return $url;
cbff94ba 212 }
cbff94ba 213
0610812a 214 /**
215 * Returns string with hidden return tracking form elements.
216 * @return string
217 */
3af29899 218 function get_form_fields() {
7a6b7acf 219 if (empty($this->type)) {
3af29899 220 return '';
cbff94ba 221 }
cbff94ba 222
3af29899 223 $result = '<input type="hidden" name="gpr_type" value="'.$this->type.'" />';
7a6b7acf 224
225 if (!empty($this->plugin)) {
226 $result .= '<input type="hidden" name="gpr_plugin" value="'.$this->plugin.'" />';
227 }
0ca5abd6 228
3af29899 229 if (!empty($this->courseid)) {
230 $result .= '<input type="hidden" name="gpr_courseid" value="'.$this->courseid.'" />';
cbff94ba 231 }
cbff94ba 232
3af29899 233 if (!empty($this->userid)) {
234 $result .= '<input type="hidden" name="gpr_userid" value="'.$this->userid.'" />';
cbff94ba 235 }
cbff94ba 236
3af29899 237 if (!empty($this->page)) {
238 $result .= '<input type="hidden" name="gpr_page" value="'.$this->page.'" />';
cbff94ba 239 }
240 }
cbff94ba 241
0610812a 242 /**
243 * Add hidden elements into mform
244 * @param object $mform moodle form object
245 * @return void
246 */
3af29899 247 function add_mform_elements(&$mform) {
7a6b7acf 248 if (empty($this->type)) {
3af29899 249 return;
cbff94ba 250 }
cbff94ba 251
3af29899 252 $mform->addElement('hidden', 'gpr_type', $this->type);
253 $mform->setType('gpr_type', PARAM_SAFEDIR);
cbff94ba 254
7a6b7acf 255 if (!empty($this->plugin)) {
256 $mform->addElement('hidden', 'gpr_plugin', $this->plugin);
257 $mform->setType('gpr_plugin', PARAM_SAFEDIR);
258 }
97033c86 259
3af29899 260 if (!empty($this->courseid)) {
261 $mform->addElement('hidden', 'gpr_courseid', $this->courseid);
262 $mform->setType('gpr_courseid', PARAM_INT);
cbff94ba 263 }
cbff94ba 264
3af29899 265 if (!empty($this->userid)) {
266 $mform->addElement('hidden', 'gpr_userid', $this->userid);
267 $mform->setType('gpr_userid', PARAM_INT);
cbff94ba 268 }
cbff94ba 269
3af29899 270 if (!empty($this->page)) {
271 $mform->addElement('hidden', 'gpr_page', $this->page);
272 $mform->setType('gpr_page', PARAM_INT);
cbff94ba 273 }
274 }
281ffa4a 275
0610812a 276 /**
277 * Add return tracking params into url
278 * @param string $url
279 * @return string $url with erturn tracking params
280 */
3af29899 281 function add_url_params($url) {
7a6b7acf 282 if (empty($this->type)) {
3af29899 283 return $url;
cbff94ba 284 }
5609f9e6 285
3af29899 286 if (strpos($url, '?') === false) {
287 $url .= '?gpr_type='.$this->type;
288 } else {
289 $url .= '&amp;gpr_type='.$this->type;
cbff94ba 290 }
cbff94ba 291
7a6b7acf 292 if (!empty($this->plugin)) {
293 $url .= '&amp;gpr_plugin='.$this->plugin;
294 }
cbff94ba 295
3af29899 296 if (!empty($this->courseid)) {
297 $url .= '&amp;gpr_courseid='.$this->courseid;
cbff94ba 298 }
cbff94ba 299
3af29899 300 if (!empty($this->userid)) {
301 $url .= '&amp;gpr_userid='.$this->userid;
cbff94ba 302 }
0a8a95c9 303
3af29899 304 if (!empty($this->page)) {
305 $url .= '&amp;gpr_page='.$this->page;
0a8a95c9 306 }
5a412dbf 307
3af29899 308 return $url;
5a412dbf 309 }
5a412dbf 310}
7a6b7acf 311
312
313/**
314 * This class represents a complete tree of categories, grade_items and final grades,
315 * organises as an array primarily, but which can also be converted to other formats.
316 * It has simple method calls with complex implementations, allowing for easy insertion,
317 * deletion and moving of items and categories within the tree.
318 */
319class grade_tree {
320
321 /**
322 * The basic representation of the tree as a hierarchical, 3-tiered array.
323 * @var object $top_element
324 */
325 var $top_element;
326
327 /**
328 * A string of GET URL variables, namely courseid and sesskey, used in most URLs built by this class.
329 * @var string $commonvars
330 */
331 var $commonvars;
332
333 /**
334 * 2D array of grade items and categories
335 */
336 var $levels;
337
2cc773f5 338 /**
339 * Course context
340 */
341 var $context;
342
7a6b7acf 343 /**
344 * Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item
345 * objects for the given courseid. Full objects are instantiated.
346 * and renumbering.
347 * @param int $courseid
348 * @param boolean $fillers include fillers and colspans, make the levels var "rectangular"
349 * @param boolean $category_grade_last category grade item is the last child
350 * @param boolean $aggregation_view Either full view (0) or compact view (1)
351 */
352 function grade_tree($courseid, $fillers=true, $category_grade_last=false,
353 $aggregation_view=GRADE_REPORT_AGGREGATION_VIEW_FULL) {
354 global $USER, $CFG;
355
356 $this->courseid = $courseid;
357 $this->commonvars = "&amp;sesskey=$USER->sesskey&amp;id=$this->courseid";
358 $this->levels = array();
2cc773f5 359 $this->context = get_context_instance(CONTEXT_COURSE, $courseid);
7a6b7acf 360
361 // get course grade tree
362 $this->top_element = grade_category::fetch_course_tree($courseid, true);
363
364 if ($category_grade_last) {
365 grade_tree::category_grade_last($this->top_element);
366 }
367
368 if ($fillers) {
369 // inject fake categories == fillers
370 grade_tree::inject_fillers($this->top_element, 0);
371 // add colspans to categories and fillers
372 grade_tree::inject_colspans($this->top_element);
373 }
374
375 grade_tree::fill_levels($this->levels, $this->top_element, 0);
376 }
377
378
379 /**
380 * Static recursive helper - makes the grade_item for category the last children
381 * @static
382 * @param array $element The seed of the recursion
383 * @return void
384 */
385 function category_grade_last(&$element) {
386 if (empty($element['children'])) {
387 return;
388 }
389 if (count($element['children']) < 2) {
390 return;
391 }
392 $category_item = reset($element['children']);
393 $order = key($element['children']);
394 unset($element['children'][$order]);
395 $element['children'][$order] =& $category_item;
396 foreach ($element['children'] as $sortorder=>$child) {
397 grade_tree::category_grade_last($element['children'][$sortorder]);
398 }
399 }
400
401 /**
402 * Static recursive helper - fills the levels array, useful when accessing tree elements of one level
403 * @static
404 * @param int $levels
405 * @param array $element The seed of the recursion
406 * @param int $depth
407 * @return void
408 */
409 function fill_levels(&$levels, &$element, $depth) {
410 if (!array_key_exists($depth, $levels)) {
411 $levels[$depth] = array();
412 }
413
414 // prepare unique identifier
415 if ($element['type'] == 'category') {
416 $element['eid'] = 'c'.$element['object']->id;
417 } else if (in_array($element['type'], array('item', 'courseitem', 'categoryitem'))) {
418 $element['eid'] = 'i'.$element['object']->id;
419 }
420
421 $levels[$depth][] =& $element;
422 $depth++;
423 if (empty($element['children'])) {
424 return;
425 }
426 $prev = 0;
427 foreach ($element['children'] as $sortorder=>$child) {
428 grade_tree::fill_levels($levels, $element['children'][$sortorder], $depth);
429 $element['children'][$sortorder]['prev'] = $prev;
430 $element['children'][$sortorder]['next'] = 0;
431 if ($prev) {
432 $element['children'][$prev]['next'] = $sortorder;
433 }
434 $prev = $sortorder;
435 }
436 }
437
438 /**
439 * Static recursive helper - makes full tree (all leafes are at the same level)
440 */
441 function inject_fillers(&$element, $depth) {
442 $depth++;
443
444 if (empty($element['children'])) {
445 return $depth;
446 }
447 $chdepths = array();
448 $chids = array_keys($element['children']);
449 $last_child = end($chids);
450 $first_child = reset($chids);
451
452 foreach ($chids as $chid) {
453 $chdepths[$chid] = grade_tree::inject_fillers($element['children'][$chid], $depth);
454 }
455 arsort($chdepths);
456
457 $maxdepth = reset($chdepths);
458 foreach ($chdepths as $chid=>$chd) {
459 if ($chd == $maxdepth) {
460 continue;
461 }
462 for ($i=0; $i < $maxdepth-$chd; $i++) {
463 if ($chid == $first_child) {
464 $type = 'fillerfirst';
465 } else if ($chid == $last_child) {
466 $type = 'fillerlast';
467 } else {
468 $type = 'filler';
469 }
470 $oldchild =& $element['children'][$chid];
471 $element['children'][$chid] = array('object'=>'filler', 'type'=>$type, 'eid'=>'', 'depth'=>$element['object']->depth,'children'=>array($oldchild));
472 }
473 }
474
475 return $maxdepth;
476 }
477
478 /**
479 * Static recursive helper - add colspan information into categories
480 */
481 function inject_colspans(&$element) {
482 if (empty($element['children'])) {
483 return 1;
484 }
485 $count = 0;
486 foreach ($element['children'] as $key=>$child) {
487 $count += grade_tree::inject_colspans($element['children'][$key]);
488 }
489 $element['colspan'] = $count;
490 return $count;
491 }
492
493 /**
494 * Parses the array in search of a given eid and returns a element object with
495 * information about the element it has found.
496 * @param int $eid
497 * @return object element
498 */
499 function locate_element($eid) {
500 if (strpos($eid, 'g') === 0) {
501 // it is a grade construct a new object
502 $id = (int)substr($eid, 1);
503 if (!$grade = grade_grade::fetch(array('id'=>$id))) {
504 return null;
505 }
506 //extra security check - the grade item must be in this tree
507 if (!$item_el = $this->locate_element('i'.$grade->itemid)) {
508 return null;
509 }
510 $grade->grade_item =& $item_el['object']; // this may speedup grade_grade methods!
511 return array('eid'=>'g'.$id,'object'=>$grade, 'type'=>'grade');
512 }
513
514 // it is a category or item
515 foreach ($this->levels as $row) {
516 foreach ($row as $element) {
517 if ($element['type'] == 'filler') {
518 continue;
519 }
520 if ($element['eid'] == $eid) {
521 return $element;
522 }
523 }
524 }
525
526 return null;
527 }
528
529 /**
530 * Return edit icon for give element
531 * @param object $element
532 * @return string
533 */
534 function get_edit_icon($element, $gpr) {
535 global $CFG;
536
2cc773f5 537 if (!has_capability('moodle/grade:manage', $this->context)) {
7a6b7acf 538 return '';
539 }
540
2cc773f5 541 static $stredit = null;
542 if (is_null($stredit)) {
543 $stredit = get_string('edit');
544 }
545
7a6b7acf 546 $object = $element['object'];
2cc773f5 547 $overlib = '';
7a6b7acf 548
549 switch ($element['type']) {
550 case 'item':
551 case 'categoryitem':
552 case 'courseitem':
553 $url = $CFG->wwwroot.'/grade/edit/item.php?courseid='.$this->courseid.'&amp;id='.$object->id;
554 $url = $gpr->add_url_params($url);
555 break;
556
557 case 'category':
558 $url = $CFG->wwwroot.'/grade/edit/category.php?courseid='.$this->courseid.'&amp;id='.$object->id;
559 $url = $gpr->add_url_params($url);
560 break;
561
562 case 'grade':
563 //TODO: improve dealing with new grades
564 $url = $CFG->wwwroot.'/grade/edit/grade.php?courseid='.$this->courseid.'&amp;id='.$object->id;
565 $url = $gpr->add_url_params($url);
2cc773f5 566 if (!empty($object->feedback)) {
567 $feedback = format_text($object->feedback, $object->feedbackformat);
568 $function = "return overlib('".s(ltrim($object->feedback)."', FULLHTML);");
569 $overlib = 'onmouseover="'.$function.'" onmouseout="return nd();"';
570 }
7a6b7acf 571 break;
572
573 default:
574 $url = null;
575 }
576
577 if ($url) {
2cc773f5 578 return '<a href="'.$url.'"><img '.$overlib.' src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>';
7a6b7acf 579
580 } else {
581 return '';
582 }
583 }
584
585 /**
586 * Return hiding icon for give element
587 * @param object $element
588 * @return string
589 */
590 function get_hiding_icon($element, $gpr) {
591 global $CFG;
592
2cc773f5 593 if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:hide', $this->context)) {
7a6b7acf 594 return '';
595 }
596
2cc773f5 597 static $strshow = null;
598 static $strhide = null;
599 if (is_null($strshow)) {
7a6b7acf 600 $strshow = get_string('show');
2cc773f5 601 $strhide = get_string('hide');
602 }
603
604 if ($element['object']->is_hidden()) {
7a6b7acf 605 $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=show&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
606 $url = $gpr->add_url_params($url);
607 $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.$strshow.'" title="'.$strshow.'"/></a>';
608
609 } else {
7a6b7acf 610 $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=hide&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
611 $url = $gpr->add_url_params($url);
612 $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.$strhide.'" title="'.$strhide.'"/></a>';
613 }
614 return $action;
615 }
616
617 /**
618 * Return locking icon for give element
619 * @param object $element
620 * @return string
621 */
622 function get_locking_icon($element, $gpr) {
623 global $CFG;
624
2cc773f5 625 static $strunlock = null;
626 static $strlock = null;
627 if (is_null($strunlock)) {
628 $strunlock = get_string('unlock', 'grades');
629 $strlock = get_string('lock', 'grades');
630 }
7a6b7acf 631
632 if ($element['object']->is_locked()) {
2cc773f5 633 if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:unlock', $this->context)) {
7a6b7acf 634 return '';
635 }
7a6b7acf 636 $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=unlock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
637 $url = $gpr->add_url_params($url);
638 $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/unlock.gif" class="iconsmall" alt="'.$strunlock.'" title="'.$strunlock.'"/></a>';
639
640 } else {
2cc773f5 641 if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:lock', $this->context)) {
7a6b7acf 642 return '';
643 }
7a6b7acf 644 $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=lock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
645 $url = $gpr->add_url_params($url);
646 $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/lock.gif" class="iconsmall" alt="'.$strlock.'" title="'.$strlock.'"/></a>';
647 }
648 return $action;
649 }
650
2cc773f5 651 /**
652 * Return calculation icon for given element
653 * @param object $element
654 * @return string
655 */
656 function get_calculation_icon($element, $gpr) {
657 global $CFG;
658 if (!has_capability('moodle/grade:manage', $this->context)) {
659 return '';
660 }
661
662 $calculation_icon = '';
663
664 $type = $element['type'];
665 $object = $element['object'];
666
667 if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') {
668 $streditcalculation = get_string('editcalculation', 'grades');
669
670 // show calculation icon only when calculation possible
671 if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
672 $url = $CFG->wwwroot.'/grade/edit/calculation.php?courseid='.$this->courseid.'&amp;id='.$object->id;
673 $url = $gpr->add_url_params($url);
674 $calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="'
675 . $streditcalculation.'" title="'.$streditcalculation.'" /></a>'. "\n";
676 }
677 }
678
679 return $calculation_icon;
680 }
7a6b7acf 681}
682
e2008be2 683?>