See Release Notes
Long Term Support Release
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 * Generator for the gradingforum_rubric plugin. 19 * 20 * @package gradingform_rubric 21 * @category test 22 * @copyright 2018 Adrian Greeve <adriangreeve.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace tests\gradingform_rubric\generator; 27 28 use gradingform_controller; 29 use stdClass; 30 31 /** 32 * Test rubric. 33 * 34 * @package gradingform_rubric 35 * @category test 36 * @copyright 2018 Adrian Greeve <adriangreeve.com> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class rubric { 40 41 /** @var array $criteria The criteria for this rubric. */ 42 protected $criteria = []; 43 44 /** @var string The name of this rubric. */ 45 protected $name; 46 47 /** @var string A description for this rubric. */ 48 protected $description; 49 50 /** @var array The rubric options. */ 51 protected $options = []; 52 53 /** 54 * Create a new gradingform_rubric_generator_rubric. 55 * 56 * @param string $name 57 * @param string $description 58 */ 59 public function __construct(string $name, string $description) { 60 $this->name = $name; 61 $this->description = $description; 62 63 $this->set_option('sortlevelsasc', 1); 64 $this->set_option('lockzeropoints', 1); 65 $this->set_option('showdescriptionteacher', 1); 66 $this->set_option('showdescriptionstudent', 1); 67 $this->set_option('showscoreteacher', 1); 68 $this->set_option('showscorestudent', 1); 69 $this->set_option('enableremarks', 1); 70 $this->set_option('showremarksstudent', 1); 71 } 72 73 /** 74 * Creates the rubric using the appropriate APIs. 75 */ 76 public function get_definition(): stdClass { 77 return (object) [ 78 'name' => $this->name, 79 'description_editor' => [ 80 'text' => $this->description, 81 'format' => FORMAT_HTML, 82 'itemid' => 1 83 ], 84 'rubric' => [ 85 'criteria' => $this->get_all_criterion_values(), 86 'options' => $this->options, 87 ], 88 'saverubric' => 'Save rubric and make it ready', 89 'status' => gradingform_controller::DEFINITION_STATUS_READY, 90 ]; 91 } 92 93 /** 94 * Set an option for the rubric. 95 * 96 * @param string $key 97 * @param mixed $value 98 * @return self 99 */ 100 public function set_option(string $key, $value): self { 101 $this->options[$key] = $value; 102 return $this; 103 } 104 105 /** 106 * Adds a criterion to the rubric. 107 * 108 * @param criterion $criterion The criterion object (class below). 109 * @return self 110 */ 111 public function add_criteria(criterion $criterion): self { 112 $this->criteria[] = $criterion; 113 114 return $this; 115 } 116 117 /** 118 * Get all criterion values. 119 * 120 * @return array 121 */ 122 protected function get_all_criterion_values(): array { 123 $result = []; 124 125 foreach ($this->criteria as $index => $criterion) { 126 $id = $index + 1; 127 $result["NEWID{$id}"] = $criterion->get_all_values($id); 128 } 129 130 return $result; 131 132 } 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body