MDL-18083 (including MDL-15680, MDL-17829, MDL-17807, MDL-18004, MDL-12631, MDL-16913)
[moodle.git] / grade / edit / tree / lib.php
CommitLineData
dc482cfa 1<?php // $Id$
2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.com //
9// //
10// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
26class grade_edit_tree {
27 public $columns = array();
28
29 /**
30 * @var object $gtree @see grade/lib.php
31 */
32 public $gtree;
33
34 /**
35 * @var grade_plugin_return @see grade/lib.php
36 */
37 public $gpr;
38
39 /**
40 * @var string $moving The eid of the category or item being moved
41 */
42 public $moving;
43
44 public $deepest_level;
45
46 /**
47 * Constructor
48 */
49 public function __construct($gtree, $moving=false, $gpr) {
50 $this->gtree = $gtree;
51 $this->moving = $moving;
52 $this->gpr = $gpr;
53 $this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
54
55 $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)),
56 grade_edit_tree_column::factory('aggregation', array('flag' => true)),
57 grade_edit_tree_column::factory('weightorextracredit', array('adv' => 'aggregationcoef')),
58 grade_edit_tree_column::factory('range'), // This is not a setting... How do we deal with it?
59 grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true)),
60 grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true)),
61 grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true)),
62 grade_edit_tree_column::factory('droplow', array('flag' => true)),
63 grade_edit_tree_column::factory('keephigh', array('flag' => true)),
64 grade_edit_tree_column::factory('multfactor', array('adv' => true)),
65 grade_edit_tree_column::factory('plusfactor', array('adv' => true)),
66 grade_edit_tree_column::factory('actions'),
67 grade_edit_tree_column::factory('select')
68 );
69 }
70
71 /**
72 * Recursive function for building the table holding the grade categories and items,
73 * with CSS indentation and styles.
74 *
75 * @param array $element The current tree element being rendered
76 * @param boolean $totals Whether or not to print category grade items (category totals)
77 * @param array $parents An array of parent categories for the current element (used for indentation and row classes)
78 *
79 * @return string HTML
80 */
81 public function build_html_tree($element, $totals, $parents=array(), &$categories=array(), $level=0, &$row_count=0) {
82 global $CFG, $COURSE, $USER;
83
84 $object = $element['object'];
85 $eid = $element['eid'];
86 $object->name = $this->gtree->get_element_header($element, true, true, false);
87 $object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
88
89 $is_category_item = false;
90 if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') {
91 $is_category_item = true;
92 }
93
94 $rowclasses = '';
95 foreach ($parents as $parent_eid) {
96 $rowclasses .= " $parent_eid ";
97 }
98
99 $actions = '';
100
101 if (!$is_category_item) {
102 $actions .= $this->gtree->get_edit_icon($element, $this->gpr);
103 }
104
105 $actions .= $this->gtree->get_calculation_icon($element, $this->gpr);
106
107 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
108 if ($this->element_deletable($element)) {
109 $actions .= '<a href="index.php?id='.$COURSE->id.'&amp;action=delete&amp;eid='
110 . $eid.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" class="iconsmall" alt="'
111 . get_string('delete').'" title="'.get_string('delete').'"/></a>';
112 }
113 $actions .= '<a href="index.php?id='.$COURSE->id.'&amp;action=moveselect&amp;eid='
114 . $eid.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="'
115 . get_string('move').'" title="'.get_string('move').'"/></a>';
116 }
117
118 $actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
119 $actions .= $this->gtree->get_locking_icon($element, $this->gpr);
120
121 $mode = ($USER->gradeediting[$COURSE->id]) ? 'advanced' : 'simple';
122
123 $html = '';
124 $root = false;
125
126
127 $id = required_param('id', PARAM_INT);
128
129 /// prepare move target if needed
130 $last = '';
131
132 /// print the list items now
133 if ($this->moving == $eid) {
134
135 // do not diplay children
136 return '<tr><td colspan="12" class="'.$element['type'].' moving">'.$object->name.' ('.get_string('move').')</td></tr>';
137
138 }
139
140 if ($element['type'] == 'category') {
141 $level++;
142 $categories[$object->id] = $object->stripped_name;
143 $category = grade_category::fetch(array('id' => $object->id));
144 $item = $category->get_grade_item();
145
146 // Add aggregation coef input if not a course item and if parent category has correct aggregation type
147 $dimmed = ($item->hidden) ? " dimmed " : "";
148
149 // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
150 $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
151 $category_total_data = null; // Used if aggregationposition is set to "last", so we can print it last
152
153 $html_children = '';
154
155 $row_count = 0;
156
157 foreach($element['children'] as $child_el) {
158 $moveto = '';
159
160 if (empty($child_el['object']->itemtype)) {
161 $child_el['object']->itemtype = false;
162 }
163
164 if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) {
165 continue;
166 }
167
168 $child_eid = $child_el['eid'];
169 $first = '';
170
171 if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
172 $first = '&amp;first=1';
173 $child_eid = $eid;
174 }
175
176 if ($this->moving && $this->moving != $child_eid) {
177
178 $strmove = get_string('move');
179 $strmovehere = get_string('movehere');
180 $actions = ''; // no action icons when moving
181
182 $moveto = '<tr><td colspan="12"><a href="index.php?id='.$COURSE->id.'&amp;action=move&amp;eid='.$this->moving.'&amp;moveafter='
183 . $child_eid.'&amp;sesskey='.sesskey().$first.'"><img class="movetarget" src="'.$CFG->wwwroot.'/pix/movehere.gif" alt="'
184 . $strmovehere.'" title="'.$strmovehere.'" /></a></td></tr>';
185 }
186
187 $newparents = $parents;
188 $newparents[] = $eid;
189
190 $row_count++;
191 $child_row_count = 0;
192
193 // If moving, do not print course and category totals, but still print the moveto target box
194 if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) {
195 $html_children .= $moveto;
196 } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') {
197 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans)
198 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $categories, $level, $child_row_count);
199 if (!$aggregation_position) {
200 $html_children .= $category_total_item;
201 }
202 } else {
203 $html_children .= $this->build_html_tree($child_el, $totals, $newparents, $categories, $level, $child_row_count) . $moveto;
204
205 if ($this->moving) {
206 $row_count++;
207 }
208 }
209
210 $row_count += $child_row_count;
211
212 // If the child is a category, increment row_count by one more (for the extra coloured row)
213 if ($child_el['type'] == 'category') {
214 $row_count++;
215 }
216 }
217
218 // Print category total at the end if aggregation position is "last" (1)
219 if (!empty($category_total_item) && $aggregation_position) {
220 $html_children .= $category_total_item;
221 }
222
223 // now build the header
224 if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) {
225 // Reduce width if advanced elements are not shown
226 $width_style = '';
227
228 if ($mode == 'simple') {
229 $width_style = ' style="width:auto;" ';
230 }
231
232 $html .= '<table cellpadding="5" class="generaltable" '.$width_style.'>
233 <tr>';
234
235 foreach ($this->columns as $column) {
236 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
237 $html .= $column->get_header_cell();
238 }
239 }
240
241 $html .= '</tr>';
242 $root = true;
243 }
244
245 $row_count_offset = 0;
246
247 if (empty($category_total_item) && !$this->moving) {
248 $row_count_offset = -1;
249 }
250
251 $levelclass = " level$level ";
252
253 $html .= '
254 <tr class="category '.$dimmed.$rowclasses.'">
255 <th scope="row" title="'.$object->stripped_name.'" class="cell rowspan '.$levelclass.'" rowspan="'.($row_count+1+$row_count_offset).'"></th>';
256
257 foreach ($this->columns as $column) {
258 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
259 $html .= $column->get_category_cell($category, $levelclass, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions, 'eid' => $eid));
260 }
261 }
262
263 $html .= '</tr>';
264
265 $html .= $html_children;
266
267 // Print a coloured row to show the end of the category accross the table
268 $html .= '<tr><td colspan="'.(19 - $level).'" class="colspan '.$levelclass.'"></td></tr>';
269
270 } else { // Dealing with a grade item
271
272 $item = grade_item::fetch(array('id' => $object->id));
273 $element['type'] = 'item';
274 $element['object'] = $item;
275
276 // Determine aggregation coef element
277
278 $dimmed = ($item->hidden) ? " dimmed_text " : "";
279 $html .= '<tr class="item'.$dimmed.$rowclasses.'">';
280
281 foreach ($this->columns as $column) {
282 if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
283 $html .= $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 'level' => $level, 'actions' => $actions,
284 'element' => $element, 'eid' => $eid, 'itemtype' => $object->itemtype));
285 }
286 }
287
288 $html .= '</tr>';
289 }
290
291
292 if ($root) {
293 $html .= "</table>\n";
294 }
295
296 return $html;
297
298 }
299
300 /**
301 * Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
302 * @param grade_item $item
303 * @return string HTML
304 */
305 function get_weight_input($item) {
306 if (!is_object($item) || get_class($item) !== 'grade_item') {
307 throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
308 return false;
309 }
310
311 if ($item->is_course_item()) {
312 return '';
313 }
314
315 $parent_category = $item->get_parent_category();
316
317 if ($item->is_category_item()) {
318 $parent_category = $parent_category->get_parent_category();
319 }
320
321 $parent_category->apply_forced_settings();
322
323 if ($parent_category->is_aggregationcoef_used()) {
324 $aggcoef = '';
325
326 if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
327 $aggcoef = 'aggregationcoefweight';
328 } elseif ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
329 $aggcoef = 'aggregationcoefextra';
330 } elseif ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
331 $aggcoef = 'aggregationcoefextrasum';
332 }
333
334 if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextra') {
335 return '<input type="text" size="6" id="aggregationcoef_'.$item->id.'" name="aggregationcoef_'.$item->id.'"
336 value="'.format_float($item->aggregationcoef).'" />';
337 } elseif ($aggcoef == 'aggregationcoefextrasum' ) {
338 $checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
339 $extracredit = ($item->aggregationcoef > 0) ? 1 : 0;
340
341 return '<input type="checkbox" id="extracredit_'.$item->id.'" name="extracredit_'.$item->id.'" ' . "$checked />\n"
342 . '<input type="hidden" name="extracredit_original_'.$item->id.'" value="'.$extracredit.'" />';
343 } else {
344 return '';
345 }
346 }
347 }
348
349 /**
350 * Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable)
351 *
352 * @param array $element
353 * @return bool
354 */
355 function element_deletable($element) {
356 global $COURSE;
357
358 if ($element['type'] != 'item') {
359 return true;
360 }
361
362 $grade_item = $element['object'];
363
364 if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) {
365 return true;
366 }
367
368 $modinfo = get_fast_modinfo($COURSE);
369 if (!isset($modinfo->instances[$grade_item->itemmodule][$grade_item->iteminstance])) {
370 // module does not exist
371 return true;
372 }
373
374 return false;
375 }
376
377 /**
378 * Given the grade tree and an array of element ids (e.g. c15, i42), and expecting the 'moveafter' URL param,
379 * moves the selected items to the requested location. Then redirects the user to the given $returnurl
380 *
381 * @param object $gtree The grade tree (a recursive representation of the grade categories and grade items)
382 * @param array $eids
383 * @param string $returnurl
384 */
385 function move_elements($eids, $returnurl) {
386 $moveafter = required_param('moveafter', PARAM_INT);
387
388 if (!is_array($eids)) {
389 $eids = array($eids);
390 }
391
392 if(!$after_el = $this->gtree->locate_element("c$moveafter")) {
393 print_error('invalidelementid', '', $returnurl);
394 }
395
396 $after = $after_el['object'];
397 $parent = $after;
398 $sortorder = $after->get_sortorder();
399
400 foreach ($eids as $eid) {
401 if (!$element = $this->gtree->locate_element($eid)) {
402 print_error('invalidelementid', '', $returnurl);
403 }
404 $object = $element['object'];
405
406 $object->set_parent($parent->id);
407 $object->move_after_sortorder($sortorder);
408 }
409
410 redirect($returnurl, '', 0);
411 }
412
413 /**
414 * Recurses through the entire grade tree to find and return the maximum depth of the tree.
415 * This should be run only once from the root element (course category), and is used for the
416 * indentation of the Name column's cells (colspan)
417 *
418 * @param array $element An array of values representing a grade tree's element (all grade items in this case)
419 * @param int $level The level of the current recursion
420 * @param int $deepest_level A value passed to each subsequent level of recursion and incremented if $level > $deepest_level
421 * @return int Deepest level
422 */
423 function get_deepest_level($element, $level=0, $deepest_level=1) {
424 $object = $element['object'];
425
426 $level++;
427
428 if ($element['type'] == 'category') {
429 foreach($element['children'] as $child_el) {
430 if ($level > $deepest_level) {
431 $deepest_level = $level;
432 }
433 $deepest_level = $this->get_deepest_level($child_el, $level, $deepest_level);
434 }
435 }
436
437 return $deepest_level;
438 }
439}
440
441abstract class grade_edit_tree_column {
442 public $forced;
443 public $hidden;
444 public $forced_hidden;
445 public $advanced_hidden;
446 public $hide_when_moving = true;
447
448 public static function factory($name, $params=array()) {
449 $class_name = "grade_edit_tree_column_$name";
450 if (class_exists($class_name)) {
451 return new $class_name($params);
452 }
453 }
454
455 public abstract function get_header_cell();
456
457 public abstract function get_category_cell($category, $levelclass, $params);
458
459 public abstract function get_item_cell($item, $params);
460
461 public abstract function is_hidden($mode='simple');
462}
463
464abstract class grade_edit_tree_column_category extends grade_edit_tree_column {
465
466 public $forced;
467 public $advanced;
468
469 public function __construct($name) {
470 global $CFG;
471 $this->forced = (int)$CFG->{"grade_$name"."_flag"} & 1;
472 $this->advanced = (int)$CFG->{"grade_$name"."_flag"} & 2;
473 }
474
475 public function is_hidden($mode='simple') {
476 global $CFG;
477 if ($mode == 'simple') {
478 return $this->advanced;
479 } elseif ($mode == 'advanced') {
480 if ($this->forced && $CFG->grade_hideforcedsettings) {
481 return true;
482 } else {
483 return false;
484 }
485 }
486 }
487}
488
489class grade_edit_tree_column_name extends grade_edit_tree_column {
490 public $forced = false;
491 public $hidden = false;
492 public $forced_hidden = false;
493 public $advanced_hidden = false;
494 public $deepest_level = 1;
495 public $hide_when_moving = false;
496
497 public function __construct($params) {
498 if (empty($params['deepest_level'])) {
499 throw new Exception('Tried to instantiate a grade_edit_tree_column_name object without the "deepest_level" param!');
500 }
501
502 $this->deepest_level = $params['deepest_level'];
503 }
504
505 public function get_header_cell() {
506 return '<th class="header name" colspan="'.($this->deepest_level + 1).'" scope="col">'.get_string('name').'</th>';
507 }
508
509 public function get_category_cell($category, $levelclass, $params) {
510 if (empty($params['name']) || empty($params['level'])) {
511 throw new Exception('Array key (name or level) missing from 3rd param of grade_edit_tree_column_name::get_category_cell($category, $levelclass, $params)');
512 }
513
514 return '<td class="cell name '.$levelclass.'" colspan="'.(($this->deepest_level +1) - $params['level']).'"><h4>' . $params['name'] . "</h4></td>\n";
515 }
516
517 public function get_item_cell($item, $params) {
518 global $CFG;
519
520 if (empty($params['element']) || empty($params['name']) || empty($params['level'])) {
521 throw new Exception('Array key (name, level or element) missing from 2nd param of grade_edit_tree_column_name::get_item_cell($item, $params)');
522 }
523
524 $name = $params['name'];
525
526 return '<td class="cell name" colspan="'.(($this->deepest_level + 1) - $params['level']).'">' . $name . '</td>';
527 }
528
529 public function is_hidden($mode='simple') {
530 return false;
531 }
532}
533
534class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category {
535
536 public function __construct($params) {
537 parent::__construct('aggregation');
538 }
539
540 public function get_header_cell() {
541 return '<th class="header" scope="col">'.get_string('aggregation', 'grades').helpbutton('aggregation', 'aggregation', 'grade', true, false, '', true).'</th>';
542 }
543
544 public function get_category_cell($category, $levelclass, $params) {
545 if (empty($params['id'])) {
546 throw new Exception('Array key (id) missing from 3rd param of grade_edit_tree_column_aggregation::get_category_cell($category, $levelclass, $params)');
547 }
548
549 $options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'),
550 GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'),
551 GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'),
552 GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'),
553 GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'),
554 GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'),
555 GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'),
556 GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'),
557 GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades'));
558
559 $script = "window.location='index.php?id={$params['id']}&amp;category={$category->id}&amp;aggregationtype='+this.value";
560 $aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
561
562 if ($this->forced) {
563 $aggregation = $options[$category->aggregation];
564 }
565
566 return '<td class="cell '.$levelclass.'">' . $aggregation . '</td>';
567
568 }
569
570 public function get_item_cell($item, $params) {
571 return '<td class="cell"> - </td>';
572 }
573}
574
575class grade_edit_tree_column_weightorextracredit extends grade_edit_tree_column {
576
577 public function get_header_cell() {
578 return '<th class="header" scope="col">'.get_string('weightorextracredit', 'grades').helpbutton('aggregationcoefweight', 'aggregationcoefweight', 'grade', true, false, '', true).'</th>';
579 }
580
581 public function get_category_cell($category, $levelclass, $params) {
582
583 $item = $category->get_grade_item();
584 $aggcoef_input = grade_edit_tree::get_weight_input($item);
585 return '<td class="cell '.$levelclass.'">' . $aggcoef_input . '</td>';
586 }
587
588 public function get_item_cell($item, $params) {
589 if (empty($params['element'])) {
590 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
591 }
592
593 $aggcoef_input = grade_edit_tree::get_weight_input($item);
594 $html = '<td class="cell">';
595
596 if ($params['element']['type'] == 'categoryitem' || $params['element']['type'] == 'courseitem') {
597 $html .= $aggcoef_input;
598 }
599
600 return $html.'</td>';
601 }
602
603 public function is_hidden($mode='simple') {
604 global $CFG;
605 if ($mode == 'simple') {
606 return strstr($CFG->grade_item_advanced, 'aggregationcoef');
607 } elseif ($mode == 'advanced') {
608 return false;
609 }
610 }
611}
612
613class grade_edit_tree_column_range extends grade_edit_tree_column {
614
615 public function get_header_cell() {
616 return '<th class="header" scope="col">'.get_string('maxgrade', 'grades').'</th>';
617 }
618
619 public function get_category_cell($category, $levelclass, $params) {
620 return '<td class="cell range '.$levelclass.'"> - </td>';
621 }
622
623 public function get_item_cell($item, $params) {
624 if ($item->gradetype == GRADE_TYPE_SCALE) {
625 $scale = get_record('scale', 'id', $item->scaleid);
626 $scale_items = explode(',', $scale->scale);
627 $grademax = end($scale_items) . ' (' . count($scale_items) . ')';
628 } elseif ($item->is_external_item()) {
629 $grademax = format_float($item->grademax, $item->get_decimals());
630 } else {
631 $grademax = '<input type="text" size="3" id="grademax'.$item->id.'" name="grademax'.$item->id.'" value="'.format_float($item->grademax, $item->get_decimals()).'" />';
632 }
633
634 return '<td class="cell">'.$grademax.'</td>';
635 }
636
637 public function is_hidden($mode='simple') {
638 global $CFG;
639 if ($mode == 'simple') {
640 return strstr($CFG->grade_item_advanced, 'grademax');
641 } elseif ($mode == 'advanced') {
642 return false;
643 }
644 }
645}
646
647class grade_edit_tree_column_aggregateonlygraded extends grade_edit_tree_column_category {
648
649 public function __construct($params) {
650 parent::__construct('aggregateonlygraded');
651 }
652
653 public function get_header_cell() {
654 return '<th class="header" style="width: 40px" scope="col">'.get_string('aggregateonlygraded', 'grades')
655 .helpbutton('aggregateonlygraded', 'aggregateonlygraded', 'grade', true, false, '', true).'</th>';
656 }
657
658 public function get_category_cell($category, $levelclass, $params) {
659 $onlygradedcheck = ($category->aggregateonlygraded == 1) ? 'checked="checked"' : '';
660 $aggregateonlygraded ='<input type="checkbox" id="aggregateonlygraded_'.$category->id.'" name="aggregateonlygraded_'.$category->id.'" '.$onlygradedcheck . ' />';
661 $hidden = '<input type="hidden" name="aggregateonlygraded_original_'.$category->id.'" value="'.$category->aggregateonlygraded.'" />';
662
663 if ($this->forced) {
664 $aggregateonlygraded = ($category->aggregateonlygraded) ? get_string('yes') : get_string('no');
665 }
666
667 return '<td class="cell '.$levelclass.'">' . $aggregateonlygraded . '</td>';
668 }
669
670 public function get_item_cell($item, $params) {
671 return '<td class="cell"> - </td>';
672 }
673}
674
675class grade_edit_tree_column_aggregatesubcats extends grade_edit_tree_column_category {
676
677 public function __construct($params) {
678 parent::__construct('aggregatesubcats');
679 }
680
681 public function get_header_cell() {
682 return '<th class="header" style="width: 40px" scope="col">'.get_string('aggregatesubcats', 'grades')
683 .helpbutton('aggregatesubcats', 'aggregatesubcats', 'grade', true, false, '', true).'</th>';
684 }
685
686 public function get_category_cell($category, $levelclass, $params) {
687 $subcatscheck = ($category->aggregatesubcats == 1) ? 'checked="checked"' : '';
688 $aggregatesubcats = '<input type="checkbox" id="aggregatesubcats_'.$category->id.'" name="aggregatesubcats_'.$category->id.'" ' . $subcatscheck.' />';
689 $hidden = '<input type="hidden" name="aggregatesubcats_original_'.$category->id.'" value="'.$category->aggregatesubcats.'" />';
690
691 if ($this->forced) {
692 $aggregatesubcats = ($category->aggregatesubcats) ? get_string('yes') : get_string('no');
693 }
694
695 return '<td class="cell '.$levelclass.'">' . $aggregatesubcats . $hidden.'</td>';
696
697 }
698
699 public function get_item_cell($item, $params) {
700 return '<td class="cell"> - </td>';
701 }
702}
703
704class grade_edit_tree_column_aggregateoutcomes extends grade_edit_tree_column_category {
705
706 public function __construct($params) {
707 parent::__construct('aggregateoutcomes');
708 }
709
710 public function get_header_cell() {
711 return '<th class="header" style="width: 40px" scope="col">'.get_string('aggregateoutcomes', 'grades')
712 .helpbutton('aggregateoutcomes', 'aggregateoutcomes', 'grade', true, false, '', true).'</th>';
713 }
714
715 public function get_category_cell($category, $levelclass, $params) {
716
717 $outcomescheck = ($category->aggregateoutcomes == 1) ? 'checked="checked"' : '';
718 $aggregateoutcomes = '<input type="checkbox" id="aggregateoutcomes_'.$category->id.'" name="aggregateoutcomes_'.$category->id.'" ' . $outcomescheck.' />';
719 $hidden = '<input type="hidden" name="aggregateoutcomes_original_'.$category->id.'" value="'.$category->aggregateoutcomes.'" />';
720
721 if ($this->forced) {
722 $aggregateoutcomes = ($category->aggregateoutcomes) ? get_string('yes') : get_string('no');
723 }
724
725 return '<td class="cell '.$levelclass.'">' . $aggregateoutcomes . $hidden.'</td>';
726 }
727
728 public function get_item_cell($item, $params) {
729 return '<td class="cell"> - </td>';
730 }
731
732 public function is_hidden($mode='simple') {
733 global $CFG;
734 if ($CFG->enableoutcomes) {
735 return parent::is_hidden($mode);
736 } else {
737 return true;
738 }
739 }
740}
741
742class grade_edit_tree_column_droplow extends grade_edit_tree_column_category {
743
744 public function __construct($params) {
745 parent::__construct('droplow');
746 }
747
748 public function get_header_cell() {
749 return '<th class="header" scope="col">'.get_string('droplow', 'grades').helpbutton('droplow', 'droplow', 'grade', true, false, '', true).'</th>';
750 }
751
752 public function get_category_cell($category, $levelclass, $params) {
753 $droplow = '<input type="text" size="3" id="droplow_'.$category->id.'" name="droplow_'.$category->id.'" value="'.$category->droplow.'" />';
754
755 if ($this->forced) {
756 $droplow = $category->droplow;
757 }
758
759 return '<td class="cell '.$levelclass.'">' . $droplow . '</td>';
760 }
761
762 public function get_item_cell($item, $params) {
763 return '<td class="cell"> - </td>';
764 }
765}
766
767class grade_edit_tree_column_keephigh extends grade_edit_tree_column_category {
768
769 public function __construct($params) {
770 parent::__construct('keephigh');
771 }
772
773 public function get_header_cell() {
774 return '<th class="header" scope="col">'.get_string('keephigh', 'grades').helpbutton('keephigh', 'keephigh', 'grade', true, false, '', true).'</th>';
775 }
776
777 public function get_category_cell($category, $levelclass, $params) {
778 $keephigh = '<input type="text" size="3" id="keephigh_'.$category->id.'" name="keephigh_'.$category->id.'" value="'.$category->keephigh.'" />';
779
780 if ($this->forced) {
781 $keephigh = $category->keephigh;
782 }
783
784 return '<td class="cell '.$levelclass.'">' . $keephigh . '</td>';
785 }
786
787 public function get_item_cell($item, $params) {
788 return '<td class="cell"> - </td>';
789 }
790}
791
792class grade_edit_tree_column_multfactor extends grade_edit_tree_column {
793
794 public function __construct($params) {
795
796 }
797
798 public function get_header_cell() {
799 return '<th class="header" scope="col">'.get_string('multfactor', 'grades').helpbutton('multfactor', 'multfactor', 'grade', true, false, '', true).'</th>';
800 }
801
802 public function get_category_cell($category, $levelclass, $params) {
803
804 return '<td class="cell '.$levelclass.'"> - </td>';
805 }
806
807 public function get_item_cell($item, $params) {
808 $multfactor = '<input type="text" size="3" id="multfactor'.$item->id.'" name="multfactor'.$item->id.'" value="'.format_float($item->multfactor).'" />';
809 return '<td class="cell">'.$multfactor.'</td>';
810 }
811
812 public function is_hidden($mode='simple') {
813 global $CFG;
814 if ($mode == 'simple') {
815 return strstr($CFG->grade_item_advanced, 'multfactor');
816 } elseif ($mode == 'advanced') {
817 return false;
818 }
819 }
820}
821
822class grade_edit_tree_column_plusfactor extends grade_edit_tree_column {
823
824 public function get_header_cell() {
825 return '<th class="header" scope="col">'.get_string('plusfactor', 'grades').helpbutton('plusfactor', 'plusfactor', 'grade', true, false, '', true).'</th>';
826 }
827
828 public function get_category_cell($category, $levelclass, $params) {
829 return '<td class="cell '.$levelclass.'"> - </td>';
830
831 }
832
833 public function get_item_cell($item, $params) {
834 $plusfactor = '<input type="text" size="3" id="plusfactor_'.$item->id.'" name="plusfactor_'.$item->id.'" value="'.format_float($item->plusfactor).'" />';
835 return '<td class="cell">'.$plusfactor.'</td>';
836
837 }
838
839 public function is_hidden($mode='simple') {
840 global $CFG;
841 if ($mode == 'simple') {
842 return strstr($CFG->grade_item_advanced, 'plusfactor');
843 } elseif ($mode == 'advanced') {
844 return false;
845 }
846 }
847}
848
849class grade_edit_tree_column_actions extends grade_edit_tree_column {
850
851 public function __construct($params) {
852
853 }
854
855 public function get_header_cell() {
856 return '<th class="header actions" scope="col">'.get_string('actions').'</th>';
857 }
858
859 public function get_category_cell($category, $levelclass, $params) {
860
861 if (empty($params['actions'])) {
862 throw new Exception('Array key (actions) missing from 3rd param of grade_edit_tree_column_actions::get_category_actions($category, $levelclass, $params)');
863 }
864
865 return '<td class="cell actions '.$levelclass.'">' . $params['actions'] . '</td>';
866 }
867
868 public function get_item_cell($item, $params) {
869 if (empty($params['actions'])) {
870 throw new Exception('Array key (actions) missing from 2nd param of grade_edit_tree_column_actions::get_item_cell($item, $params)');
871 }
872 return '<td class="cell actions">' . $params['actions'] . '</td>';
873 }
874
875 public function is_hidden($mode='simple') {
876 return false;
877 }
878}
879
880class grade_edit_tree_column_select extends grade_edit_tree_column {
881
882 public function get_header_cell() {
883 return '<th class="header selection" scope="col">'.get_string('select').'</th>';
884 }
885
886 public function get_category_cell($category, $levelclass, $params) {
887
888 if (empty($params['eid'])) {
889 throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
890 }
891
892 return '<td class="cell last '.$levelclass.'" style="text-align: center">
893 <span class="actionlink" onclick="togglecheckboxes(\''.$params['eid'].'\', true);">'.get_string('all').'</span><br />
894 <span class="actionlink" onclick="togglecheckboxes(\''.$params['eid'].'\', false);">'.get_string('none').'</span>
895 </td>';
896 }
897
898 public function get_item_cell($item, $params) {
899 if (empty($params['itemtype']) || empty($params['eid'])) {
900 throw new Exception('Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)');
901 }
902 $itemselect = '';
903
904 if ($params['itemtype'] != 'course' && $params['itemtype'] != 'category') {
905 $itemselect = '<input class="itemselect" type="checkbox" name="select_'.$params['eid'].'" />';
906 }
907 return '<td class="cell last selection">' . $itemselect . '</td>';
908 }
909
910 public function is_hidden($mode='simple') {
911 return false;
912 }
913}
914?>