[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/grade/report/singleview/classes/local/ui/ -> dropdown_attribute.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   * Drop down list (select list) 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  use html_writer;
  28  
  29  defined('MOODLE_INTERNAL') || die;
  30  
  31  /**
  32   * Drop down list (select list) element
  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 dropdown_attribute extends element {
  39  
  40      /** @var string $selected Who is selected ? */
  41      private $selected;
  42  
  43      /** @var array $options List of options ? */
  44      private $options;
  45  
  46      /** @var bool $isdisabled Is this input disabled. */
  47      private $isdisabled;
  48  
  49      /**
  50       * Constructor
  51       *
  52       * @param string $name The first bit of the name of this input.
  53       * @param array $options The options list for this select.
  54       * @param string $label The form label for this input.
  55       * @param string $selected The name of the selected item in this input.
  56       * @param bool $isdisabled Are we disabled?
  57       */
  58      public function __construct($name, $options, $label, $selected = '', $isdisabled = false) {
  59          $this->selected = $selected;
  60          $this->options = $options;
  61          $this->isdisabled = $isdisabled;
  62          parent::__construct($name, $selected, $label);
  63      }
  64  
  65      /**
  66       * Nasty function spreading dropdown logic around.
  67       *
  68       * @return bool
  69       */
  70      public function is_dropdown() {
  71          return true;
  72      }
  73  
  74      /**
  75       * Render this element as html.
  76       *
  77       * @return string
  78       */
  79      public function html() {
  80          $old = array(
  81              'type' => 'hidden',
  82              'name' => 'old' . $this->name,
  83              'value' => $this->selected
  84          );
  85  
  86          $attributes = array('tabindex' => '1');
  87  
  88          if (!empty($this->isdisabled)) {
  89              $attributes['disabled'] = 'DISABLED';
  90          }
  91  
  92          $select = html_writer::select(
  93              $this->options, $this->name, $this->selected, false, $attributes
  94          );
  95  
  96          return ($select . html_writer::empty_tag('input', $old));
  97      }
  98  }


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