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   * Checkbox element used for bulk inserting values in the gradebook.
  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 html_writer;
  28  
  29  defined('MOODLE_INTERNAL') || die;
  30  
  31  /**
  32   * Checkbox element used for bulk inserting values in the gradebook.
  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  class bulk_insert extends element {
  39  
  40      /**
  41       * Constructor
  42       *
  43       * @param mixed $item The grade item or user.
  44       */
  45      public function __construct($item) {
  46          $this->name = 'bulk_' . $item->id;
  47          $this->applyname = $this->name_for('apply');
  48          $this->selectname = $this->name_for('type');
  49          $this->insertname = $this->name_for('value');
  50      }
  51  
  52      /**
  53       * Is this checkbox checked?
  54       *
  55       * @param array $data The form data
  56       * @return bool
  57       */
  58      public function is_applied($data) {
  59          return isset($data->{$this->applyname});
  60      }
  61  
  62      /**
  63       * Get the type of this input (user or grade)
  64       *
  65       * @param array $data The form data
  66       * @return string
  67       */
  68      public function get_type($data) {
  69          return $data->{$this->selectname};
  70      }
  71  
  72      /**
  73       * Get the value from either the user or grade.
  74       *
  75       * @param array $data The form data
  76       * @return string
  77       */
  78      public function get_insert_value($data) {
  79          return $data->{$this->insertname};
  80      }
  81  
  82      /**
  83       * Generate the html for this form element.
  84       *
  85       * @return string HTML
  86       */
  87      public function html() {
  88          global $OUTPUT;
  89  
  90          $text = new text_attribute($this->insertname, "0", 'bulk');
  91          $context = (object) [
  92              'label' => get_string('bulklegend', 'gradereport_singleview'),
  93              'applylabel' => get_string('bulkperform', 'gradereport_singleview'),
  94              'applyname' => $this->applyname,
  95              'menuname' => $this->selectname,
  96              'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'),
  97              'menuoptions' => [
  98                  ['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')],
  99                  ['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true],
 100              ],
 101              'valuename' => $this->insertname,
 102              'valuelabel' => get_string('bulkinsertvalue', 'gradereport_singleview'),
 103              'valuefield' => $text->html()
 104          ];
 105  
 106          return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context);
 107      }
 108  
 109      /**
 110       * This form element has 3 elements with different suffixes.
 111       * Generate the name with the suffix.
 112       *
 113       * @param string $extend The suffix.
 114       * @return string
 115       */
 116      private function name_for($extend) {
 117          return "{$this->name}_$extend";
 118      }
 119  }