[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 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/>. 16 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 25 class grade_edit_tree { 26 public $columns = array(); 27 28 /** 29 * @var grade_tree $gtree @see grade/lib.php 30 */ 31 public $gtree; 32 33 /** 34 * @var grade_plugin_return @see grade/lib.php 35 */ 36 public $gpr; 37 38 /** 39 * @var string $moving The eid of the category or item being moved 40 */ 41 public $moving; 42 43 public $deepest_level; 44 45 public $uses_weight = false; 46 47 public $table; 48 49 public $categories = array(); 50 51 /** 52 * Show calculator icons next to manual grade items 53 * @var bool $show_calculations 54 */ 55 private $show_calculations; 56 57 /** 58 * Constructor 59 */ 60 public function __construct($gtree, $moving=false, $gpr) { 61 global $USER, $OUTPUT, $COURSE; 62 63 $systemdefault = get_config('moodle', 'grade_report_showcalculations'); 64 $this->show_calculations = get_user_preferences('grade_report_showcalculations', $systemdefault); 65 66 $this->gtree = $gtree; 67 $this->moving = $moving; 68 $this->gpr = $gpr; 69 $this->deepest_level = $this->get_deepest_level($this->gtree->top_element); 70 71 $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level))); 72 73 if ($this->uses_weight) { 74 $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'weight')); 75 } 76 77 $this->columns[] = grade_edit_tree_column::factory('range'); // This is not a setting... How do we deal with it? 78 $this->columns[] = grade_edit_tree_column::factory('actions'); 79 80 if ($this->deepest_level > 1) { 81 $this->columns[] = grade_edit_tree_column::factory('select'); 82 } 83 84 $this->table = new html_table(); 85 $this->table->id = "grade_edit_tree_table"; 86 $this->table->attributes['class'] = 'generaltable simple setup-grades'; 87 if ($this->moving) { 88 $this->table->attributes['class'] .= ' moving'; 89 } 90 91 foreach ($this->columns as $column) { 92 if (!($this->moving && $column->hide_when_moving)) { 93 $this->table->head[] = $column->get_header_cell(); 94 } 95 } 96 97 $rowcount = 0; 98 $this->table->data = $this->build_html_tree($this->gtree->top_element, true, array(), 0, $rowcount); 99 } 100 101 /** 102 * Recursive function for building the table holding the grade categories and items, 103 * with CSS indentation and styles. 104 * 105 * @param array $element The current tree element being rendered 106 * @param boolean $totals Whether or not to print category grade items (category totals) 107 * @param array $parents An array of parent categories for the current element (used for indentation and row classes) 108 * 109 * @return string HTML 110 */ 111 public function build_html_tree($element, $totals, $parents, $level, &$row_count) { 112 global $CFG, $COURSE, $PAGE, $OUTPUT; 113 114 $object = $element['object']; 115 $eid = $element['eid']; 116 $object->name = $this->gtree->get_element_header($element, true, true, true, true, true); 117 $object->stripped_name = $this->gtree->get_element_header($element, false, false, false); 118 119 $is_category_item = false; 120 if ($element['type'] == 'categoryitem' || $element['type'] == 'courseitem') { 121 $is_category_item = true; 122 } 123 124 $rowclasses = array(); 125 foreach ($parents as $parent_eid) { 126 $rowclasses[] = $parent_eid; 127 } 128 129 $moveaction = ''; 130 $actionsmenu = new action_menu(); 131 $actionsmenu->initialise_js($PAGE); 132 $actionsmenu->set_menu_trigger(get_string('edit')); 133 $actionsmenu->set_owner_selector('grade-item-' . $eid); 134 $actionsmenu->set_alignment(action_menu::TL, action_menu::BL); 135 136 if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) { 137 $actionsmenu->add($icon); 138 } 139 // MDL-49281 if grade_item already has calculation, it should be editable even if global setting is off. 140 $type = $element['type']; 141 $iscalculated = ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') && $object->is_calculated(); 142 $icon = $this->gtree->get_calculation_icon($element, $this->gpr, true); 143 if ($iscalculated || ($this->show_calculations && $icon)) { 144 $actionsmenu->add($icon); 145 } 146 147 if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) { 148 if ($this->element_deletable($element)) { 149 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey())); 150 $icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete')); 151 $actionsmenu->add($icon); 152 } 153 154 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey())); 155 $moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move'))); 156 } 157 158 if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) { 159 $actionsmenu->add($icon); 160 } 161 162 if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) { 163 $actionsmenu->add($icon); 164 } 165 166 $actions = $OUTPUT->render($actionsmenu); 167 168 $returnrows = array(); 169 $root = false; 170 171 $id = required_param('id', PARAM_INT); 172 173 /// prepare move target if needed 174 $last = ''; 175 176 /// print the list items now 177 if ($this->moving == $eid) { 178 // do not diplay children 179 $cell = new html_table_cell(); 180 $cell->colspan = 12; 181 $cell->attributes['class'] = $element['type'] . ' moving column-name level' . 182 ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd'); 183 $cell->text = $object->name.' ('.get_string('move').')'; 184 return array(new html_table_row(array($cell))); 185 } 186 187 if ($element['type'] == 'category') { 188 $level++; 189 $this->categories[$object->id] = $object->stripped_name; 190 $category = grade_category::fetch(array('id' => $object->id)); 191 $item = $category->get_grade_item(); 192 193 // Add aggregation coef input if not a course item and if parent category has correct aggregation type 194 $dimmed = ($item->is_hidden()) ? 'dimmed_text' : ''; 195 196 // Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan) 197 $aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition); 198 $category_total_data = null; // Used if aggregationposition is set to "last", so we can print it last 199 200 $html_children = array(); 201 202 $row_count = 0; 203 204 foreach($element['children'] as $child_el) { 205 $moveto = null; 206 207 if (empty($child_el['object']->itemtype)) { 208 $child_el['object']->itemtype = false; 209 } 210 211 if (($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') && !$totals) { 212 continue; 213 } 214 215 $child_eid = $child_el['eid']; 216 $first = ''; 217 218 if ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') { 219 $first = array('first' => 1); 220 $child_eid = $eid; 221 } 222 223 if ($this->moving && $this->moving != $child_eid) { 224 225 $strmove = get_string('move'); 226 $strmovehere = get_string('movehere'); 227 $actions = $moveaction = ''; // no action icons when moving 228 229 $aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'move', 'eid' => $this->moving, 'moveafter' => $child_eid, 'sesskey' => sesskey())); 230 if ($first) { 231 $aurl->params($first); 232 } 233 234 $cell = new html_table_cell(); 235 $cell->colspan = 12; 236 $cell->attributes['class'] = 'movehere level' . ($level + 1) . ' level' . ($level % 2 ? 'even' : 'odd'); 237 238 $icon = new pix_icon('movehere', $strmovehere, null, array('class'=>'movetarget')); 239 $cell->text = $OUTPUT->action_icon($aurl, $icon); 240 241 $moveto = new html_table_row(array($cell)); 242 } 243 244 $newparents = $parents; 245 $newparents[] = $eid; 246 247 $row_count++; 248 $child_row_count = 0; 249 250 // If moving, do not print course and category totals, but still print the moveto target box 251 if ($this->moving && ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category')) { 252 $html_children[] = $moveto; 253 } elseif ($child_el['object']->itemtype == 'course' || $child_el['object']->itemtype == 'category') { 254 // We don't build the item yet because we first need to know the deepest level of categories (for category/name colspans) 255 $category_total_item = $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count); 256 if (!$aggregation_position) { 257 $html_children = array_merge($html_children, $category_total_item); 258 } 259 } else { 260 $html_children = array_merge($html_children, $this->build_html_tree($child_el, $totals, $newparents, $level, $child_row_count)); 261 if (!empty($moveto)) { 262 $html_children[] = $moveto; 263 } 264 265 if ($this->moving) { 266 $row_count++; 267 } 268 } 269 270 $row_count += $child_row_count; 271 272 // If the child is a category, increment row_count by one more (for the extra coloured row) 273 if ($child_el['type'] == 'category') { 274 $row_count++; 275 } 276 } 277 278 // Print category total at the end if aggregation position is "last" (1) 279 if (!empty($category_total_item) && $aggregation_position) { 280 $html_children = array_merge($html_children, $category_total_item); 281 } 282 283 // Determine if we are at the root 284 if (isset($element['object']->grade_item) && $element['object']->grade_item->is_course_item()) { 285 $root = true; 286 } 287 288 $levelclass = "level$level level" . ($level % 2 ? 'odd' : 'even'); 289 290 $courseclass = ''; 291 if ($level == 1) { 292 $courseclass = 'coursecategory'; 293 } 294 295 $row = new html_table_row(); 296 $row->id = 'grade-item-' . $eid; 297 $row->attributes['class'] = $courseclass . ' category ' . $dimmed; 298 $row->attributes['data-category'] = $eid; 299 $row->attributes['data-itemid'] = $category->get_grade_item()->id; 300 foreach ($rowclasses as $class) { 301 $row->attributes['class'] .= ' ' . $class; 302 } 303 304 $headercell = new html_table_cell(); 305 $headercell->header = true; 306 $headercell->scope = 'row'; 307 $headercell->attributes['title'] = $object->stripped_name; 308 $headercell->attributes['class'] = 'cell column-rowspan rowspan ' . $levelclass; 309 $headercell->rowspan = $row_count + 1; 310 $row->cells[] = $headercell; 311 312 foreach ($this->columns as $column) { 313 if (!($this->moving && $column->hide_when_moving)) { 314 $row->cells[] = $column->get_category_cell($category, $levelclass, [ 315 'id' => $id, 316 'name' => $object->name, 317 'level' => $level, 318 'actions' => $actions, 319 'moveaction' => $moveaction, 320 'eid' => $eid, 321 ]); 322 } 323 } 324 325 $returnrows[] = $row; 326 327 $returnrows = array_merge($returnrows, $html_children); 328 329 // Print a coloured row to show the end of the category across the table 330 $endcell = new html_table_cell(); 331 $endcell->colspan = (19 - $level); 332 $endcell->attributes['class'] = 'emptyrow colspan ' . $levelclass; 333 334 $returnrows[] = new html_table_row(array($endcell)); 335 336 } else { // Dealing with a grade item 337 338 $item = grade_item::fetch(array('id' => $object->id)); 339 $element['type'] = 'item'; 340 $element['object'] = $item; 341 342 $categoryitemclass = ''; 343 if ($item->itemtype == 'category') { 344 $categoryitemclass = 'categoryitem'; 345 } 346 if ($item->itemtype == 'course') { 347 $categoryitemclass = 'courseitem'; 348 } 349 350 $dimmed = ($item->is_hidden()) ? "dimmed_text" : ""; 351 $gradeitemrow = new html_table_row(); 352 $gradeitemrow->id = 'grade-item-' . $eid; 353 $gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed; 354 $gradeitemrow->attributes['data-itemid'] = $object->id; 355 foreach ($rowclasses as $class) { 356 $gradeitemrow->attributes['class'] .= ' ' . $class; 357 } 358 359 foreach ($this->columns as $column) { 360 if (!($this->moving && $column->hide_when_moving)) { 361 $gradeitemrow->cells[] = $column->get_item_cell($item, array('id' => $id, 'name' => $object->name, 362 'level' => $level, 'actions' => $actions, 'element' => $element, 'eid' => $eid, 363 'moveaction' => $moveaction, 'itemtype' => $object->itemtype)); 364 } 365 } 366 367 $returnrows[] = $gradeitemrow; 368 } 369 370 return $returnrows; 371 372 } 373 374 /** 375 * Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it. 376 * @param grade_item $item 377 * @return string HTML 378 */ 379 static function get_weight_input($item) { 380 global $OUTPUT; 381 382 if (!is_object($item) || get_class($item) !== 'grade_item') { 383 throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)'); 384 return false; 385 } 386 387 if ($item->is_course_item()) { 388 return ''; 389 } 390 391 $parent_category = $item->get_parent_category(); 392 $parent_category->apply_forced_settings(); 393 $aggcoef = $item->get_coefstring(); 394 395 $itemname = $item->itemname; 396 if ($item->is_category_item()) { 397 // Remember, the parent category of a category item is the category itself. 398 $itemname = $parent_category->get_name(); 399 } 400 $str = ''; 401 402 if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') { 403 return '<label class="accesshide" for="weight_'.$item->id.'">' . 404 get_string('extracreditvalue', 'grades', $itemname).'</label>' . 405 html_writer::empty_tag('input', [ 406 'type' => 'text', 407 'size' => 6, 408 'id' => 'weight_' . $item->id, 409 'name' => 'weight_' . $item->id, 410 'value' => self::format_number($item->aggregationcoef), 411 ]); 412 413 } else if ($aggcoef == 'aggregationcoefextraweightsum') { 414 415 $checkboxname = 'weightoverride_' . $item->id; 416 $checkboxlbl = html_writer::tag('label', get_string('overrideweightofa', 'grades', $itemname), 417 array('for' => $checkboxname, 'class' => 'accesshide')); 418 $checkbox = html_writer::empty_tag('input', [ 419 'name' => $checkboxname, 420 'type' => 'hidden', 421 'value' => 0, 422 ]); 423 424 $checkbox .= html_writer::empty_tag('input', [ 425 'name' => $checkboxname, 426 'type' => 'checkbox', 427 'value' => 1, 428 'id' => $checkboxname, 429 'class' => 'weightoverride', 430 'checked' => ($item->weightoverride ? 'checked' : null), 431 ]); 432 433 $name = 'weight_' . $item->id; 434 $hiddenlabel = html_writer::tag( 435 'label', 436 get_string('weightofa', 'grades', $itemname), 437 array( 438 'class' => 'accesshide', 439 'for' => $name 440 ) 441 ); 442 443 $input = html_writer::empty_tag( 444 'input', 445 array( 446 'type' => 'text', 447 'size' => 6, 448 'id' => $name, 449 'name' => $name, 450 'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0), 451 'disabled' => ($item->weightoverride ? null : 'disabled') 452 ) 453 ); 454 455 $str .= $checkboxlbl . $checkbox . $hiddenlabel . $input; 456 } 457 458 return $str; 459 } 460 461 // Trims trailing zeros. 462 // Used on the 'Gradebook setup' page for grade items settings like aggregation co-efficient. 463 // Grader report has its own decimal place settings so they are handled elsewhere. 464 static function format_number($number) { 465 $formatted = rtrim(format_float($number, 4),'0'); 466 if (substr($formatted, -1)==get_string('decsep', 'langconfig')) { //if last char is the decimal point 467 $formatted .= '0'; 468 } 469 return $formatted; 470 } 471 472 /** 473 * Given an element of the grade tree, returns whether it is deletable or not (only manual grade items are deletable) 474 * 475 * @param array $element 476 * @return bool 477 */ 478 function element_deletable($element) { 479 global $COURSE; 480 481 if ($element['type'] != 'item') { 482 return true; 483 } 484 485 $grade_item = $element['object']; 486 487 if ($grade_item->itemtype != 'mod' or $grade_item->is_outcome_item() or $grade_item->gradetype == GRADE_TYPE_NONE) { 488 return true; 489 } 490 491 $modinfo = get_fast_modinfo($COURSE); 492 if (!isset($modinfo->instances[$grade_item->itemmodule][$grade_item->iteminstance])) { 493 // module does not exist 494 return true; 495 } 496 497 return false; 498 } 499 500 /** 501 * Given the grade tree and an array of element ids (e.g. c15, i42), and expecting the 'moveafter' URL param, 502 * moves the selected items to the requested location. Then redirects the user to the given $returnurl 503 * 504 * @param object $gtree The grade tree (a recursive representation of the grade categories and grade items) 505 * @param array $eids 506 * @param string $returnurl 507 */ 508 function move_elements($eids, $returnurl) { 509 $moveafter = required_param('moveafter', PARAM_INT); 510 511 if (!is_array($eids)) { 512 $eids = array($eids); 513 } 514 515 if(!$after_el = $this->gtree->locate_element("cg$moveafter")) { 516 print_error('invalidelementid', '', $returnurl); 517 } 518 519 $after = $after_el['object']; 520 $parent = $after; 521 $sortorder = $after->get_sortorder(); 522 523 foreach ($eids as $eid) { 524 if (!$element = $this->gtree->locate_element($eid)) { 525 print_error('invalidelementid', '', $returnurl); 526 } 527 $object = $element['object']; 528 529 $object->set_parent($parent->id); 530 $object->move_after_sortorder($sortorder); 531 $sortorder++; 532 } 533 534 redirect($returnurl, '', 0); 535 } 536 537 /** 538 * Recurses through the entire grade tree to find and return the maximum depth of the tree. 539 * This should be run only once from the root element (course category), and is used for the 540 * indentation of the Name column's cells (colspan) 541 * 542 * @param array $element An array of values representing a grade tree's element (all grade items in this case) 543 * @param int $level The level of the current recursion 544 * @param int $deepest_level A value passed to each subsequent level of recursion and incremented if $level > $deepest_level 545 * @return int Deepest level 546 */ 547 function get_deepest_level($element, $level=0, $deepest_level=1) { 548 $object = $element['object']; 549 550 $level++; 551 $coefstring = $element['object']->get_coefstring(); 552 if ($element['type'] == 'category') { 553 if ($coefstring == 'aggregationcoefweight' || $coefstring == 'aggregationcoefextraweightsum' || 554 $coefstring == 'aggregationcoefextraweight') { 555 $this->uses_weight = true; 556 } 557 558 foreach($element['children'] as $child_el) { 559 if ($level > $deepest_level) { 560 $deepest_level = $level; 561 } 562 $deepest_level = $this->get_deepest_level($child_el, $level, $deepest_level); 563 } 564 565 $category = grade_category::fetch(array('id' => $object->id)); 566 $item = $category->get_grade_item(); 567 if ($item->gradetype == GRADE_TYPE_NONE) { 568 // Add 1 more level for grade category that has no total. 569 $deepest_level++; 570 } 571 } 572 573 return $deepest_level; 574 } 575 } 576 577 /** 578 * Class grade_edit_tree_column 579 * 580 * @package core_grades 581 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 582 */ 583 abstract class grade_edit_tree_column { 584 public $forced; 585 public $hidden; 586 public $forced_hidden; 587 public $advanced_hidden; 588 public $hide_when_moving = true; 589 /** 590 * html_table_cell object used as a template for header cells in all categories. 591 * It must be cloned before being used. 592 * @var html_table_cell $headercell 593 */ 594 public $headercell; 595 /** 596 * html_table_cell object used as a template for category cells in all categories. 597 * It must be cloned before being used. 598 * @var html_table_cell $categorycell 599 */ 600 public $categorycell; 601 /** 602 * html_table_cell object used as a template for item cells in all categories. 603 * It must be cloned before being used. 604 * @var html_table_cell $itemcell 605 */ 606 public $itemcell; 607 608 public static function factory($name, $params=array()) { 609 $class_name = "grade_edit_tree_column_$name"; 610 if (class_exists($class_name)) { 611 return new $class_name($params); 612 } 613 } 614 615 public abstract function get_header_cell(); 616 617 public function get_category_cell($category, $levelclass, $params) { 618 $cell = clone($this->categorycell); 619 $cell->attributes['class'] .= ' ' . $levelclass; 620 $cell->attributes['text'] = ''; 621 return $cell; 622 } 623 624 public function get_item_cell($item, $params) { 625 $cell = clone($this->itemcell); 626 $cell->attributes['text'] = ''; 627 if (isset($params['level'])) { 628 $level = $params['level'] + (($item->itemtype == 'category' || $item->itemtype == 'course') ? 0 : 1); 629 $cell->attributes['class'] .= ' level' . $level; 630 $cell->attributes['class'] .= ' level' . ($level % 2 ? 'odd' : 'even'); 631 } 632 return $cell; 633 } 634 635 public function __construct() { 636 $this->headercell = new html_table_cell(); 637 $this->headercell->header = true; 638 $this->headercell->attributes['class'] = 'header'; 639 640 $this->categorycell = new html_table_cell(); 641 $this->categorycell->attributes['class'] = 'cell'; 642 643 $this->itemcell = new html_table_cell(); 644 $this->itemcell->attributes['class'] = 'cell'; 645 646 if (preg_match('/^grade_edit_tree_column_(\w*)$/', get_class($this), $matches)) { 647 $this->headercell->attributes['class'] .= ' column-' . $matches[1]; 648 $this->categorycell->attributes['class'] .= ' column-' . $matches[1]; 649 $this->itemcell->attributes['class'] .= ' column-' . $matches[1]; 650 } 651 } 652 } 653 654 /** 655 * Class grade_edit_tree_column_name 656 * 657 * @package core_grades 658 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 659 */ 660 class grade_edit_tree_column_name extends grade_edit_tree_column { 661 public $forced = false; 662 public $hidden = false; 663 public $forced_hidden = false; 664 public $advanced_hidden = false; 665 public $deepest_level = 1; 666 public $hide_when_moving = false; 667 668 public function __construct($params) { 669 if (empty($params['deepest_level'])) { 670 throw new Exception('Tried to instantiate a grade_edit_tree_column_name object without the "deepest_level" param!'); 671 } 672 673 $this->deepest_level = $params['deepest_level']; 674 parent::__construct(); 675 } 676 677 public function get_header_cell() { 678 $headercell = clone($this->headercell); 679 $headercell->colspan = $this->deepest_level + 1; 680 $headercell->text = get_string('name'); 681 return $headercell; 682 } 683 684 public function get_category_cell($category, $levelclass, $params) { 685 global $OUTPUT; 686 if (empty($params['name']) || empty($params['level'])) { 687 throw new Exception('Array key (name or level) missing from 3rd param of grade_edit_tree_column_name::get_category_cell($category, $levelclass, $params)'); 688 } 689 $moveaction = isset($params['moveaction']) ? $params['moveaction'] : ''; 690 $categorycell = parent::get_category_cell($category, $levelclass, $params); 691 $categorycell->colspan = ($this->deepest_level +1) - $params['level']; 692 $categorycell->text = $OUTPUT->heading($moveaction . $params['name'], 4); 693 return $categorycell; 694 } 695 696 public function get_item_cell($item, $params) { 697 global $CFG; 698 699 if (empty($params['element']) || empty($params['name']) || empty($params['level'])) { 700 throw new Exception('Array key (name, level or element) missing from 2nd param of grade_edit_tree_column_name::get_item_cell($item, $params)'); 701 } 702 703 $name = $params['name']; 704 $moveaction = isset($params['moveaction']) ? $params['moveaction'] : ''; 705 706 $itemcell = parent::get_item_cell($item, $params); 707 $itemcell->colspan = ($this->deepest_level + 1) - $params['level']; 708 $itemcell->text = $moveaction . $name; 709 return $itemcell; 710 } 711 } 712 713 /** 714 * Class grade_edit_tree_column_weight 715 * 716 * @package core_grades 717 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 718 */ 719 class grade_edit_tree_column_weight extends grade_edit_tree_column { 720 721 public function get_header_cell() { 722 global $OUTPUT; 723 $headercell = clone($this->headercell); 724 $headercell->text = get_string('weights', 'grades').$OUTPUT->help_icon('aggregationcoefweight', 'grades'); 725 return $headercell; 726 } 727 728 public function get_category_cell($category, $levelclass, $params) { 729 730 $item = $category->get_grade_item(); 731 $categorycell = parent::get_category_cell($category, $levelclass, $params); 732 $categorycell->text = grade_edit_tree::get_weight_input($item); 733 return $categorycell; 734 } 735 736 public function get_item_cell($item, $params) { 737 global $CFG; 738 if (empty($params['element'])) { 739 throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)'); 740 } 741 $itemcell = parent::get_item_cell($item, $params); 742 $itemcell->text = ' '; 743 $object = $params['element']['object']; 744 745 if (!in_array($object->itemtype, array('courseitem', 'categoryitem', 'category')) 746 && !in_array($object->gradetype, array(GRADE_TYPE_NONE, GRADE_TYPE_TEXT)) 747 && (!$object->is_outcome_item() || $object->load_parent_category()->aggregateoutcomes) 748 && ($object->gradetype != GRADE_TYPE_SCALE || !empty($CFG->grade_includescalesinaggregation))) { 749 $itemcell->text = grade_edit_tree::get_weight_input($item); 750 } 751 752 return $itemcell; 753 } 754 } 755 756 /** 757 * Class grade_edit_tree_column_range 758 * 759 * @package core_grades 760 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 761 */ 762 class grade_edit_tree_column_range extends grade_edit_tree_column { 763 764 public function get_header_cell() { 765 $headercell = clone($this->headercell); 766 $headercell->text = get_string('maxgrade', 'grades'); 767 return $headercell; 768 } 769 770 public function get_category_cell($category, $levelclass, $params) { 771 $categorycell = parent::get_category_cell($category, $levelclass, $params); 772 $categorycell->text = ' - '; 773 return $categorycell; 774 } 775 776 public function get_item_cell($item, $params) { 777 global $DB, $OUTPUT; 778 779 // If the parent aggregation is Natural, we should show the number, even for scales, as that value is used... 780 // ...in the computation. For text grades, the grademax is not used, so we can still show the no value string. 781 $parentcat = $item->get_parent_category(); 782 if ($item->gradetype == GRADE_TYPE_TEXT) { 783 $grademax = ' - '; 784 } else if ($item->gradetype == GRADE_TYPE_SCALE) { 785 $scale = $DB->get_record('scale', array('id' => $item->scaleid)); 786 $scale_items = null; 787 if (empty($scale)) { //if the item is using a scale that's been removed 788 $scale_items = array(); 789 } else { 790 $scale_items = explode(',', $scale->scale); 791 } 792 if ($parentcat->aggregation == GRADE_AGGREGATE_SUM) { 793 $grademax = end($scale_items) . ' (' . 794 format_float($item->grademax, $item->get_decimals()) . ')'; 795 } else { 796 $grademax = end($scale_items) . ' (' . count($scale_items) . ')'; 797 } 798 } else { 799 $grademax = format_float($item->grademax, $item->get_decimals()); 800 } 801 802 $isextracredit = false; 803 if ($item->aggregationcoef > 0) { 804 // For category grade items, we need the grandparent category. 805 // The parent is just category the grade item represents. 806 if ($item->is_category_item()) { 807 $grandparentcat = $parentcat->get_parent_category(); 808 if ($grandparentcat->is_extracredit_used()) { 809 $isextracredit = true; 810 } 811 } else if ($parentcat->is_extracredit_used()) { 812 $isextracredit = true; 813 } 814 } 815 if ($isextracredit) { 816 $grademax .= ' ' . html_writer::tag('abbr', get_string('aggregationcoefextrasumabbr', 'grades'), 817 array('title' => get_string('aggregationcoefextrasum', 'grades'))); 818 } 819 820 $itemcell = parent::get_item_cell($item, $params); 821 $itemcell->text = $grademax; 822 return $itemcell; 823 } 824 } 825 826 /** 827 * Class grade_edit_tree_column_actions 828 * 829 * @package core_grades 830 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 831 */ 832 class grade_edit_tree_column_actions extends grade_edit_tree_column { 833 834 public function __construct($params) { 835 parent::__construct(); 836 } 837 838 public function get_header_cell() { 839 $headercell = clone($this->headercell); 840 $headercell->text = get_string('actions'); 841 return $headercell; 842 } 843 844 public function get_category_cell($category, $levelclass, $params) { 845 846 if (empty($params['actions'])) { 847 throw new Exception('Array key (actions) missing from 3rd param of grade_edit_tree_column_actions::get_category_actions($category, $levelclass, $params)'); 848 } 849 850 $categorycell = parent::get_category_cell($category, $levelclass, $params); 851 $categorycell->text = $params['actions']; 852 return $categorycell; 853 } 854 855 public function get_item_cell($item, $params) { 856 if (empty($params['actions'])) { 857 throw new Exception('Array key (actions) missing from 2nd param of grade_edit_tree_column_actions::get_item_cell($item, $params)'); 858 } 859 $itemcell = parent::get_item_cell($item, $params); 860 $itemcell->text = $params['actions']; 861 return $itemcell; 862 } 863 } 864 865 /** 866 * Class grade_edit_tree_column_select 867 * 868 * @package core_grades 869 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 870 */ 871 class grade_edit_tree_column_select extends grade_edit_tree_column { 872 873 public function get_header_cell() { 874 $headercell = clone($this->headercell); 875 $headercell->text = get_string('select'); 876 return $headercell; 877 } 878 879 public function get_category_cell($category, $levelclass, $params) { 880 if (empty($params['eid'])) { 881 throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)'); 882 } 883 $selectall = html_writer::link('#', get_string('all'), [ 884 'data-action' => 'grade_edittree-index-bulkselect', 885 'data-checked' => true, 886 ]); 887 $selectnone = html_writer::link('#', get_string('none'), [ 888 'data-action' => 'grade_edittree-index-bulkselect', 889 'data-checked' => false, 890 ]); 891 892 $categorycell = parent::get_category_cell($category, $levelclass, $params); 893 $categorycell->text = $selectall . ' / ' . $selectnone; 894 return $categorycell; 895 } 896 897 public function get_item_cell($item, $params) { 898 if (empty($params['itemtype']) || empty($params['eid'])) { 899 print_error('missingitemtypeoreid', 'core_grades'); 900 } 901 $itemcell = parent::get_item_cell($item, $params); 902 903 if ($params['itemtype'] != 'course' && $params['itemtype'] != 'category') { 904 $itemcell->text = '<label class="accesshide" for="select_'.$params['eid'].'">'. 905 get_string('select', 'grades', $item->itemname).'</label> 906 <input class="itemselect ignoredirty" type="checkbox" name="select_'.$params['eid'].'" id="select_'.$params['eid']. 907 '"/>'; 908 } 909 return $itemcell; 910 } 911 } 912
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |