MDL-34777 grading: add label to select and input tag
[moodle.git] / grade / edit / tree / lib.php
CommitLineData
e060e33d 1<?php
e060e33d 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/>.
dc482cfa 16
a153c9f2
AD
17/**
18 * A library of classes used by the grade edit pages
19 *
20 * @package core_grades
21 * @copyright 2009 Nicolas Connault
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
dc482cfa 25class grade_edit_tree {
26 public $columns = array();
27
28 /**
29 * @var object $gtree @see grade/lib.php
30 */
31 public $gtree;
32
33 /**
34 * @var grade_plugin_return @see grade/lib.php
35 */
36 public $gpr;
37
38 /**
39 * @var string $moving The eid of the category or item being moved
40 */
41 public $moving;
42
43 public $deepest_level;
44
653a8648 45 public $uses_extra_credit = false;
46
47 public $uses_weight = false;
71297a3f 48
54a007e8 49 public $table;
71297a3f 50
54a007e8 51 public $categories = array();
dc482cfa 52 /**
53 * Constructor
54 */
55 public function __construct($gtree, $moving=false, $gpr) {
54a007e8 56 global $USER, $OUTPUT, $COURSE;
57
dc482cfa 58 $this->gtree = $gtree;
59 $this->moving = $moving;
60 $this->gpr = $gpr;
61 $this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
62
63 $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)),
653a8648 64 grade_edit_tree_column::factory('aggregation', array('flag' => true)));
65
66 if ($this->uses_weight) {
67 $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
68 }
69 if ($this->uses_extra_credit) {
70 $this->columns[] = grade_edit_tree_column::factory('extracredit', array('adv' => 'aggregationcoef'));
71 }
72
73 $this->columns[] = grade_edit_tree_column::factory('range'); // This is not a setting... How do we deal with it?
74 $this->columns[] = grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true));
75 $this->columns[] = grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true));
76 $this->columns[] = grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true));
77 $this->columns[] = grade_edit_tree_column::factory('droplow', array('flag' => true));
78 $this->columns[] = grade_edit_tree_column::factory('keephigh', array('flag' => true));
79 $this->columns[] = grade_edit_tree_column::factory('multfactor', array('adv' => true));
80 $this->columns[] = grade_edit_tree_column::factory('plusfactor', array('adv' => true));
81 $this->columns[] = grade_edit_tree_column::factory('actions');
82 $this->columns[] = grade_edit_tree_column::factory('select');
54a007e8 83
84 $mode = ($USER->gradeediting[$COURSE->id]) ? 'advanced' : 'simple';
71297a3f 85
54a007e8 86 $widthstyle = '';
87 if ($mode == 'simple') {
88 $widthstyle = ' style="width:auto;" ';
89 }
90
91 $this->table = new html_table();
92 $this->table->id = "grade_edit_tree_table";
93 $this->table->cellpadding = 5;
16be8974 94 $this->table->attributes['class'] = 'generaltable ' . $mode;
54a007e8 95 $this->table->style = $widthstyle;
96
97 foreach ($this->columns as $column) {
98 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
99 $this->table->head[] = $column->get_header_cell();
100 }
101 }
102
103 $rowcount = 0;
104 $this->table->data = $this->build_html_tree($this->gtree->top_element, true, array(), 0, $rowcount);
dc482cfa 105 }
106
107 /**
108 * Recursive function for building the table holding the grade categories and items,
109 * with CSS indentation and styles.
110 *
1c1f64a2 111 * @param array $element The current tree element being rendered
112 * @param boolean $totals Whether or not to print category grade items (category totals)
113 * @param array $parents An array of parent categories for the current element (used for indentation and row classes)
dc482cfa 114 *
115 * @return string HTML
116 */
54a007e8 117 public function build_html_tree($element, $totals, $parents, $level, &$row_count) {
6b608f8f 118 global $CFG, $COURSE, $USER, $OUTPUT;
71297a3f 119
dc482cfa 120 $object = $element['object'];
121 $eid = $element['eid'];
122 $object->name = $this->gtree->get_element_header($element, true, true, false);
123 $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
124
125 $is_category_item = false;
126 if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
127 $is_category_item = true;
128 }
129
54a007e8 130 $rowclasses = array();
dc482cfa 131 foreach ($parents as $parent_eid) {
54a007e8 132 $rowclasses[] = $parent_eid;
dc482cfa 133 }
134
135 $actions = '';
136
137 if (!$is_category_item) {
138 $actions .= $this->gtree->get_edit_icon($element, $this->gpr);
139 }
140
141 $actions .= $this->gtree->get_calculation_icon($element, $this->gpr);
142
143 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
144 if ($this->element_deletable($element)) {
8ae8bf8a 145 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
c63923bd 146 $actions .= $OUTPUT->action_icon($aurl, new pix_icon('t/delete', get_string('delete')));
dc482cfa 147 }
1c1f64a2 148
8ae8bf8a 149 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
c63923bd 150 $actions .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
dc482cfa 151 }
152
153 $actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
154 $actions .= $this->gtree->get_locking_icon($element, $this->gpr);
155
156 $mode = ($USER->gradeediting[$COURSE->id]) ? 'advanced' : 'simple';
157
54a007e8 158 $returnrows = array();
dc482cfa 159 $root = false;
160
dc482cfa 161 $id = required_param('id', PARAM_INT);
162
163 /// prepare move target if needed
164 $last = '';
165
166 /// print the list items now
167 if ($this->moving == $eid) {
dc482cfa 168 // do not diplay children
54a007e8 169 $cell = new html_table_cell();
170 $cell->colspan = 12;
16be8974 171 $cell->attributes['class'] = $element['type'] . ' moving';
54a007e8 172 $cell->text = $object->name.' ('.get_string('move').')';
8cea545e 173 return array(new html_table_row(array($cell)));
dc482cfa 174 }
175
176 if ($element['type'] == 'category') {
177 $level++;
54a007e8 178 $this->categories[$object->id] = $object->stripped_name;
dc482cfa 179 $category = grade_category::fetch(array('id' => $object->id));
180 $item = $category->get_grade_item();
181
182 // Add aggregation coef input if not a course item and if parent category has correct aggregation type
54a007e8 183 $dimmed = ($item->is_hidden()) ? 'dimmed' : '';
dc482cfa 184
185 // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
186 $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
187 $category_total_data = null; // Used if aggregationposition is set to "last", so we can print it last
188
54a007e8 189 $html_children = array();
dc482cfa 190
191 $row_count = 0;
192
193 foreach($element['children'] as $child_el) {
54a007e8 194 $moveto = null;
dc482cfa 195
196 if (empty($child_el['object']->itemtype)) {
197 $child_el['object']->itemtype = false;
198 }
199
200 if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
201 continue;
202 }
203
54a007e8 204 $child_eid = $child_el['eid'];
dc482cfa 205 $first = '';
206
207 if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
1c1f64a2 208 $first = array('first' => 1);
dc482cfa 209 $child_eid = $eid;
210 }
211
212 if ($this->moving && $this->moving != $child_eid) {
213
214 $strmove = get_string('move');
215 $strmovehere = get_string('movehere');
216 $actions = ''; // no action icons when moving
217
8ae8bf8a 218 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey()));
1c1f64a2 219 if ($first) {
8ae8bf8a 220 $aurl->params($first);
1c1f64a2 221 }
71297a3f 222
54a007e8 223 $cell = new html_table_cell();
224 $cell->colspan = 12;
6ef4878b 225
84d32de3
AD
226 $icon = new pix_icon('movehere', $strmovehere, null, array('class'=>'movetarget'));
227 $cell->text = $OUTPUT->action_icon($aurl, $icon);
1c1f64a2 228
8cea545e 229 $moveto = new html_table_row(array($cell));
dc482cfa 230 }
231
232 $newparents = $parents;
233 $newparents[] = $eid;
234
235 $row_count++;
236 $child_row_count = 0;
237
238 // If moving, do not print course and category totals, but still print the moveto target box
239 if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
54a007e8 240 $html_children[] = $moveto;
dc482cfa 241 } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
242 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
54a007e8 243 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count);
dc482cfa 244 if (!$aggregation_position) {
54a007e8 245 $html_children = array_merge($html_children, $category_total_item);
dc482cfa 246 }
247 } else {
54a007e8 248 $html_children = array_merge($html_children, $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count));
249 if (!empty($moveto)) {
250 $html_children[] = $moveto;
251 }
dc482cfa 252
253 if ($this->moving) {
254 $row_count++;
255 }
256 }
257
258 $row_count += $child_row_count;
259
260 // If the child is a category, increment row_count by one more (for the extra coloured row)
261 if ($child_el['type'] == 'category') {
262 $row_count++;
263 }
264 }
265
266 // Print category total at the end if aggregation position is "last" (1)
267 if (!empty($category_total_item) && $aggregation_position) {
54a007e8 268 $html_children = array_merge($html_children, $category_total_item);
dc482cfa 269 }
270
54a007e8 271 // Determine if we are at the root
dc482cfa 272 if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) {
dc482cfa 273 $root = true;
274 }
275
276 $row_count_offset = 0;
277
278 if (empty($category_total_item) && !$this->moving) {
279 $row_count_offset = -1;
280 }
281
54a007e8 282 $levelclass = "level$level";
2be6ca78 283
b189277f 284 $courseclass = '';
285 if ($level == 1) {
286 $courseclass = 'coursecategory';
287 }
71297a3f 288
54a007e8 289 $row = new html_table_row();
16be8974 290 $row->attributes['class'] = $courseclass . ' category ' . $dimmed;
54a007e8 291 foreach ($rowclasses as $class) {
16be8974 292 $row->attributes['class'] .= ' ' . $class;
54a007e8 293 }
dc482cfa 294
54a007e8 295 $headercell = new html_table_cell();
296 $headercell->header = true;
297 $headercell->scope = 'row';
16be8974
DM
298 $headercell->attributes['title'] = $object->stripped_name;
299 $headercell->attributes['class'] = 'cell rowspan ' . $levelclass;
54a007e8 300 $headercell->rowspan = $row_count+1+$row_count_offset;
301 $row->cells[] = $headercell;
dc482cfa 302
303 foreach ($this->columns as $column) {
304 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
54a007e8 305 $row->cells[] = $column->get_category_cell($category, $levelclass, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'eid' => $eid));
dc482cfa 306 }
307 }
71297a3f 308
54a007e8 309 $returnrows[] = $row;
dc482cfa 310
54a007e8 311 $returnrows = array_merge($returnrows, $html_children);
dc482cfa 312
6ef4878b 313 // Print a coloured row to show the end of the category across the table
54a007e8 314 $endcell = new html_table_cell();
315 $endcell->colspan = (19 - $level);
16be8974 316 $endcell->attributes['class'] = 'colspan ' . $levelclass;
54a007e8 317
8cea545e 318 $returnrows[] = new html_table_row(array($endcell));;
dc482cfa 319
320 } else { // Dealing with a grade item
321
322 $item = grade_item::fetch(array('id' => $object->id));
323 $element['type'] = 'item';
324 $element['object'] = $item;
2be6ca78 325
b189277f 326 $categoryitemclass = '';
327 if ($item->itemtype == 'category') {
328 $categoryitemclass = 'categoryitem';
329 }
dc482cfa 330
54a007e8 331 $dimmed = ($item->is_hidden()) ? "dimmed_text" : "";
332 $gradeitemrow = new html_table_row();
16be8974 333 $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
54a007e8 334 foreach ($rowclasses as $class) {
16be8974 335 $gradeitemrow->attributes['class'] .= ' ' . $class;
54a007e8 336 }
dc482cfa 337
338 foreach ($this->columns as $column) {
339 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
54a007e8 340 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions,
dc482cfa 341 'element' => $element, 'eid' => $eid, 'itemtype' => $object->itemtype));
342 }
343 }
344
54a007e8 345 $returnrows[] = $gradeitemrow;
dc482cfa 346 }
347
54a007e8 348 return $returnrows;
dc482cfa 349
350 }
351
352 /**
353 * Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
354 * @param grade_item $item
653a8648 355 * @param string type "extra" or "weight": the type of the column hosting the weight input
dc482cfa 356 * @return string HTML
357 */
e2bb3c92 358 static function get_weight_input($item, $type) {
1c1f64a2 359 global $OUTPUT;
360
dc482cfa 361 if (!is_object($item) || get_class($item) !== 'grade_item') {
362 throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
363 return false;
364 }
365
366 if ($item->is_course_item()) {
367 return '';
368 }
369
370 $parent_category = $item->get_parent_category();
dc482cfa 371 $parent_category->apply_forced_settings();
653a8648 372 $aggcoef = $item->get_coefstring();
dc482cfa 373
653a8648 374 if ((($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef') && $type == 'weight') ||
3869ab1a 375 ($aggcoef == 'aggregationcoefextraweight' && $type == 'extra')) {
b1fec412
RW
376 return '<label class="accesshide" for="aggregationcoef_'.$item->id.'">'.get_string('extracreditvalue', 'grades', $item->itemname).'</label>'.
377 '<input type="text" size="6" id="aggregationcoef_'.$item->id.'" name="aggregationcoef_'.$item->id.'"
3cf33f51 378 value="'.grade_edit_tree::format_number($item->aggregationcoef).'" />';
653a8648 379 } elseif ($aggcoef == 'aggregationcoefextrasum' && $type == 'extra') {
cd3a391c 380 $checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
916276fc
PS
381 return '<input type="hidden" name="extracredit_'.$item->id.'" value="0" />
382 <input type="checkbox" id="extracredit_'.$item->id.'" name="extracredit_'.$item->id.'" value="1" '."$checked />\n";
cd3a391c 383 } else {
384 return '';
dc482cfa 385 }
cd3a391c 386 }
dc482cfa 387
6ef4878b 388 //Trims trailing zeros
4592df46 389 //Used on the 'categories and items' page for grade items settings like aggregation co-efficient
e229506d 390 //Grader report has its own decimal place settings so they are handled elsewhere
e2bb3c92 391 static function format_number($number) {
4592df46 392 $formatted = rtrim(format_float($number, 4),'0');
dacd5daa 393 if (substr($formatted, -1)==get_string('decsep', 'langconfig')) { //if last char is the decimal point
4592df46
AD
394 $formatted .= '0';
395 }
396 return $formatted;
3cf33f51
AD
397 }
398
dc482cfa 399 /**
400 * Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable)
401 *
402 * @param array $element
403 * @return bool
404 */
405 function element_deletable($element) {
406 global $COURSE;
407
408 if ($element['type'] != 'item') {
409 return true;
410 }
411
412 $grade_item = $element['object'];
413
414 if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) {
415 return true;
416 }
417
418 $modinfo = get_fast_modinfo($COURSE);
419 if (!isset($modinfo->instances[$grade_item->itemmodule][$grade_item->iteminstance])) {
420 // module does not exist
421 return true;
422 }
423
424 return false;
425 }
426
427 /**
428 * Given the grade tree and an array of element ids (e.g. c15, i42), and expecting the 'moveafter' URL param,
429 * moves the selected items to the requested location. Then redirects the user to the given $returnurl
430 *
431 * @param object $gtree The grade tree (a recursive representation of the grade categories and grade items)
432 * @param array $eids
433 * @param string $returnurl
434 */
435 function move_elements($eids, $returnurl) {
436 $moveafter = required_param('moveafter', PARAM_INT);
437
438 if (!is_array($eids)) {
439 $eids = array($eids);
440 }
441
442 if(!$after_el = $this->gtree->locate_element("c$moveafter")) {
443 print_error('invalidelementid', '', $returnurl);
444 }
445
446 $after = $after_el['object'];
447 $parent = $after;
448 $sortorder = $after->get_sortorder();
449
450 foreach ($eids as $eid) {
451 if (!$element = $this->gtree->locate_element($eid)) {
452 print_error('invalidelementid', '', $returnurl);
453 }
454 $object = $element['object'];
455
456 $object->set_parent($parent->id);
457 $object->move_after_sortorder($sortorder);
4d2f7923 458 $sortorder++;
dc482cfa 459 }
460
461 redirect($returnurl, '', 0);
462 }
463
464 /**
465 * Recurses through the entire grade tree to find and return the maximum depth of the tree.
466 * This should be run only once from the root element (course category), and is used for the
467 * indentation of the Name column's cells (colspan)
468 *
469 * @param array $element An array of values representing a grade tree's element (all grade items in this case)
470 * @param int $level The level of the current recursion
471 * @param int $deepest_level A value passed to each subsequent level of recursion and incremented if $level > $deepest_level
472 * @return int Deepest level
473 */
474 function get_deepest_level($element, $level=0, $deepest_level=1) {
475 $object = $element['object'];
476
477 $level++;
653a8648 478 $coefstring = $element['object']->get_coefstring();
dc482cfa 479 if ($element['type'] == 'category') {
653a8648 480 if ($coefstring == 'aggregationcoefweight') {
481 $this->uses_weight = true;
3869ab1a 482 } elseif ($coefstring == 'aggregationcoefextraweight' || $coefstring == 'aggregationcoefextrasum') {
653a8648 483 $this->uses_extra_credit = true;
484 }
485
dc482cfa 486 foreach($element['children'] as $child_el) {
487 if ($level > $deepest_level) {
488 $deepest_level = $level;
489 }
490 $deepest_level = $this->get_deepest_level($child_el, $level, $deepest_level);
491 }
492 }
493
494 return $deepest_level;
495 }
496}
497
498abstract class grade_edit_tree_column {
499 public $forced;
500 public $hidden;
501 public $forced_hidden;
502 public $advanced_hidden;
503 public $hide_when_moving = true;
54a007e8 504 /**
505 * html_table_cell object used as a template for header cells in all categories.
506 * It must be cloned before being used.
507 * @var html_table_cell $headercell
508 */
509 public $headercell;
510 /**
511 * html_table_cell object used as a template for category cells in all categories.
512 * It must be cloned before being used.
513 * @var html_table_cell $categorycell
514 */
515 public $categorycell;
516 /**
517 * html_table_cell object used as a template for item cells in all categories.
518 * It must be cloned before being used.
519 * @var html_table_cell $itemcell
520 */
521 public $itemcell;
dc482cfa 522
523 public static function factory($name, $params=array()) {
524 $class_name = "grade_edit_tree_column_$name";
525 if (class_exists($class_name)) {
526 return new $class_name($params);
527 }
528 }
529
530 public abstract function get_header_cell();
531
532 public abstract function get_category_cell($category, $levelclass, $params);
533
534 public abstract function get_item_cell($item, $params);
535
536 public abstract function is_hidden($mode='simple');
54a007e8 537
538 public function __construct() {
539 $this->headercell = new html_table_cell();
540 $this->headercell->header = true;
541 $this->headercell->style = 'whitespace: normal;';
16be8974 542 $this->headercell->attributes['class'] = 'header';
54a007e8 543
544 $this->categorycell = new html_table_cell();
16be8974 545 $this->categorycell->attributes['class'] = 'cell';
54a007e8 546
547 $this->itemcell = new html_table_cell();
16be8974 548 $this->itemcell->attributes['class'] = 'cell';
54a007e8 549 }
dc482cfa 550}
551
552abstract class grade_edit_tree_column_category extends grade_edit_tree_column {
553
554 public $forced;
555 public $advanced;
556
557 public function __construct($name) {
558 global $CFG;
559 $this->forced = (int)$CFG->{"grade_$name"."_flag"} & 1;
560 $this->advanced = (int)$CFG->{"grade_$name"."_flag"} & 2;
54a007e8 561 parent::__construct();
dc482cfa 562 }
563
564 public function is_hidden($mode='simple') {
565 global $CFG;
566 if ($mode == 'simple') {
567 return $this->advanced;
568 } elseif ($mode == 'advanced') {
569 if ($this->forced && $CFG->grade_hideforcedsettings) {
570 return true;
571 } else {
572 return false;
573 }
574 }
575 }
576}
577
578class grade_edit_tree_column_name extends grade_edit_tree_column {
579 public $forced = false;
580 public $hidden = false;
581 public $forced_hidden = false;
582 public $advanced_hidden = false;
583 public $deepest_level = 1;
584 public $hide_when_moving = false;
585
586 public function __construct($params) {
587 if (empty($params['deepest_level'])) {
588 throw new Exception('Tried to instantiate a grade_edit_tree_column_name object without the "deepest_level" param!');
589 }
590
591 $this->deepest_level = $params['deepest_level'];
54a007e8 592 parent::__construct();
dc482cfa 593 }
594
595 public function get_header_cell() {
54a007e8 596 $headercell = clone($this->headercell);
16be8974 597 $headercell->attributes['class'] .= ' name';
54a007e8 598 $headercell->colspan = $this->deepest_level + 1;
599 $headercell->text = get_string('name');
600 return $headercell;
dc482cfa 601 }
602
603 public function get_category_cell($category, $levelclass, $params) {
54a007e8 604 global $OUTPUT;
dc482cfa 605 if (empty($params['name']) || empty($params['level'])) {
606 throw new Exception('Array key (name or level) missing from 3rd param of grade_edit_tree_column_name::get_category_cell($category, $levelclass, $params)');
607 }
54a007e8 608 $categorycell = clone($this->categorycell);
16be8974 609 $categorycell->attributes['class'] .= ' name ' . $levelclass;
54a007e8 610 $categorycell->colspan = ($this->deepest_level +1) - $params['level'];
611 $categorycell->text = $OUTPUT->heading($params['name'], 4);
612 return $categorycell;
dc482cfa 613 }
614
615 public function get_item_cell($item, $params) {
616 global $CFG;
617
618 if (empty($params['element']) || empty($params['name']) || empty($params['level'])) {
619 throw new Exception('Array key (name, level or element) missing from 2nd param of grade_edit_tree_column_name::get_item_cell($item, $params)');
620 }
621
622 $name = $params['name'];
623
54a007e8 624 $itemcell = clone($this->itemcell);
16be8974 625 $itemcell->attributes['class'] .= ' name';
54a007e8 626 $itemcell->colspan = ($this->deepest_level + 1) - $params['level'];
627 $itemcell->text = $name;
628 return $itemcell;
dc482cfa 629 }
630
631 public function is_hidden($mode='simple') {
632 return false;
633 }
634}
635
636class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category {
637
638 public function __construct($params) {
639 parent::__construct('aggregation');
640 }
641
642 public function get_header_cell() {
c3b834b4 643 global $OUTPUT;
54a007e8 644 $headercell = clone($this->headercell);
f89b71eb 645 $headercell->text = get_string('aggregation', 'grades').$OUTPUT->help_icon('aggregation', 'grades');
54a007e8 646 return $headercell;
dc482cfa 647 }
648
649 public function get_category_cell($category, $levelclass, $params) {
0a95bebf 650 global $CFG, $OUTPUT;
dc482cfa 651 if (empty($params['id'])) {
652 throw new Exception('Array key (id) missing from 3rd param of grade_edit_tree_column_aggregation::get_category_cell($category, $levelclass, $params)');
653 }
654
655 $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'),
656 GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'),
657 GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'),
658 GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'),
659 GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'),
660 GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'),
661 GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'),
662 GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'),
663 GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
664
653a8648 665 $visible = explode(',', $CFG->grade_aggregations_visible);
666 foreach ($options as $constant => $string) {
667 if (!in_array($constant, $visible) && $constant != $category->aggregation) {
668 unset($options[$constant]);
669 }
670 }
671
dc482cfa 672 if ($this->forced) {
673 $aggregation = $options[$category->aggregation];
064527d6
PS
674 } else {
675 $attributes = array();
676 $attributes['id'] = 'aggregation_'.$category->id;
29bea634
RW
677 $aggregation = html_writer::label(get_string('aggregation', 'grades'), 'aggregation_'.$category->id, false, array('class' => 'accesshide'));
678 $aggregation .= html_writer::select($options, 'aggregation_'.$category->id, $category->aggregation, null, $attributes);
064527d6 679 $action = new component_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
c80877aa 680 $OUTPUT->add_action_handler($action, 'aggregation_'.$category->id);
dc482cfa 681 }
682
54a007e8 683 $categorycell = clone($this->categorycell);
16be8974 684 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 685 $categorycell->text = $aggregation;
686 return $categorycell;
dc482cfa 687
688 }
689
690 public function get_item_cell($item, $params) {
54a007e8 691 $itemcell = clone($this->itemcell);
692 $itemcell->text = ' - ';
693 return $itemcell;
dc482cfa 694 }
695}
696
653a8648 697class grade_edit_tree_column_extracredit extends grade_edit_tree_column {
698
699 public function get_header_cell() {
c3b834b4 700 global $OUTPUT;
54a007e8 701 $headercell = clone($this->headercell);
3869ab1a 702 $headercell->text = get_string('aggregationcoefextra', 'grades').$OUTPUT->help_icon('aggregationcoefextra', 'grades');
54a007e8 703 return $headercell;
653a8648 704 }
705
706 public function get_category_cell($category, $levelclass, $params) {
653a8648 707 $item = $category->get_grade_item();
54a007e8 708 $categorycell = clone($this->categorycell);
16be8974 709 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 710 $categorycell->text = grade_edit_tree::get_weight_input($item, 'extra');
711 return $categorycell;
653a8648 712 }
713
714 public function get_item_cell($item, $params) {
715 if (empty($params['element'])) {
716 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
717 }
718
54a007e8 719 $itemcell = clone($this->itemcell);
720 $itemcell->text = '&nbsp;';
653a8648 721
722 if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
54a007e8 723 $itemcell->text = grade_edit_tree::get_weight_input($item, 'extra');
653a8648 724 }
725
54a007e8 726 return $itemcell;
653a8648 727 }
728
729 public function is_hidden($mode='simple') {
730 global $CFG;
731 if ($mode == 'simple') {
732 return strstr($CFG->grade_item_advanced, 'aggregationcoef');
733 } elseif ($mode == 'advanced') {
734 return false;
735 }
736 }
737}
738
739class grade_edit_tree_column_weight extends grade_edit_tree_column {
dc482cfa 740
741 public function get_header_cell() {
c3b834b4 742 global $OUTPUT;
54a007e8 743 $headercell = clone($this->headercell);
3869ab1a 744 $headercell->text = get_string('weightuc', 'grades').$OUTPUT->help_icon('aggregationcoefweight', 'grades');
54a007e8 745 return $headercell;
dc482cfa 746 }
747
748 public function get_category_cell($category, $levelclass, $params) {
749
750 $item = $category->get_grade_item();
54a007e8 751 $categorycell = clone($this->categorycell);
16be8974 752 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 753 $categorycell->text = grade_edit_tree::get_weight_input($item, 'weight');
754 return $categorycell;
dc482cfa 755 }
756
757 public function get_item_cell($item, $params) {
758 if (empty($params['element'])) {
759 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
760 }
54a007e8 761 $itemcell = clone($this->itemcell);
762 $itemcell->text = '&nbsp;';
dc482cfa 763
b8436ccb 764 if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
54a007e8 765 $itemcell->text = grade_edit_tree::get_weight_input($item, 'weight');
dc482cfa 766 }
767
54a007e8 768 return $itemcell;
dc482cfa 769 }
770
771 public function is_hidden($mode='simple') {
772 global $CFG;
773 if ($mode == 'simple') {
774 return strstr($CFG->grade_item_advanced, 'aggregationcoef');
775 } elseif ($mode == 'advanced') {
776 return false;
777 }
778 }
779}
780
781class grade_edit_tree_column_range extends grade_edit_tree_column {
782
783 public function get_header_cell() {
54a007e8 784 $headercell = clone($this->headercell);
785 $headercell->text = get_string('maxgrade', 'grades');
786 return $headercell;
dc482cfa 787 }
788
789 public function get_category_cell($category, $levelclass, $params) {
54a007e8 790 $categorycell = clone($this->categorycell);
16be8974 791 $categorycell->attributes['class'] .= ' range ' . $levelclass;
54a007e8 792 $categorycell->text = ' - ';
793 return $categorycell;
dc482cfa 794 }
795
796 public function get_item_cell($item, $params) {
1c1f64a2 797 global $DB, $OUTPUT;
46409b20 798
799 // If the parent aggregation is Sum of Grades, this cannot be changed
800 $parent_cat = $item->get_parent_category();
801 if ($parent_cat->aggregation == GRADE_AGGREGATE_SUM) {
802 $grademax = format_float($item->grademax, $item->get_decimals());
803 } elseif ($item->gradetype == GRADE_TYPE_SCALE) {
3998cc5c 804 $scale = $DB->get_record('scale', array('id' => $item->scaleid));
e2a84477
AD
805 $scale_items = null;
806 if (empty($scale)) { //if the item is using a scale that's been removed
807 $scale_items = array();
808 } else {
809 $scale_items = explode(',', $scale->scale);
810 }
dc482cfa 811 $grademax = end($scale_items) . ' (' . count($scale_items) . ')';
812 } elseif ($item->is_external_item()) {
813 $grademax = format_float($item->grademax, $item->get_decimals());
814 } else {
b1fec412
RW
815 $grademax = '<label class="accesshide" for="grademax'.$item->id.'">'.get_string('grademax', 'grades').'</label>';
816 $grademax .= '<input type="text" size="6" id="grademax'.$item->id.'" name="grademax_'.$item->id.'" value="'.format_float($item->grademax, $item->get_decimals()).'" />';
dc482cfa 817 }
818
54a007e8 819 $itemcell = clone($this->itemcell);
820 $itemcell->text = $grademax;
821 return $itemcell;
dc482cfa 822 }
823
824 public function is_hidden($mode='simple') {
825 global $CFG;
826 if ($mode == 'simple') {
827 return strstr($CFG->grade_item_advanced, 'grademax');
828 } elseif ($mode == 'advanced') {
829 return false;
830 }
831 }
832}
833
834class grade_edit_tree_column_aggregateonlygraded extends grade_edit_tree_column_category {
835
836 public function __construct($params) {
837 parent::__construct('aggregateonlygraded');
838 }
839
840 public function get_header_cell() {
c3b834b4 841 global $OUTPUT;
54a007e8 842 $headercell = clone($this->headercell);
843 $headercell->style .= 'width: 40px;';
71297a3f 844 $headercell->text = get_string('aggregateonlygraded', 'grades')
be3df7fb 845 . $OUTPUT->help_icon('aggregateonlygraded', 'grades');
54a007e8 846 return $headercell;
dc482cfa 847 }
848
849 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
850 $onlygradedcheck = ($category->aggregateonlygraded == 1) ? 'checked="checked"' : '';
851 $hidden = '<input type="hidden" name="aggregateonlygraded_'.$category->id.'" value="0" />';
852 $aggregateonlygraded ='<input type="checkbox" id="aggregateonlygraded_'.$category->id.'" name="aggregateonlygraded_'.$category->id.'" value="1" '.$onlygradedcheck . ' />';
dc482cfa 853
854 if ($this->forced) {
855 $aggregateonlygraded = ($category->aggregateonlygraded) ? get_string('yes') : get_string('no');
856 }
857
54a007e8 858 $categorycell = clone($this->categorycell);
16be8974 859 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 860 $categorycell->text = $hidden.$aggregateonlygraded;
54a007e8 861 return $categorycell;
dc482cfa 862 }
863
864 public function get_item_cell($item, $params) {
54a007e8 865 $itemcell = clone($this->itemcell);
866 $itemcell->text = ' - ';
867 return $itemcell;
dc482cfa 868 }
869}
870
871class grade_edit_tree_column_aggregatesubcats extends grade_edit_tree_column_category {
872
873 public function __construct($params) {
874 parent::__construct('aggregatesubcats');
875 }
876
877 public function get_header_cell() {
c3b834b4 878 global $OUTPUT;
54a007e8 879 $headercell = clone($this->headercell);
880 $headercell->style .= 'width: 40px;';
881 $headercell->text = get_string('aggregatesubcats', 'grades')
cb616be8 882 .$OUTPUT->help_icon('aggregatesubcats', 'grades');
54a007e8 883 return $headercell;
dc482cfa 884 }
885
886 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
887 $subcatscheck = ($category->aggregatesubcats == 1) ? 'checked="checked"' : '';
888 $hidden = '<input type="hidden" name="aggregatesubcats_'.$category->id.'" value="0" />';
889 $aggregatesubcats = '<input type="checkbox" id="aggregatesubcats_'.$category->id.'" name="aggregatesubcats_'.$category->id.'" value="1" ' . $subcatscheck.' />';
dc482cfa 890
891 if ($this->forced) {
892 $aggregatesubcats = ($category->aggregatesubcats) ? get_string('yes') : get_string('no');
893 }
894
54a007e8 895 $categorycell = clone($this->categorycell);
16be8974 896 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 897 $categorycell->text = $hidden.$aggregatesubcats;
54a007e8 898 return $categorycell;
dc482cfa 899
900 }
901
902 public function get_item_cell($item, $params) {
54a007e8 903 $itemcell = clone($this->itemcell);
904 $itemcell->text = ' - ';
905 return $itemcell;
dc482cfa 906 }
907}
908
909class grade_edit_tree_column_aggregateoutcomes extends grade_edit_tree_column_category {
910
911 public function __construct($params) {
912 parent::__construct('aggregateoutcomes');
913 }
914
915 public function get_header_cell() {
c3b834b4 916 global $OUTPUT;
54a007e8 917 $headercell = clone($this->headercell);
918 $headercell->style .= 'width: 40px;';
919 $headercell->text = get_string('aggregateoutcomes', 'grades')
3f781a22 920 .$OUTPUT->help_icon('aggregateoutcomes', 'grades');
54a007e8 921 return $headercell;
dc482cfa 922 }
923
924 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
925 $outcomescheck = ($category->aggregateoutcomes == 1) ? 'checked="checked"' : '';
926 $hidden = '<input type="hidden" name="aggregateoutcomes_'.$category->id.'" value="0" />';
927 $aggregateoutcomes = '<input type="checkbox" id="aggregateoutcomes_'.$category->id.'" name="aggregateoutcomes_'.$category->id.'" value="1" ' . $outcomescheck.' />';
dc482cfa 928
929 if ($this->forced) {
930 $aggregateoutcomes = ($category->aggregateoutcomes) ? get_string('yes') : get_string('no');
931 }
932
54a007e8 933 $categorycell = clone($this->categorycell);
16be8974 934 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 935 $categorycell->text = $hidden.$aggregateoutcomes;
54a007e8 936 return $categorycell;
dc482cfa 937 }
938
939 public function get_item_cell($item, $params) {
54a007e8 940 $itemcell = clone($this->itemcell);
941 $itemcell->text = ' - ';
942 return $itemcell;
dc482cfa 943 }
944
945 public function is_hidden($mode='simple') {
946 global $CFG;
947 if ($CFG->enableoutcomes) {
948 return parent::is_hidden($mode);
949 } else {
950 return true;
951 }
952 }
953}
954
955class grade_edit_tree_column_droplow extends grade_edit_tree_column_category {
956
957 public function __construct($params) {
958 parent::__construct('droplow');
959 }
960
961 public function get_header_cell() {
c3b834b4 962 global $OUTPUT;
54a007e8 963 $headercell = clone($this->headercell);
b37760fc 964 $headercell->text = get_string('droplow', 'grades').$OUTPUT->help_icon('droplow', 'grades');
54a007e8 965 return $headercell;
dc482cfa 966 }
967
968 public function get_category_cell($category, $levelclass, $params) {
b1fec412
RW
969 $droplow = '<label class="accesshide" for="droplow_'.$category->id.'">'.get_string('droplowestvalue', 'grades').'</label>';
970 $droplow .= '<input type="text" size="3" id="droplow_'.$category->id.'" name="droplow_'.$category->id.'" value="'.$category->droplow.'" />';
dc482cfa 971
972 if ($this->forced) {
973 $droplow = $category->droplow;
974 }
975
54a007e8 976 $categorycell = clone($this->categorycell);
16be8974 977 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 978 $categorycell->text = $droplow;
979 return $categorycell;
dc482cfa 980 }
981
982 public function get_item_cell($item, $params) {
54a007e8 983 $itemcell = clone($this->itemcell);
984 $itemcell->text = ' - ';
985 return $itemcell;
dc482cfa 986 }
987}
988
989class grade_edit_tree_column_keephigh extends grade_edit_tree_column_category {
990
991 public function __construct($params) {
992 parent::__construct('keephigh');
993 }
994
995 public function get_header_cell() {
c3b834b4 996 global $OUTPUT;
54a007e8 997 $headercell = clone($this->headercell);
cb616be8 998 $headercell->text = get_string('keephigh', 'grades').$OUTPUT->help_icon('keephigh', 'grades');
54a007e8 999 return $headercell;
dc482cfa 1000 }
1001
1002 public function get_category_cell($category, $levelclass, $params) {
b1fec412
RW
1003 $keephigh = '<label class="accesshide" for="keephigh_'.$category->id.'">'.get_string('keephigh', 'grades').'</label>';
1004 $keephigh .= '<input type="text" size="3" id="keephigh_'.$category->id.'" name="keephigh_'.$category->id.'" value="'.$category->keephigh.'" />';
dc482cfa 1005
1006 if ($this->forced) {
1007 $keephigh = $category->keephigh;
1008 }
1009
54a007e8 1010 $categorycell = clone($this->categorycell);
16be8974 1011 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1012 $categorycell->text = $keephigh;
1013 return $categorycell;
dc482cfa 1014 }
1015
1016 public function get_item_cell($item, $params) {
54a007e8 1017 $itemcell = clone($this->itemcell);
1018 $itemcell->text = ' - ';
1019 return $itemcell;
dc482cfa 1020 }
1021}
1022
1023class grade_edit_tree_column_multfactor extends grade_edit_tree_column {
1024
1025 public function __construct($params) {
54a007e8 1026 parent::__construct();
dc482cfa 1027 }
1028
1029 public function get_header_cell() {
c3b834b4 1030 global $OUTPUT;
54a007e8 1031 $headercell = clone($this->headercell);
d4a11ee5 1032 $headercell->text = get_string('multfactor', 'grades').$OUTPUT->help_icon('multfactor', 'grades');
54a007e8 1033 return $headercell;
dc482cfa 1034 }
1035
1036 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1037 $categorycell = clone($this->categorycell);
16be8974 1038 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1039 $categorycell->text = ' - ';
1040 return $categorycell;
dc482cfa 1041 }
1042
1043 public function get_item_cell($item, $params) {
54a007e8 1044 global $OUTPUT;
1045
1046 $itemcell = clone($this->itemcell);
a043086f 1047 if (!$item->is_raw_used()) {
54a007e8 1048 $itemcell->text = '&nbsp;';
1049 return $itemcell;
a043086f 1050 }
b1fec412
RW
1051 $multfactor = '<label class="accesshide" for="multfactor'.$item->id.'">'.get_string('multfactorvalue', 'grades', $item->itemname).'</label>';
1052 $multfactor .= '<input type="text" size="4" id="multfactor'.$item->id.'" name="multfactor_'.$item->id.'" value="'.grade_edit_tree::format_number($item->multfactor).'" />';
54a007e8 1053
7d89f0b0 1054 $itemcell->text = $multfactor;
54a007e8 1055 return $itemcell;
dc482cfa 1056 }
1057
1058 public function is_hidden($mode='simple') {
1059 global $CFG;
1060 if ($mode == 'simple') {
1061 return strstr($CFG->grade_item_advanced, 'multfactor');
1062 } elseif ($mode == 'advanced') {
1063 return false;
1064 }
1065 }
1066}
1067
1068class grade_edit_tree_column_plusfactor extends grade_edit_tree_column {
1069
1070 public function get_header_cell() {
c3b834b4 1071 global $OUTPUT;
54a007e8 1072 $headercell = clone($this->headercell);
12b0938c 1073 $headercell->text = get_string('plusfactor', 'grades').$OUTPUT->help_icon('plusfactor', 'grades');
54a007e8 1074 return $headercell;
dc482cfa 1075 }
1076
1077 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1078 $categorycell = clone($this->categorycell);
16be8974 1079 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1080 $categorycell->text = ' - ';
1081 return $categorycell;
dc482cfa 1082
1083 }
1084
1085 public function get_item_cell($item, $params) {
54a007e8 1086 global $OUTPUT;
1087
1088 $itemcell = clone($this->itemcell);
a043086f 1089 if (!$item->is_raw_used()) {
54a007e8 1090 $itemcell->text = '&nbsp;';
1091 return $itemcell;
a043086f 1092 }
54a007e8 1093
b1fec412
RW
1094 $plusfactor = '<label class="accesshide" for="plusfactor_'. $item->id . '">'.get_string('plusfactorvalue', 'grades', $item->itemname).'</label>';
1095 $plusfactor .= '<input type="text" size="4" id="plusfactor_'.$item->id.'" name="plusfactor_'.$item->id.'" value="'.grade_edit_tree::format_number($item->plusfactor).'" />';
916276fc 1096
7d89f0b0 1097 $itemcell->text = $plusfactor;
54a007e8 1098 return $itemcell;
dc482cfa 1099
1100 }
1101
1102 public function is_hidden($mode='simple') {
1103 global $CFG;
1104 if ($mode == 'simple') {
1105 return strstr($CFG->grade_item_advanced, 'plusfactor');
1106 } elseif ($mode == 'advanced') {
1107 return false;
1108 }
1109 }
1110}
1111
1112class grade_edit_tree_column_actions extends grade_edit_tree_column {
1113
1114 public function __construct($params) {
71297a3f 1115 parent::__construct();
dc482cfa 1116 }
1117
1118 public function get_header_cell() {
54a007e8 1119 $headercell = clone($this->headercell);
16be8974 1120 $headercell->attributes['class'] .= ' actions';
54a007e8 1121 $headercell->text = get_string('actions');
1122 return $headercell;
dc482cfa 1123 }
1124
1125 public function get_category_cell($category, $levelclass, $params) {
1126
1127 if (empty($params['actions'])) {
1128 throw new Exception('Array key (actions) missing from 3rd param of grade_edit_tree_column_actions::get_category_actions($category, $levelclass, $params)');
1129 }
1130
54a007e8 1131 $categorycell = clone($this->categorycell);
16be8974 1132 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1133 $categorycell->text = $params['actions'];
1134 return $categorycell;
dc482cfa 1135 }
1136
1137 public function get_item_cell($item, $params) {
1138 if (empty($params['actions'])) {
1139 throw new Exception('Array key (actions) missing from 2nd param of grade_edit_tree_column_actions::get_item_cell($item, $params)');
1140 }
54a007e8 1141 $itemcell = clone($this->itemcell);
16be8974 1142 $itemcell->attributes['class'] .= ' actions';
54a007e8 1143 $itemcell->text = $params['actions'];
1144 return $itemcell;
dc482cfa 1145 }
1146
1147 public function is_hidden($mode='simple') {
1148 return false;
1149 }
1150}
1151
1152class grade_edit_tree_column_select extends grade_edit_tree_column {
1153
1154 public function get_header_cell() {
54a007e8 1155 $headercell = clone($this->headercell);
16be8974 1156 $headercell->attributes['class'] .= ' selection';
54a007e8 1157 $headercell->text = get_string('select');
1158 return $headercell;
dc482cfa 1159 }
1160
1161 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1162 global $OUTPUT;
dc482cfa 1163 if (empty($params['eid'])) {
1164 throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
1165 }
4ee753eb
PS
1166 $selectall = new action_link(new moodle_url('#'), get_string('all'), new component_action('click', 'togglecheckboxes', array('eid' => $params['eid'], 'check' => true)));
1167 $selectnone = new action_link(new moodle_url('#'), get_string('none'), new component_action('click', 'togglecheckboxes', array('eid' => $params['eid'], 'check' => false)));
dc482cfa 1168
54a007e8 1169 $categorycell = clone($this->categorycell);
16be8974 1170 $categorycell->attributes['class'] .= ' last ' . $levelclass;
54a007e8 1171 $categorycell->style .= 'text-align: center;';
4ee753eb 1172 $categorycell->text = $OUTPUT->render($selectall) . '<br />' . $OUTPUT->render($selectnone);
54a007e8 1173 return $categorycell;
dc482cfa 1174 }
1175
1176 public function get_item_cell($item, $params) {
54a007e8 1177 if (empty($params['itemtype']) || empty($params['eid'])) {
2f0e96e4 1178 error('Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)');
54a007e8 1179 }
1180 $itemselect = '';
1181
1182 if ($params['itemtype'] != 'course' && $params['itemtype'] != 'category') {
2f0e96e4 1183 $itemselect = '<input class="itemselect" type="checkbox" name="select_'.$params['eid'].'" onchange="toggleCategorySelector();"/>'; // TODO: convert to YUI handler
dc482cfa 1184 }
5174f3c5
AD
1185 //html_writer::table() will wrap the item cell contents in a <TD> so don't do it here
1186 return $itemselect;
dc482cfa 1187 }
1188
1189 public function is_hidden($mode='simple') {
1190 return false;
1191 }
1192}
6c3ef410 1193