Source for file calendar.php

Documentation is available at calendar.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Form Field class for the Joomla Platform.
  14.  *
  15.  * Provides a pop up date picker linked to a button.
  16.  * Optionally may be filtered to use user's or server's time zone.
  17.  *
  18.  * @package     Joomla.Platform
  19.  * @subpackage  Form
  20.  * @since       11.1
  21.  */
  22. {
  23.     /**
  24.      * The form field type.
  25.      *
  26.      * @var    string 
  27.      * @since  11.1
  28.      */
  29.     protected $type = 'Calendar';
  30.  
  31.     /**
  32.      * The allowable maxlength of calendar field.
  33.      *
  34.      * @var    integer 
  35.      * @since  3.2
  36.      */
  37.     protected $maxlength;
  38.  
  39.     /**
  40.      * The format of date and time.
  41.      *
  42.      * @var    integer 
  43.      * @since  3.2
  44.      */
  45.     protected $format;
  46.  
  47.     /**
  48.      * The filter.
  49.      *
  50.      * @var    integer 
  51.      * @since  3.2
  52.      */
  53.     protected $filter;
  54.  
  55.     /**
  56.      * Method to get certain otherwise inaccessible properties from the form field object.
  57.      *
  58.      * @param   string  $name  The property name for which to the the value.
  59.      *
  60.      * @return  mixed  The property value or null.
  61.      *
  62.      * @since   3.2
  63.      */
  64.     public function __get($name)
  65.     {
  66.         switch ($name)
  67.         {
  68.             case 'maxlength':
  69.             case 'format':
  70.             case 'filter':
  71.                 return $this->$name;
  72.         }
  73.  
  74.         return parent::__get($name);
  75.     }
  76.  
  77.     /**
  78.      * Method to set certain otherwise inaccessible properties of the form field object.
  79.      *
  80.      * @param   string  $name   The property name for which to the the value.
  81.      * @param   mixed   $value  The value of the property.
  82.      *
  83.      * @return  void 
  84.      *
  85.      * @since   3.2
  86.      */
  87.     public function __set($name$value)
  88.     {
  89.         switch ($name)
  90.         {
  91.             case 'maxlength':
  92.                 $value = (int) $value;
  93.  
  94.             case 'format':
  95.             case 'filter':
  96.                 $this->$name = (string) $value;
  97.                 break;
  98.  
  99.             default:
  100.                 parent::__set($name$value);
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * Method to attach a JForm object to the field.
  106.      *
  107.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  108.      * @param   mixed             $value    The form field value to validate.
  109.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  110.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  111.      *                                       full field name would end up being "bar[foo]".
  112.      *
  113.      * @return  boolean  True on success.
  114.      *
  115.      * @see     JFormField::setup()
  116.      * @since   3.2
  117.      */
  118.     public function setup(SimpleXMLElement $element$value$group null)
  119.     {
  120.         $return parent::setup($element$value$group);
  121.  
  122.         if ($return)
  123.         {
  124.             $this->maxlength = (int) $this->element['maxlength'? (int) $this->element['maxlength'45;
  125.             $this->format    = (string) $this->element['format'? (string) $this->element['format''%Y-%m-%d';
  126.             $this->filter    = (string) $this->element['filter'? (string) $this->element['filter''USER_UTC';
  127.         }
  128.  
  129.         return $return;
  130.     }
  131.  
  132.     /**
  133.      * Method to get the field input markup.
  134.      *
  135.      * @return  string  The field input markup.
  136.      *
  137.      * @since   11.1
  138.      */
  139.     protected function getInput()
  140.     {
  141.         // Translate placeholder text
  142.         $hint $this->translateHint ? JText::_($this->hint$this->hint;
  143.  
  144.         // Initialize some field attributes.
  145.         $format $this->format;
  146.  
  147.         // Build the attributes array.
  148.         $attributes array();
  149.  
  150.         empty($this->size)      null $attributes['size'$this->size;
  151.         empty($this->maxlengthnull $attributes['maxlength'$this->maxlength;
  152.         empty($this->class)     null $attributes['class'$this->class;
  153.         !$this->readonly        ? null $attributes['readonly''';
  154.         !$this->disabled        ? null $attributes['disabled''';
  155.         empty($this->onchange)  null $attributes['onchange'$this->onchange;
  156.         empty($hint)            null $attributes['placeholder'$hint;
  157.         $this->autocomplete     ? null $attributes['autocomplete''off';
  158.         !$this->autofocus       ? null $attributes['autofocus''';
  159.  
  160.         if ($this->required)
  161.         {
  162.             $attributes['required''';
  163.             $attributes['aria-required''true';
  164.         }
  165.  
  166.         // Handle the special case for "now".
  167.         if (strtoupper($this->value== 'NOW')
  168.         {
  169.             $this->value = strftime($format);
  170.         }
  171.  
  172.         // Get some system objects.
  173.         $config JFactory::getConfig();
  174.         $user JFactory::getUser();
  175.  
  176.         // If a known filter is given use it.
  177.         switch (strtoupper($this->filter))
  178.         {
  179.             case 'SERVER_UTC':
  180.                 // Convert a date to UTC based on the server timezone.
  181.                 if ((int) $this->value)
  182.                 {
  183.                     // Get a date object based on the correct timezone.
  184.                     $date JFactory::getDate($this->value'UTC');
  185.                     $date->setTimezone(new DateTimeZone($config->get('offset')));
  186.  
  187.                     // Transform the date string.
  188.                     $this->value = $date->format('Y-m-d H:i:s'truefalse);
  189.                 }
  190.  
  191.                 break;
  192.  
  193.             case 'USER_UTC':
  194.                 // Convert a date to UTC based on the user timezone.
  195.                 if ((int) $this->value)
  196.                 {
  197.                     // Get a date object based on the correct timezone.
  198.                     $date JFactory::getDate($this->value'UTC');
  199.  
  200.                     $date->setTimezone(new DateTimeZone($user->getParam('timezone'$config->get('offset'))));
  201.  
  202.                     // Transform the date string.
  203.                     $this->value = $date->format('Y-m-d H:i:s'truefalse);
  204.                 }
  205.  
  206.                 break;
  207.         }
  208.  
  209.         // Including fallback code for HTML5 non supported browsers.
  210.         JHtml::_('jquery.framework');
  211.         JHtml::_('script''system/html5fallback.js'falsetrue);
  212.  
  213.         return JHtml::_('calendar'$this->value$this->name$this->id$format$attributes);
  214.     }
  215. }

Documentation generated on Tue, 19 Nov 2013 14:54:59 +0100 by phpDocumentor 1.4.3