weekly release 2.8dev
[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 /**
39873128 29 * @var grade_tree $gtree @see grade/lib.php
dc482cfa 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
54a007e8 276 $levelclass = "level$level";
2be6ca78 277
b189277f 278 $courseclass = '';
279 if ($level == 1) {
280 $courseclass = 'coursecategory';
281 }
71297a3f 282
54a007e8 283 $row = new html_table_row();
16be8974 284 $row->attributes['class'] = $courseclass . ' category ' . $dimmed;
54a007e8 285 foreach ($rowclasses as $class) {
16be8974 286 $row->attributes['class'] .= ' ' . $class;
54a007e8 287 }
dc482cfa 288
54a007e8 289 $headercell = new html_table_cell();
290 $headercell->header = true;
291 $headercell->scope = 'row';
16be8974
DM
292 $headercell->attributes['title'] = $object->stripped_name;
293 $headercell->attributes['class'] = 'cell rowspan ' . $levelclass;
bd26d932 294 $headercell->rowspan = $row_count + 1;
54a007e8 295 $row->cells[] = $headercell;
dc482cfa 296
297 foreach ($this->columns as $column) {
298 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
54a007e8 299 $row->cells[] = $column->get_category_cell($category, $levelclass, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'eid' => $eid));
dc482cfa 300 }
301 }
71297a3f 302
54a007e8 303 $returnrows[] = $row;
dc482cfa 304
54a007e8 305 $returnrows = array_merge($returnrows, $html_children);
dc482cfa 306
6ef4878b 307 // Print a coloured row to show the end of the category across the table
54a007e8 308 $endcell = new html_table_cell();
309 $endcell->colspan = (19 - $level);
16be8974 310 $endcell->attributes['class'] = 'colspan ' . $levelclass;
54a007e8 311
0e35ba6f 312 $returnrows[] = new html_table_row(array($endcell));
dc482cfa 313
314 } else { // Dealing with a grade item
315
316 $item = grade_item::fetch(array('id' => $object->id));
317 $element['type'] = 'item';
318 $element['object'] = $item;
2be6ca78 319
b189277f 320 $categoryitemclass = '';
321 if ($item->itemtype == 'category') {
322 $categoryitemclass = 'categoryitem';
323 }
dc482cfa 324
54a007e8 325 $dimmed = ($item->is_hidden()) ? "dimmed_text" : "";
326 $gradeitemrow = new html_table_row();
16be8974 327 $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
54a007e8 328 foreach ($rowclasses as $class) {
16be8974 329 $gradeitemrow->attributes['class'] .= ' ' . $class;
54a007e8 330 }
dc482cfa 331
332 foreach ($this->columns as $column) {
333 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
54a007e8 334 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions,
dc482cfa 335 'element' => $element, 'eid' => $eid, 'itemtype' => $object->itemtype));
336 }
337 }
338
54a007e8 339 $returnrows[] = $gradeitemrow;
dc482cfa 340 }
341
54a007e8 342 return $returnrows;
dc482cfa 343
344 }
345
346 /**
347 * Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
348 * @param grade_item $item
653a8648 349 * @param string type "extra" or "weight": the type of the column hosting the weight input
dc482cfa 350 * @return string HTML
351 */
e2bb3c92 352 static function get_weight_input($item, $type) {
1c1f64a2 353 global $OUTPUT;
354
dc482cfa 355 if (!is_object($item) || get_class($item) !== 'grade_item') {
356 throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
357 return false;
358 }
359
360 if ($item->is_course_item()) {
361 return '';
362 }
363
364 $parent_category = $item->get_parent_category();
dc482cfa 365 $parent_category->apply_forced_settings();
653a8648 366 $aggcoef = $item->get_coefstring();
dc482cfa 367
653a8648 368 if ((($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef') && $type == 'weight') ||
3869ab1a 369 ($aggcoef == 'aggregationcoefextraweight' && $type == 'extra')) {
7400be1b
RT
370 return '<label class="accesshide" for="aggregationcoef_'.$item->id.'">'.
371 get_string('extracreditvalue', 'grades', $item->itemname).'</label>'.
b1fec412 372 '<input type="text" size="6" id="aggregationcoef_'.$item->id.'" name="aggregationcoef_'.$item->id.'"
3cf33f51 373 value="'.grade_edit_tree::format_number($item->aggregationcoef).'" />';
653a8648 374 } elseif ($aggcoef == 'aggregationcoefextrasum' && $type == 'extra') {
cd3a391c 375 $checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
916276fc 376 return '<input type="hidden" name="extracredit_'.$item->id.'" value="0" />
7400be1b
RT
377 <label class="accesshide" for="extracredit_'.$item->id.'">'.
378 get_string('extracreditvalue', 'grades', $item->itemname).'</label>
379 <input type="checkbox" id="extracredit_'.$item->id.'" name="extracredit_'.$item->id.'" value="1" '."$checked />\n";
cd3a391c 380 } else {
381 return '';
dc482cfa 382 }
cd3a391c 383 }
dc482cfa 384
6ef4878b 385 //Trims trailing zeros
4592df46 386 //Used on the 'categories and items' page for grade items settings like aggregation co-efficient
e229506d 387 //Grader report has its own decimal place settings so they are handled elsewhere
e2bb3c92 388 static function format_number($number) {
4592df46 389 $formatted = rtrim(format_float($number, 4),'0');
dacd5daa 390 if (substr($formatted, -1)==get_string('decsep', 'langconfig')) { //if last char is the decimal point
4592df46
AD
391 $formatted .= '0';
392 }
393 return $formatted;
3cf33f51
AD
394 }
395
dc482cfa 396 /**
397 * Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable)
398 *
399 * @param array $element
400 * @return bool
401 */
402 function element_deletable($element) {
403 global $COURSE;
404
405 if ($element['type'] != 'item') {
406 return true;
407 }
408
409 $grade_item = $element['object'];
410
411 if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) {
412 return true;
413 }
414
415 $modinfo = get_fast_modinfo($COURSE);
416 if (!isset($modinfo->instances[$grade_item->itemmodule][$grade_item->iteminstance])) {
417 // module does not exist
418 return true;
419 }
420
421 return false;
422 }
423
424 /**
425 * Given the grade tree and an array of element ids (e.g. c15, i42), and expecting the 'moveafter' URL param,
426 * moves the selected items to the requested location. Then redirects the user to the given $returnurl
427 *
428 * @param object $gtree The grade tree (a recursive representation of the grade categories and grade items)
429 * @param array $eids
430 * @param string $returnurl
431 */
432 function move_elements($eids, $returnurl) {
433 $moveafter = required_param('moveafter', PARAM_INT);
434
435 if (!is_array($eids)) {
436 $eids = array($eids);
437 }
438
439 if(!$after_el = $this->gtree->locate_element("c$moveafter")) {
440 print_error('invalidelementid', '', $returnurl);
441 }
442
443 $after = $after_el['object'];
444 $parent = $after;
445 $sortorder = $after->get_sortorder();
446
447 foreach ($eids as $eid) {
448 if (!$element = $this->gtree->locate_element($eid)) {
449 print_error('invalidelementid', '', $returnurl);
450 }
451 $object = $element['object'];
452
453 $object->set_parent($parent->id);
454 $object->move_after_sortorder($sortorder);
4d2f7923 455 $sortorder++;
dc482cfa 456 }
457
458 redirect($returnurl, '', 0);
459 }
460
461 /**
462 * Recurses through the entire grade tree to find and return the maximum depth of the tree.
463 * This should be run only once from the root element (course category), and is used for the
464 * indentation of the Name column's cells (colspan)
465 *
466 * @param array $element An array of values representing a grade tree's element (all grade items in this case)
467 * @param int $level The level of the current recursion
468 * @param int $deepest_level A value passed to each subsequent level of recursion and incremented if $level > $deepest_level
469 * @return int Deepest level
470 */
471 function get_deepest_level($element, $level=0, $deepest_level=1) {
472 $object = $element['object'];
473
474 $level++;
653a8648 475 $coefstring = $element['object']->get_coefstring();
dc482cfa 476 if ($element['type'] == 'category') {
653a8648 477 if ($coefstring == 'aggregationcoefweight') {
478 $this->uses_weight = true;
3869ab1a 479 } elseif ($coefstring == 'aggregationcoefextraweight' || $coefstring == 'aggregationcoefextrasum') {
653a8648 480 $this->uses_extra_credit = true;
481 }
482
dc482cfa 483 foreach($element['children'] as $child_el) {
484 if ($level > $deepest_level) {
485 $deepest_level = $level;
486 }
487 $deepest_level = $this->get_deepest_level($child_el, $level, $deepest_level);
488 }
489 }
490
491 return $deepest_level;
492 }
493}
494
495abstract class grade_edit_tree_column {
496 public $forced;
497 public $hidden;
498 public $forced_hidden;
499 public $advanced_hidden;
500 public $hide_when_moving = true;
54a007e8 501 /**
502 * html_table_cell object used as a template for header cells in all categories.
503 * It must be cloned before being used.
504 * @var html_table_cell $headercell
505 */
506 public $headercell;
507 /**
508 * html_table_cell object used as a template for category cells in all categories.
509 * It must be cloned before being used.
510 * @var html_table_cell $categorycell
511 */
512 public $categorycell;
513 /**
514 * html_table_cell object used as a template for item cells in all categories.
515 * It must be cloned before being used.
516 * @var html_table_cell $itemcell
517 */
518 public $itemcell;
dc482cfa 519
520 public static function factory($name, $params=array()) {
521 $class_name = "grade_edit_tree_column_$name";
522 if (class_exists($class_name)) {
523 return new $class_name($params);
524 }
525 }
526
527 public abstract function get_header_cell();
528
529 public abstract function get_category_cell($category, $levelclass, $params);
530
531 public abstract function get_item_cell($item, $params);
532
533 public abstract function is_hidden($mode='simple');
54a007e8 534
535 public function __construct() {
536 $this->headercell = new html_table_cell();
537 $this->headercell->header = true;
538 $this->headercell->style = 'whitespace: normal;';
16be8974 539 $this->headercell->attributes['class'] = 'header';
54a007e8 540
541 $this->categorycell = new html_table_cell();
16be8974 542 $this->categorycell->attributes['class'] = 'cell';
54a007e8 543
544 $this->itemcell = new html_table_cell();
16be8974 545 $this->itemcell->attributes['class'] = 'cell';
54a007e8 546 }
dc482cfa 547}
548
549abstract class grade_edit_tree_column_category extends grade_edit_tree_column {
550
551 public $forced;
552 public $advanced;
553
554 public function __construct($name) {
555 global $CFG;
556 $this->forced = (int)$CFG->{"grade_$name"."_flag"} & 1;
557 $this->advanced = (int)$CFG->{"grade_$name"."_flag"} & 2;
54a007e8 558 parent::__construct();
dc482cfa 559 }
560
561 public function is_hidden($mode='simple') {
562 global $CFG;
563 if ($mode == 'simple') {
564 return $this->advanced;
565 } elseif ($mode == 'advanced') {
566 if ($this->forced && $CFG->grade_hideforcedsettings) {
567 return true;
568 } else {
569 return false;
570 }
571 }
572 }
573}
574
575class grade_edit_tree_column_name extends grade_edit_tree_column {
576 public $forced = false;
577 public $hidden = false;
578 public $forced_hidden = false;
579 public $advanced_hidden = false;
580 public $deepest_level = 1;
581 public $hide_when_moving = false;
582
583 public function __construct($params) {
584 if (empty($params['deepest_level'])) {
585 throw new Exception('Tried to instantiate a grade_edit_tree_column_name object without the "deepest_level" param!');
586 }
587
588 $this->deepest_level = $params['deepest_level'];
54a007e8 589 parent::__construct();
dc482cfa 590 }
591
592 public function get_header_cell() {
54a007e8 593 $headercell = clone($this->headercell);
16be8974 594 $headercell->attributes['class'] .= ' name';
54a007e8 595 $headercell->colspan = $this->deepest_level + 1;
596 $headercell->text = get_string('name');
597 return $headercell;
dc482cfa 598 }
599
600 public function get_category_cell($category, $levelclass, $params) {
54a007e8 601 global $OUTPUT;
dc482cfa 602 if (empty($params['name']) || empty($params['level'])) {
603 throw new Exception('Array key (name or level) missing from 3rd param of grade_edit_tree_column_name::get_category_cell($category, $levelclass, $params)');
604 }
54a007e8 605 $categorycell = clone($this->categorycell);
16be8974 606 $categorycell->attributes['class'] .= ' name ' . $levelclass;
54a007e8 607 $categorycell->colspan = ($this->deepest_level +1) - $params['level'];
608 $categorycell->text = $OUTPUT->heading($params['name'], 4);
609 return $categorycell;
dc482cfa 610 }
611
612 public function get_item_cell($item, $params) {
613 global $CFG;
614
615 if (empty($params['element']) || empty($params['name']) || empty($params['level'])) {
616 throw new Exception('Array key (name, level or element) missing from 2nd param of grade_edit_tree_column_name::get_item_cell($item, $params)');
617 }
618
619 $name = $params['name'];
620
54a007e8 621 $itemcell = clone($this->itemcell);
16be8974 622 $itemcell->attributes['class'] .= ' name';
54a007e8 623 $itemcell->colspan = ($this->deepest_level + 1) - $params['level'];
624 $itemcell->text = $name;
625 return $itemcell;
dc482cfa 626 }
627
628 public function is_hidden($mode='simple') {
629 return false;
630 }
631}
632
633class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category {
634
635 public function __construct($params) {
636 parent::__construct('aggregation');
637 }
638
639 public function get_header_cell() {
c3b834b4 640 global $OUTPUT;
54a007e8 641 $headercell = clone($this->headercell);
f89b71eb 642 $headercell->text = get_string('aggregation', 'grades').$OUTPUT->help_icon('aggregation', 'grades');
54a007e8 643 return $headercell;
dc482cfa 644 }
645
646 public function get_category_cell($category, $levelclass, $params) {
0a95bebf 647 global $CFG, $OUTPUT;
dc482cfa 648 if (empty($params['id'])) {
649 throw new Exception('Array key (id) missing from 3rd param of grade_edit_tree_column_aggregation::get_category_cell($category, $levelclass, $params)');
650 }
651
652 $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'),
653 GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'),
654 GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'),
655 GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'),
656 GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'),
657 GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'),
658 GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'),
659 GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'),
660 GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
661
653a8648 662 $visible = explode(',', $CFG->grade_aggregations_visible);
663 foreach ($options as $constant => $string) {
664 if (!in_array($constant, $visible) && $constant != $category->aggregation) {
665 unset($options[$constant]);
666 }
667 }
668
dc482cfa 669 if ($this->forced) {
670 $aggregation = $options[$category->aggregation];
064527d6
PS
671 } else {
672 $attributes = array();
673 $attributes['id'] = 'aggregation_'.$category->id;
742d9165 674 $attributes['class'] = 'ignoredirty';
29bea634
RW
675 $aggregation = html_writer::label(get_string('aggregation', 'grades'), 'aggregation_'.$category->id, false, array('class' => 'accesshide'));
676 $aggregation .= html_writer::select($options, 'aggregation_'.$category->id, $category->aggregation, null, $attributes);
064527d6 677 $action = new component_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
c80877aa 678 $OUTPUT->add_action_handler($action, 'aggregation_'.$category->id);
dc482cfa 679 }
680
54a007e8 681 $categorycell = clone($this->categorycell);
16be8974 682 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 683 $categorycell->text = $aggregation;
684 return $categorycell;
dc482cfa 685
686 }
687
688 public function get_item_cell($item, $params) {
54a007e8 689 $itemcell = clone($this->itemcell);
690 $itemcell->text = ' - ';
691 return $itemcell;
dc482cfa 692 }
693}
694
653a8648 695class grade_edit_tree_column_extracredit extends grade_edit_tree_column {
696
697 public function get_header_cell() {
c3b834b4 698 global $OUTPUT;
54a007e8 699 $headercell = clone($this->headercell);
3869ab1a 700 $headercell->text = get_string('aggregationcoefextra', 'grades').$OUTPUT->help_icon('aggregationcoefextra', 'grades');
54a007e8 701 return $headercell;
653a8648 702 }
703
704 public function get_category_cell($category, $levelclass, $params) {
653a8648 705 $item = $category->get_grade_item();
54a007e8 706 $categorycell = clone($this->categorycell);
16be8974 707 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 708 $categorycell->text = grade_edit_tree::get_weight_input($item, 'extra');
709 return $categorycell;
653a8648 710 }
711
712 public function get_item_cell($item, $params) {
713 if (empty($params['element'])) {
714 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
715 }
716
54a007e8 717 $itemcell = clone($this->itemcell);
718 $itemcell->text = '&nbsp;';
653a8648 719
720 if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
54a007e8 721 $itemcell->text = grade_edit_tree::get_weight_input($item, 'extra');
653a8648 722 }
723
54a007e8 724 return $itemcell;
653a8648 725 }
726
727 public function is_hidden($mode='simple') {
728 global $CFG;
729 if ($mode == 'simple') {
730 return strstr($CFG->grade_item_advanced, 'aggregationcoef');
731 } elseif ($mode == 'advanced') {
732 return false;
733 }
734 }
735}
736
737class grade_edit_tree_column_weight extends grade_edit_tree_column {
dc482cfa 738
739 public function get_header_cell() {
c3b834b4 740 global $OUTPUT;
54a007e8 741 $headercell = clone($this->headercell);
3869ab1a 742 $headercell->text = get_string('weightuc', 'grades').$OUTPUT->help_icon('aggregationcoefweight', 'grades');
54a007e8 743 return $headercell;
dc482cfa 744 }
745
746 public function get_category_cell($category, $levelclass, $params) {
747
748 $item = $category->get_grade_item();
54a007e8 749 $categorycell = clone($this->categorycell);
16be8974 750 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 751 $categorycell->text = grade_edit_tree::get_weight_input($item, 'weight');
752 return $categorycell;
dc482cfa 753 }
754
755 public function get_item_cell($item, $params) {
756 if (empty($params['element'])) {
757 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
758 }
54a007e8 759 $itemcell = clone($this->itemcell);
760 $itemcell->text = '&nbsp;';
dc482cfa 761
b8436ccb 762 if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
54a007e8 763 $itemcell->text = grade_edit_tree::get_weight_input($item, 'weight');
dc482cfa 764 }
765
54a007e8 766 return $itemcell;
dc482cfa 767 }
768
769 public function is_hidden($mode='simple') {
770 global $CFG;
771 if ($mode == 'simple') {
772 return strstr($CFG->grade_item_advanced, 'aggregationcoef');
773 } elseif ($mode == 'advanced') {
774 return false;
775 }
776 }
777}
778
779class grade_edit_tree_column_range extends grade_edit_tree_column {
780
781 public function get_header_cell() {
54a007e8 782 $headercell = clone($this->headercell);
783 $headercell->text = get_string('maxgrade', 'grades');
784 return $headercell;
dc482cfa 785 }
786
787 public function get_category_cell($category, $levelclass, $params) {
54a007e8 788 $categorycell = clone($this->categorycell);
16be8974 789 $categorycell->attributes['class'] .= ' range ' . $levelclass;
54a007e8 790 $categorycell->text = ' - ';
791 return $categorycell;
dc482cfa 792 }
793
794 public function get_item_cell($item, $params) {
1c1f64a2 795 global $DB, $OUTPUT;
46409b20 796
e3a65c9e
EM
797 // If the parent aggregation is Sum of Grades, we should show the number, even for scales, as that value is used...
798 // ...in the computation. For text grades, the grademax is not used, so we can still show the no value string.
46409b20 799 $parent_cat = $item->get_parent_category();
e3a65c9e
EM
800 if ($item->gradetype == GRADE_TYPE_TEXT) {
801 $grademax = ' - ';
802 } else if ($parent_cat->aggregation == GRADE_AGGREGATE_SUM) {
46409b20 803 $grademax = format_float($item->grademax, $item->get_decimals());
804 } elseif ($item->gradetype == GRADE_TYPE_SCALE) {
3998cc5c 805 $scale = $DB->get_record('scale', array('id' => $item->scaleid));
e2a84477
AD
806 $scale_items = null;
807 if (empty($scale)) { //if the item is using a scale that's been removed
808 $scale_items = array();
809 } else {
810 $scale_items = explode(',', $scale->scale);
811 }
dc482cfa 812 $grademax = end($scale_items) . ' (' . count($scale_items) . ')';
813 } elseif ($item->is_external_item()) {
814 $grademax = format_float($item->grademax, $item->get_decimals());
815 } else {
7400be1b
RT
816 $grademax = '<label class="accesshide" for="grademax'.$item->id.'">'.get_string('grademax', 'grades').'</label>
817 <input type="text" size="6" id="grademax'.$item->id.'" name="grademax_'.$item->id.'" value="'.
818 format_float($item->grademax, $item->get_decimals()).'" />';
dc482cfa 819 }
820
54a007e8 821 $itemcell = clone($this->itemcell);
822 $itemcell->text = $grademax;
823 return $itemcell;
dc482cfa 824 }
825
826 public function is_hidden($mode='simple') {
827 global $CFG;
828 if ($mode == 'simple') {
829 return strstr($CFG->grade_item_advanced, 'grademax');
830 } elseif ($mode == 'advanced') {
831 return false;
832 }
833 }
834}
835
836class grade_edit_tree_column_aggregateonlygraded extends grade_edit_tree_column_category {
837
838 public function __construct($params) {
839 parent::__construct('aggregateonlygraded');
840 }
841
842 public function get_header_cell() {
c3b834b4 843 global $OUTPUT;
54a007e8 844 $headercell = clone($this->headercell);
845 $headercell->style .= 'width: 40px;';
71297a3f 846 $headercell->text = get_string('aggregateonlygraded', 'grades')
be3df7fb 847 . $OUTPUT->help_icon('aggregateonlygraded', 'grades');
54a007e8 848 return $headercell;
dc482cfa 849 }
850
851 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
852 $onlygradedcheck = ($category->aggregateonlygraded == 1) ? 'checked="checked"' : '';
853 $hidden = '<input type="hidden" name="aggregateonlygraded_'.$category->id.'" value="0" />';
7400be1b
RT
854 $aggregateonlygraded = '<label class="accesshide" for="aggregateonlygraded_'.$category->id.'">'.
855 get_string('aggregateonlygraded', 'grades').'</label>
856 <input type="checkbox" id="aggregateonlygraded_'.$category->id.'" name="aggregateonlygraded_'.
857 $category->id.'" value="1" '.$onlygradedcheck . ' />';
dc482cfa 858
859 if ($this->forced) {
860 $aggregateonlygraded = ($category->aggregateonlygraded) ? get_string('yes') : get_string('no');
861 }
862
54a007e8 863 $categorycell = clone($this->categorycell);
16be8974 864 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 865 $categorycell->text = $hidden.$aggregateonlygraded;
54a007e8 866 return $categorycell;
dc482cfa 867 }
868
869 public function get_item_cell($item, $params) {
54a007e8 870 $itemcell = clone($this->itemcell);
871 $itemcell->text = ' - ';
872 return $itemcell;
dc482cfa 873 }
874}
875
876class grade_edit_tree_column_aggregatesubcats extends grade_edit_tree_column_category {
877
878 public function __construct($params) {
879 parent::__construct('aggregatesubcats');
880 }
881
882 public function get_header_cell() {
c3b834b4 883 global $OUTPUT;
54a007e8 884 $headercell = clone($this->headercell);
885 $headercell->style .= 'width: 40px;';
886 $headercell->text = get_string('aggregatesubcats', 'grades')
cb616be8 887 .$OUTPUT->help_icon('aggregatesubcats', 'grades');
54a007e8 888 return $headercell;
dc482cfa 889 }
890
891 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
892 $subcatscheck = ($category->aggregatesubcats == 1) ? 'checked="checked"' : '';
893 $hidden = '<input type="hidden" name="aggregatesubcats_'.$category->id.'" value="0" />';
7400be1b
RT
894 $aggregatesubcats = '<label class="accesshide" for="aggregatesubcats_'.$category->id.'">'.
895 get_string('aggregatesubcats', 'grades').'</label>
896 <input type="checkbox" id="aggregatesubcats_'.$category->id.'" name="aggregatesubcats_'.$category->id.
897 '" value="1" ' . $subcatscheck.' />';
dc482cfa 898
899 if ($this->forced) {
900 $aggregatesubcats = ($category->aggregatesubcats) ? get_string('yes') : get_string('no');
901 }
902
54a007e8 903 $categorycell = clone($this->categorycell);
16be8974 904 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 905 $categorycell->text = $hidden.$aggregatesubcats;
54a007e8 906 return $categorycell;
dc482cfa 907
908 }
909
910 public function get_item_cell($item, $params) {
54a007e8 911 $itemcell = clone($this->itemcell);
912 $itemcell->text = ' - ';
913 return $itemcell;
dc482cfa 914 }
915}
916
917class grade_edit_tree_column_aggregateoutcomes extends grade_edit_tree_column_category {
918
919 public function __construct($params) {
920 parent::__construct('aggregateoutcomes');
921 }
922
923 public function get_header_cell() {
c3b834b4 924 global $OUTPUT;
54a007e8 925 $headercell = clone($this->headercell);
926 $headercell->style .= 'width: 40px;';
927 $headercell->text = get_string('aggregateoutcomes', 'grades')
3f781a22 928 .$OUTPUT->help_icon('aggregateoutcomes', 'grades');
54a007e8 929 return $headercell;
dc482cfa 930 }
931
932 public function get_category_cell($category, $levelclass, $params) {
916276fc
PS
933 $outcomescheck = ($category->aggregateoutcomes == 1) ? 'checked="checked"' : '';
934 $hidden = '<input type="hidden" name="aggregateoutcomes_'.$category->id.'" value="0" />';
7400be1b
RT
935 $aggregateoutcomes = '<label class="accesshide" for="aggregateoutcomes_'.$category->id.'">'.
936 get_string('aggregateoutcomes', 'grades').'</label>
937 <input type="checkbox" id="aggregateoutcomes_'.$category->id.'" name="aggregateoutcomes_'.$category->id.
938 '" value="1" ' . $outcomescheck.' />';
dc482cfa 939
940 if ($this->forced) {
941 $aggregateoutcomes = ($category->aggregateoutcomes) ? get_string('yes') : get_string('no');
942 }
943
54a007e8 944 $categorycell = clone($this->categorycell);
16be8974 945 $categorycell->attributes['class'] .= ' ' . $levelclass;
916276fc 946 $categorycell->text = $hidden.$aggregateoutcomes;
54a007e8 947 return $categorycell;
dc482cfa 948 }
949
950 public function get_item_cell($item, $params) {
54a007e8 951 $itemcell = clone($this->itemcell);
952 $itemcell->text = ' - ';
953 return $itemcell;
dc482cfa 954 }
955
956 public function is_hidden($mode='simple') {
957 global $CFG;
958 if ($CFG->enableoutcomes) {
959 return parent::is_hidden($mode);
960 } else {
961 return true;
962 }
963 }
964}
965
966class grade_edit_tree_column_droplow extends grade_edit_tree_column_category {
967
968 public function __construct($params) {
969 parent::__construct('droplow');
970 }
971
972 public function get_header_cell() {
c3b834b4 973 global $OUTPUT;
54a007e8 974 $headercell = clone($this->headercell);
b37760fc 975 $headercell->text = get_string('droplow', 'grades').$OUTPUT->help_icon('droplow', 'grades');
54a007e8 976 return $headercell;
dc482cfa 977 }
978
979 public function get_category_cell($category, $levelclass, $params) {
7400be1b
RT
980 $droplow = '<label class="accesshide" for="droplow_' . $category->id.'">' . get_string('droplowestvalue', 'grades') . '</label>';
981 $droplow .= '<input type="text" size="3" id="droplow_' . $category->id . '" name="droplow_' . $category->id . '" value="'
982 . $category->droplow.'" />';
dc482cfa 983
984 if ($this->forced) {
985 $droplow = $category->droplow;
986 }
987
54a007e8 988 $categorycell = clone($this->categorycell);
16be8974 989 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 990 $categorycell->text = $droplow;
991 return $categorycell;
dc482cfa 992 }
993
994 public function get_item_cell($item, $params) {
54a007e8 995 $itemcell = clone($this->itemcell);
996 $itemcell->text = ' - ';
997 return $itemcell;
dc482cfa 998 }
999}
1000
1001class grade_edit_tree_column_keephigh extends grade_edit_tree_column_category {
1002
1003 public function __construct($params) {
1004 parent::__construct('keephigh');
1005 }
1006
1007 public function get_header_cell() {
c3b834b4 1008 global $OUTPUT;
54a007e8 1009 $headercell = clone($this->headercell);
cb616be8 1010 $headercell->text = get_string('keephigh', 'grades').$OUTPUT->help_icon('keephigh', 'grades');
54a007e8 1011 return $headercell;
dc482cfa 1012 }
1013
1014 public function get_category_cell($category, $levelclass, $params) {
b1fec412 1015 $keephigh = '<label class="accesshide" for="keephigh_'.$category->id.'">'.get_string('keephigh', 'grades').'</label>';
7400be1b
RT
1016 $keephigh .= '<input type="text" size="3" id="keephigh_'.$category->id.'" name="keephigh_'.$category->id.'" value="'.
1017 $category->keephigh.'" />';
dc482cfa 1018
1019 if ($this->forced) {
1020 $keephigh = $category->keephigh;
1021 }
1022
54a007e8 1023 $categorycell = clone($this->categorycell);
16be8974 1024 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1025 $categorycell->text = $keephigh;
1026 return $categorycell;
dc482cfa 1027 }
1028
1029 public function get_item_cell($item, $params) {
54a007e8 1030 $itemcell = clone($this->itemcell);
1031 $itemcell->text = ' - ';
1032 return $itemcell;
dc482cfa 1033 }
1034}
1035
1036class grade_edit_tree_column_multfactor extends grade_edit_tree_column {
1037
1038 public function __construct($params) {
54a007e8 1039 parent::__construct();
dc482cfa 1040 }
1041
1042 public function get_header_cell() {
c3b834b4 1043 global $OUTPUT;
54a007e8 1044 $headercell = clone($this->headercell);
d4a11ee5 1045 $headercell->text = get_string('multfactor', 'grades').$OUTPUT->help_icon('multfactor', 'grades');
54a007e8 1046 return $headercell;
dc482cfa 1047 }
1048
1049 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1050 $categorycell = clone($this->categorycell);
16be8974 1051 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1052 $categorycell->text = ' - ';
1053 return $categorycell;
dc482cfa 1054 }
1055
1056 public function get_item_cell($item, $params) {
54a007e8 1057 global $OUTPUT;
1058
1059 $itemcell = clone($this->itemcell);
a043086f 1060 if (!$item->is_raw_used()) {
54a007e8 1061 $itemcell->text = '&nbsp;';
1062 return $itemcell;
a043086f 1063 }
7400be1b
RT
1064 $multfactor = '<label class="accesshide" for="multfactor'.$item->id.'">'.
1065 get_string('multfactorvalue', 'grades', $item->itemname).'</label>
1066 <input type="text" size="4" id="multfactor'.$item->id.'" name="multfactor_'.$item->id.'" value="'.
1067 grade_edit_tree::format_number($item->multfactor).'" />';
54a007e8 1068
7d89f0b0 1069 $itemcell->text = $multfactor;
54a007e8 1070 return $itemcell;
dc482cfa 1071 }
1072
1073 public function is_hidden($mode='simple') {
1074 global $CFG;
1075 if ($mode == 'simple') {
1076 return strstr($CFG->grade_item_advanced, 'multfactor');
1077 } elseif ($mode == 'advanced') {
1078 return false;
1079 }
1080 }
1081}
1082
1083class grade_edit_tree_column_plusfactor extends grade_edit_tree_column {
1084
1085 public function get_header_cell() {
c3b834b4 1086 global $OUTPUT;
54a007e8 1087 $headercell = clone($this->headercell);
12b0938c 1088 $headercell->text = get_string('plusfactor', 'grades').$OUTPUT->help_icon('plusfactor', 'grades');
54a007e8 1089 return $headercell;
dc482cfa 1090 }
1091
1092 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1093 $categorycell = clone($this->categorycell);
16be8974 1094 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1095 $categorycell->text = ' - ';
1096 return $categorycell;
dc482cfa 1097
1098 }
1099
1100 public function get_item_cell($item, $params) {
54a007e8 1101 global $OUTPUT;
1102
1103 $itemcell = clone($this->itemcell);
a043086f 1104 if (!$item->is_raw_used()) {
54a007e8 1105 $itemcell->text = '&nbsp;';
1106 return $itemcell;
a043086f 1107 }
54a007e8 1108
7400be1b
RT
1109 $plusfactor = '<label class="accesshide" for="plusfactor_'. $item->id . '">'.
1110 get_string('plusfactorvalue', 'grades', $item->itemname).'</label>
1111 <input type="text" size="4" id="plusfactor_'.$item->id.'" name="plusfactor_'.$item->id.'" value="'.
1112 grade_edit_tree::format_number($item->plusfactor).'" />';
916276fc 1113
7d89f0b0 1114 $itemcell->text = $plusfactor;
54a007e8 1115 return $itemcell;
dc482cfa 1116
1117 }
1118
1119 public function is_hidden($mode='simple') {
1120 global $CFG;
1121 if ($mode == 'simple') {
1122 return strstr($CFG->grade_item_advanced, 'plusfactor');
1123 } elseif ($mode == 'advanced') {
1124 return false;
1125 }
1126 }
1127}
1128
1129class grade_edit_tree_column_actions extends grade_edit_tree_column {
1130
1131 public function __construct($params) {
71297a3f 1132 parent::__construct();
dc482cfa 1133 }
1134
1135 public function get_header_cell() {
54a007e8 1136 $headercell = clone($this->headercell);
16be8974 1137 $headercell->attributes['class'] .= ' actions';
54a007e8 1138 $headercell->text = get_string('actions');
1139 return $headercell;
dc482cfa 1140 }
1141
1142 public function get_category_cell($category, $levelclass, $params) {
1143
1144 if (empty($params['actions'])) {
1145 throw new Exception('Array key (actions) missing from 3rd param of grade_edit_tree_column_actions::get_category_actions($category, $levelclass, $params)');
1146 }
1147
54a007e8 1148 $categorycell = clone($this->categorycell);
16be8974 1149 $categorycell->attributes['class'] .= ' ' . $levelclass;
54a007e8 1150 $categorycell->text = $params['actions'];
1151 return $categorycell;
dc482cfa 1152 }
1153
1154 public function get_item_cell($item, $params) {
1155 if (empty($params['actions'])) {
1156 throw new Exception('Array key (actions) missing from 2nd param of grade_edit_tree_column_actions::get_item_cell($item, $params)');
1157 }
54a007e8 1158 $itemcell = clone($this->itemcell);
16be8974 1159 $itemcell->attributes['class'] .= ' actions';
54a007e8 1160 $itemcell->text = $params['actions'];
1161 return $itemcell;
dc482cfa 1162 }
1163
1164 public function is_hidden($mode='simple') {
1165 return false;
1166 }
1167}
1168
1169class grade_edit_tree_column_select extends grade_edit_tree_column {
1170
1171 public function get_header_cell() {
54a007e8 1172 $headercell = clone($this->headercell);
16be8974 1173 $headercell->attributes['class'] .= ' selection';
54a007e8 1174 $headercell->text = get_string('select');
1175 return $headercell;
dc482cfa 1176 }
1177
1178 public function get_category_cell($category, $levelclass, $params) {
54a007e8 1179 global $OUTPUT;
dc482cfa 1180 if (empty($params['eid'])) {
1181 throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
1182 }
4ee753eb
PS
1183 $selectall = new action_link(new moodle_url('#'), get_string('all'), new component_action('click', 'togglecheckboxes', array('eid' => $params['eid'], 'check' => true)));
1184 $selectnone = new action_link(new moodle_url('#'), get_string('none'), new component_action('click', 'togglecheckboxes', array('eid' => $params['eid'], 'check' => false)));
dc482cfa 1185
54a007e8 1186 $categorycell = clone($this->categorycell);
16be8974 1187 $categorycell->attributes['class'] .= ' last ' . $levelclass;
54a007e8 1188 $categorycell->style .= 'text-align: center;';
4ee753eb 1189 $categorycell->text = $OUTPUT->render($selectall) . '<br />' . $OUTPUT->render($selectnone);
54a007e8 1190 return $categorycell;
dc482cfa 1191 }
1192
1193 public function get_item_cell($item, $params) {
54a007e8 1194 if (empty($params['itemtype']) || empty($params['eid'])) {
2f0e96e4 1195 error('Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)');
54a007e8 1196 }
1197 $itemselect = '';
1198
1199 if ($params['itemtype'] != 'course' && $params['itemtype'] != 'category') {
7400be1b
RT
1200 $itemselect = '<label class="accesshide" for="select_'.$params['eid'].'">'.
1201 get_string('select', 'grades', $item->itemname).'</label>
ef93efbf 1202 <input class="itemselect ignoredirty" type="checkbox" name="select_'.$params['eid'].'" id="select_'.$params['eid'].
7400be1b 1203 '" onchange="toggleCategorySelector();"/>'; // TODO: convert to YUI handler
dc482cfa 1204 }
5174f3c5
AD
1205 //html_writer::table() will wrap the item cell contents in a <TD> so don't do it here
1206 return $itemselect;
dc482cfa 1207 }
1208
1209 public function is_hidden($mode='simple') {
1210 return false;
1211 }
1212}
6c3ef410 1213