[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/grade/report/singleview/classes/local/ui/ -> bulk_insert.php (source)

   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          $insertvalue = get_string('bulkinsertvalue', 'gradereport_singleview');
  89          $insertappliesto = get_string('bulkappliesto', 'gradereport_singleview');
  90  
  91          $insertoptions = array(
  92              'all' => get_string('all_grades', 'gradereport_singleview'),
  93              'blanks' => get_string('blanks', 'gradereport_singleview')
  94          );
  95  
  96          $selectlabel = html_writer::label(
  97              $insertappliesto,
  98              'menu' . $this->selectname
  99          );
 100          $select = html_writer::select(
 101              $insertoptions,
 102              $this->selectname,
 103              'blanks',
 104              false,
 105              array(
 106                  'id' => 'menu' . $this->selectname
 107              )
 108          );
 109  
 110          $textlabel = html_writer::label(
 111              $insertvalue,
 112              $this->insertname
 113          );
 114          $text = new text_attribute($this->insertname, "0", 'bulk');
 115  
 116          $inner = implode(' ', array(
 117              $selectlabel,
 118              $select,
 119              $textlabel,
 120              $text->html()
 121          ));
 122  
 123          $fieldset = html_writer::tag(
 124              'fieldset',
 125              html_writer::tag(
 126                  'legend',
 127                  get_string('bulklegend', 'gradereport_singleview'),
 128                  array(
 129                      'class' => 'accesshide'
 130                  )
 131              ) .
 132              $inner
 133          );
 134  
 135          $apply = html_writer::checkbox(
 136              $this->applyname,
 137              1,
 138              false,
 139              get_string('bulkperform', 'gradereport_singleview')
 140          );
 141          $applydiv = html_writer::div($apply, 'enable');
 142  
 143          return $applydiv . $fieldset;
 144      }
 145  
 146      /**
 147       * This form element has 3 elements with different suffixes.
 148       * Generate the name with the suffix.
 149       *
 150       * @param string $extend The suffix.
 151       * @return string
 152       */
 153      private function name_for($extend) {
 154          return "{$this->name}_$extend";
 155      }
 156  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1