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