Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Class used to render a feedback input box.
  19   *
  20   * @package   gradereport_singleview
  21   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace gradereport_singleview\local\ui;
  26  
  27  defined('MOODLE_INTERNAL') || die;
  28  
  29  /**
  30   * Class used to render a feedback input box.
  31   *
  32   * @package   gradereport_singleview
  33   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class feedback extends grade_attribute_format implements unique_value, be_disabled {
  37  
  38      /** @var string $name Name of this input */
  39      public $name = 'feedback';
  40  
  41      /**
  42       * Get the value for this input.
  43       *
  44       * @return string The value
  45       */
  46      public function get_value() {
  47          return $this->grade->feedback ? $this->grade->feedback : '';
  48      }
  49  
  50      /**
  51       * Get the string to use in the label for this input.
  52       *
  53       * @return string The label text
  54       */
  55      public function get_label() {
  56          if (!isset($this->grade->label)) {
  57              $this->grade->label = '';
  58          }
  59          return $this->grade->label;
  60      }
  61  
  62      /**
  63       * Determine if this input should be disabled based on the other settings.
  64       *
  65       * @return boolean Should this input be disabled when the page loads.
  66       */
  67      public function is_disabled() {
  68          $locked = 0;
  69          $gradeitemlocked = 0;
  70          $overridden = 0;
  71          /* Disable editing if grade item or grade score is locked
  72          * if any of these items are set,  then we will disable editing
  73          * at some point, we might want to show the reason for the lock
  74          * this code could be simplified, but its more readable for steve's little mind
  75          */
  76          if (!empty($this->grade->locked)) {
  77              $locked = 1;
  78          }
  79          if (!empty($this->grade->grade_item->locked)) {
  80              $gradeitemlocked = 1;
  81          }
  82          if ($this->grade->grade_item->is_overridable_item() and !$this->grade->is_overridden()) {
  83              $overridden = 1;
  84          }
  85          return ($locked || $gradeitemlocked || $overridden);
  86      }
  87  
  88      /**
  89       * Create a text_attribute for this ui element.
  90       *
  91       * @return text_attribute
  92       */
  93      public function determine_format() {
  94          return new text_attribute(
  95              $this->get_name(),
  96              $this->get_value(),
  97              $this->get_label(),
  98              $this->is_disabled()
  99          );
 100      }
 101  
 102      /**
 103       * Update the value for this input.
 104       *
 105       * @param string $value The new feedback value.
 106       * @return string Any error message
 107       */
 108      public function set($value) {
 109          $finalgrade = false;
 110          $trimmed = trim($value);
 111          if (empty($trimmed)) {
 112              $feedback = null;
 113          } else {
 114              $feedback = $value;
 115          }
 116  
 117          $this->grade->grade_item->update_final_grade(
 118              $this->grade->userid, $finalgrade, 'singleview',
 119              $feedback, FORMAT_MOODLE
 120          );
 121      }
 122  }