[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/grade/report/singleview/classes/local/ui/ -> text_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   * UI element for a text input field.
  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  defined('MOODLE_INTERNAL') || die;
  29  
  30  /**
  31   * UI element for a text input field.
  32   *
  33   * @package   gradereport_singleview
  34   * @copyright 2014 Moodle Pty Ltd (http://moodle.com)
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class text_attribute extends element {
  38  
  39      /** @var bool $isdisabled Is this input disabled? */
  40      private $isdisabled;
  41  
  42      /**
  43       * Constructor
  44       *
  45       * @param string $name The input name (the first bit)
  46       * @param string $value The input initial value.
  47       * @param string $label The label for this input field.
  48       * @param bool $isdisabled Is this input disabled.
  49       */
  50      public function __construct($name, $value, $label, $isdisabled = false) {
  51          $this->isdisabled = $isdisabled;
  52          parent::__construct($name, $value, $label);
  53      }
  54  
  55      /**
  56       * Nasty function allowing custom textbox behaviour outside the class.
  57       * @return bool Is this a textbox.
  58       */
  59      public function is_textbox() {
  60          return true;
  61      }
  62  
  63      /**
  64       * Render the html for this field.
  65       * @return string The HTML.
  66       */
  67      public function html() {
  68          $attributes = array(
  69              'type' => 'text',
  70              'name' => $this->name,
  71              'value' => $this->value,
  72              'id' => $this->name
  73          );
  74  
  75          if ($this->isdisabled) {
  76              $attributes['disabled'] = 'DISABLED';
  77          }
  78  
  79          $hidden = array(
  80              'type' => 'hidden',
  81              'name' => 'old' . $this->name,
  82              'value' => $this->value
  83          );
  84  
  85          $label = '';
  86          if (preg_match("/^feedback/", $this->name)) {
  87              $labeltitle = get_string('feedbackfor', 'gradereport_singleview', $this->label);
  88              $attributes['tabindex'] = '2';
  89              $label = html_writer::tag('label', $labeltitle,  array('for' => $this->name, 'class' => 'accesshide'));
  90          } else if (preg_match("/^finalgrade/", $this->name)) {
  91              $labeltitle = get_string('gradefor', 'gradereport_singleview', $this->label);
  92              $attributes['tabindex'] = '1';
  93              $label = html_writer::tag('label', $labeltitle,  array('for' => $this->name, 'class' => 'accesshide'));
  94          }
  95  
  96          return (
  97              $label .
  98              html_writer::empty_tag('input', $attributes) .
  99              html_writer::empty_tag('input', $hidden)
 100          );
 101      }
 102  }


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