| 1 | 
           efrain | 
           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_guide plugin.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    gradingform_guide
  | 
        
        
            | 
            | 
           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_guide\generator;
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           use gradingform_controller;
  | 
        
        
            | 
            | 
           29 | 
           use stdClass;
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           /**
  | 
        
        
            | 
            | 
           32 | 
            * Test guide.
  | 
        
        
            | 
            | 
           33 | 
            *
  | 
        
        
            | 
            | 
           34 | 
            * @package    gradingform_guide
  | 
        
        
            | 
            | 
           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 guide {
  | 
        
        
            | 
            | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
               /** @var array $criteria The criteria for this guide. */
  | 
        
        
            | 
            | 
           42 | 
               protected $criteria = [];
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
               /** @var string The name of this guide. */
  | 
        
        
            | 
            | 
           45 | 
               protected $name;
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
               /** @var string A description for this guide. */
  | 
        
        
            | 
            | 
           48 | 
               protected $description;
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
               /** @var array The guide options. */
  | 
        
        
            | 
            | 
           51 | 
               protected $options = [];
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
               /**
  | 
        
        
            | 
            | 
           54 | 
                * Create a new gradingform_guide_generator_criterion.
  | 
        
        
            | 
            | 
           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('alwaysshowdefinition', 1);
  | 
        
        
            | 
            | 
           64 | 
                   $this->set_option('showmarkspercriterionstudents', 1);
  | 
        
        
            | 
            | 
           65 | 
               }
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
               /**
  | 
        
        
            | 
            | 
           68 | 
                * Creates the guide using the appropriate APIs.
  | 
        
        
            | 
            | 
           69 | 
                */
  | 
        
        
            | 
            | 
           70 | 
               public function get_definition(): stdClass {
  | 
        
        
            | 
            | 
           71 | 
                   return (object) [
  | 
        
        
            | 
            | 
           72 | 
                       'name' => $this->name,
  | 
        
        
            | 
            | 
           73 | 
                       'description_editor' => [
  | 
        
        
            | 
            | 
           74 | 
                           'text' => $this->description,
  | 
        
        
            | 
            | 
           75 | 
                           'format' => FORMAT_HTML,
  | 
        
        
            | 
            | 
           76 | 
                           'itemid' => 1
  | 
        
        
            | 
            | 
           77 | 
                       ],
  | 
        
        
            | 
            | 
           78 | 
                       'guide' => [
  | 
        
        
            | 
            | 
           79 | 
                           'criteria' => $this->get_critiera_as_array(),
  | 
        
        
            | 
            | 
           80 | 
                           'options' => $this->options,
  | 
        
        
            | 
            | 
           81 | 
                           'comments' => [],
  | 
        
        
            | 
            | 
           82 | 
                       ],
  | 
        
        
            | 
            | 
           83 | 
                       'saveguide' => 'Continue',
  | 
        
        
            | 
            | 
           84 | 
                       'status' => gradingform_controller::DEFINITION_STATUS_READY,
  | 
        
        
            | 
            | 
           85 | 
                   ];
  | 
        
        
            | 
            | 
           86 | 
               }
  | 
        
        
            | 
            | 
           87 | 
              | 
        
        
            | 
            | 
           88 | 
               /**
  | 
        
        
            | 
            | 
           89 | 
                * Set an option for the rubric.
  | 
        
        
            | 
            | 
           90 | 
                *
  | 
        
        
            | 
            | 
           91 | 
                * @param string $key
  | 
        
        
            | 
            | 
           92 | 
                * @param mixed $value
  | 
        
        
            | 
            | 
           93 | 
                * @return self
  | 
        
        
            | 
            | 
           94 | 
                */
  | 
        
        
            | 
            | 
           95 | 
               public function set_option(string $key, $value): self {
  | 
        
        
            | 
            | 
           96 | 
                   $this->options[$key] = $value;
  | 
        
        
            | 
            | 
           97 | 
                   return $this;
  | 
        
        
            | 
            | 
           98 | 
               }
  | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
               /**
  | 
        
        
            | 
            | 
           101 | 
                * Adds a criterion to the guide.
  | 
        
        
            | 
            | 
           102 | 
                *
  | 
        
        
            | 
            | 
           103 | 
                * @param criterion $criterion The criterion object (class below).
  | 
        
        
            | 
            | 
           104 | 
                * @return self
  | 
        
        
            | 
            | 
           105 | 
                */
  | 
        
        
            | 
            | 
           106 | 
               public function add_criteria(criterion $criterion): self {
  | 
        
        
            | 
            | 
           107 | 
                   $this->criteria[] = $criterion;
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
                   return $this;
  | 
        
        
            | 
            | 
           110 | 
               }
  | 
        
        
            | 
            | 
           111 | 
              | 
        
        
            | 
            | 
           112 | 
               /**
  | 
        
        
            | 
            | 
           113 | 
                * Get the criteria as an array for use in creation.
  | 
        
        
            | 
            | 
           114 | 
                *
  | 
        
        
            | 
            | 
           115 | 
                * @return array
  | 
        
        
            | 
            | 
           116 | 
                */
  | 
        
        
            | 
            | 
           117 | 
               protected function get_critiera_as_array(): array {
  | 
        
        
            | 
            | 
           118 | 
                   $return = [];
  | 
        
        
            | 
            | 
           119 | 
                   foreach ($this->criteria as $index => $criterion) {
  | 
        
        
            | 
            | 
           120 | 
                       $return["NEWID{$index}"] = $criterion->get_all_values($index + 1);
  | 
        
        
            | 
            | 
           121 | 
                   }
  | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
                   return $return;
  | 
        
        
            | 
            | 
           124 | 
               }
  | 
        
        
            | 
            | 
           125 | 
           }
  |