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