Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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   * Abstract class for a form element representing something about a grade_grade.
  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  use grade_grade;
  28  
  29  defined('MOODLE_INTERNAL') || die;
  30  
  31  /**
  32   * Abstract class for a form element representing something about a grade_grade.
  33   *
  34   * @package   gradereport_singleview
  35   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  abstract class grade_attribute_format extends attribute_format implements unique_name {
  39  
  40      /**
  41       * The first part of the name attribute of the form input
  42       * @var string $name
  43       */
  44      public $name;
  45  
  46      /**
  47       * The label of the input
  48       * @var null|string $label
  49       */
  50      public $label;
  51  
  52      /**
  53       * The grade_grade of the input
  54       * @var grade_grade $grade
  55       */
  56      public $grade;
  57  
  58      /**
  59       * Constructor
  60       *
  61       * @param grade_grade $grade The grade_grade we are editing.
  62       */
  63      public function __construct($grade = 0) {
  64          $this->grade = $grade;
  65      }
  66  
  67      /**
  68       * Get a unique name for this form input
  69       *
  70       * @return string The form input name attribute.
  71       */
  72      public function get_name(): string {
  73          return "{$this->name}_{$this->grade->itemid}_{$this->grade->userid}";
  74      }
  75  
  76      /**
  77       * Should be overridden by the child class to save the value returned in this input.
  78       *
  79       * @param string $value The value from the form.
  80       * @return string Any error message
  81       */
  82      abstract public function set($value);
  83  }