Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP version 4.0                                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2003 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 2.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available at through the world-wide-web at                           |
  11  // | http://www.php.net/license/2_02.txt.                                 |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
  17  // |          Bertrand Mansion <bmansion@mamasam.com>                     |
  18  // +----------------------------------------------------------------------+
  19  //
  20  // $Id$
  21  
  22  require_once("HTML/QuickForm/element.php");
  23  
  24  /**
  25   * HTML class for static data
  26   * 
  27   * @author       Wojciech Gdela <eltehaem@poczta.onet.pl>
  28   * @access       public
  29   */
  30  class HTML_QuickForm_static extends HTML_QuickForm_element {
  31      
  32      // {{{ properties
  33  
  34      /**
  35       * Display text
  36       * @var       string
  37       * @access    private
  38       */
  39      var $_text = null;
  40  
  41      // }}}
  42      // {{{ constructor
  43      
  44      /**
  45       * Class constructor
  46       * 
  47       * @param     string    $elementLabel   (optional)Label
  48       * @param     string    $text           (optional)Display text
  49       * @access    public
  50       * @return    void
  51       */
  52      public function __construct($elementName=null, $elementLabel=null, $text=null) {
  53          parent::__construct($elementName, $elementLabel);
  54          $this->_persistantFreeze = false;
  55          $this->_type = 'static';
  56          $this->_text = $text;
  57      } //end constructor
  58  
  59      /**
  60       * Old syntax of class constructor. Deprecated in PHP7.
  61       *
  62       * @deprecated since Moodle 3.1
  63       */
  64      public function HTML_QuickForm_static($elementName=null, $elementLabel=null, $text=null) {
  65          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  66          self::__construct($elementName, $elementLabel, $text);
  67      }
  68  
  69      // }}}
  70      // {{{ setName()
  71  
  72      /**
  73       * Sets the element name
  74       * 
  75       * @param     string    $name   Element name
  76       * @access    public
  77       * @return    void
  78       */
  79      function setName($name)
  80      {
  81          $this->updateAttributes(array('name'=>$name));
  82      } //end func setName
  83      
  84      // }}}
  85      // {{{ getName()
  86  
  87      /**
  88       * Returns the element name
  89       * 
  90       * @access    public
  91       * @return    string
  92       */
  93      function getName()
  94      {
  95          return $this->getAttribute('name');
  96      } //end func getName
  97  
  98      // }}}
  99      // {{{ setText()
 100  
 101      /**
 102       * Sets the text
 103       *
 104       * @param     string    $text
 105       * @access    public
 106       * @return    void
 107       */
 108      function setText($text)
 109      {
 110          $this->_text = $text;
 111      } // end func setText
 112  
 113      // }}}
 114      // {{{ setValue()
 115  
 116      /**
 117       * Sets the text (uses the standard setValue call to emulate a form element.
 118       *
 119       * @param     string    $text
 120       * @access    public
 121       * @return    void
 122       */
 123      function setValue($text)
 124      {
 125          $this->setText($text);
 126      } // end func setValue
 127  
 128      // }}}    
 129      // {{{ toHtml()
 130  
 131      /**
 132       * Returns the static text element in HTML
 133       * 
 134       * @access    public
 135       * @return    string
 136       */
 137      function toHtml()
 138      {
 139          return $this->_getTabs() . $this->_text;
 140      } //end func toHtml
 141      
 142      // }}}
 143      // {{{ getFrozenHtml()
 144  
 145      /**
 146       * Returns the value of field without HTML tags
 147       * 
 148       * @access    public
 149       * @return    string
 150       */
 151      function getFrozenHtml()
 152      {
 153          return $this->toHtml();
 154      } //end func getFrozenHtml
 155  
 156      // }}}
 157      // {{{ onQuickFormEvent()
 158  
 159      /**
 160       * Called by HTML_QuickForm whenever form event is made on this element
 161       *
 162       * @param     string    $event  Name of event
 163       * @param     mixed     $arg    event arguments
 164       * @param     object    $caller calling object
 165       * @since     1.0
 166       * @access    public
 167       * @return    void
 168       * @throws    
 169       */
 170      function onQuickFormEvent($event, $arg, &$caller)
 171      {
 172          switch ($event) {
 173              case 'updateValue':
 174                  // do NOT use submitted values for static elements
 175                  $value = $this->_findValue($caller->_constantValues);
 176                  if (null === $value) {
 177                      $value = $this->_findValue($caller->_defaultValues);
 178                  }
 179                  if (null !== $value) {
 180                      $this->setValue($value);
 181                  }
 182                  break;
 183              default:
 184                  parent::onQuickFormEvent($event, $arg, $caller);
 185          }
 186          return true;
 187      } // end func onQuickFormEvent
 188  
 189      // }}}
 190      // {{{ exportValue()
 191  
 192     /**
 193      * We override this here because we don't want any values from static elements
 194      */
 195      function exportValue(&$submitValues, $assoc = false)
 196      {
 197          return null;
 198      }
 199      
 200      // }}}
 201  } //end class HTML_QuickForm_static
 202  ?>