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   * An override grade checkbox element
  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   * An override grade checkbox element
  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 override extends grade_attribute_format implements be_checked, be_disabled {
  37  
  38      /** @var string $name The name for this input */
  39      public $name = 'override';
  40  
  41      /**
  42       * Is this input checked
  43       *
  44       * @return bool
  45       */
  46      public function is_checked() {
  47          return $this->grade->is_overridden();
  48      }
  49  
  50      /**
  51       * Is this input disabled
  52       *
  53       * @return bool
  54       */
  55      public function is_disabled() {
  56          $lockedgrade = $lockedgradeitem = 0;
  57          if (!empty($this->grade->locked)) {
  58              $lockedgrade = 1;
  59          }
  60          if (!empty($this->grade->grade_item->locked)) {
  61              $lockedgradeitem = 1;
  62          }
  63          return ($lockedgrade || $lockedgradeitem);
  64      }
  65  
  66      /**
  67       * Get the label for this form element.
  68       *
  69       * @return string
  70       */
  71      public function get_label() {
  72          if (!isset($this->grade->label)) {
  73              $this->grade->label = '';
  74          }
  75          return $this->grade->label;
  76      }
  77  
  78      /**
  79       * Generate the element for this form input.
  80       *
  81       * @return element
  82       */
  83      public function determine_format() {
  84          if (!$this->grade->grade_item->is_overridable_item()) {
  85              return new empty_element();
  86          }
  87          return new checkbox_attribute(
  88              $this->get_name(),
  89              $this->get_label(),
  90              $this->is_checked(),
  91              $this->is_disabled()
  92          );
  93      }
  94  
  95      /**
  96       * Save the modified value of this form element.
  97       *
  98       * @param string $value The new value to set
  99       * @return mixed string|false Any error message
 100       */
 101      public function set($value) {
 102          if (empty($this->grade->id)) {
 103              return false;
 104          }
 105  
 106          $state = $value == 0 ? false : true;
 107  
 108          $this->grade->set_overridden($state);
 109          $this->grade->grade_item->force_regrading();
 110          return false;
 111      }
 112  }