Source for file calendar.php

Documentation is available at calendar.php

  1. <?php
  2. /**
  3.  * @package    FrameworkOnFramework
  4.  * @subpackage form
  5.  * @copyright  Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. if (!class_exists('JFormFieldCalendar'))
  12. {
  13.     require_once JPATH_LIBRARIES '/joomla/form/fields/calendar.php';
  14. }
  15.  
  16. /**
  17.  * Form Field class for the FOF framework
  18.  * Supports a calendar / date field.
  19.  *
  20.  * @package  FrameworkOnFramework
  21.  * @since    2.0
  22.  */
  23. {
  24.     protected $static;
  25.  
  26.     protected $repeatable;
  27.     
  28.     /** @var   FOFTable  The item being rendered in a repeatable form field */
  29.     public $item;
  30.     
  31.     /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
  32.     public $rowid;
  33.  
  34.     /**
  35.      * Method to get certain otherwise inaccessible properties from the form field object.
  36.      *
  37.      * @param   string  $name  The property name for which to the the value.
  38.      *
  39.      * @return  mixed  The property value or null.
  40.      *
  41.      * @since   2.0
  42.      */
  43.     public function __get($name)
  44.     {
  45.         switch ($name)
  46.         {
  47.             // ATTENTION: Redirected getInput() to getStatic()
  48.             case 'input':
  49.                 if (empty($this->static))
  50.                 {
  51.                     $this->static = $this->getStatic();
  52.                 }
  53.  
  54.                 return $this->static;
  55.                 break;
  56.  
  57.             case 'repeatable':
  58.                 if (empty($this->repeatable))
  59.                 {
  60.                     $this->repeatable = $this->getRepeatable();
  61.                 }
  62.  
  63.                 return $this->static;
  64.                 break;
  65.  
  66.             default:
  67.                 return parent::__get($name);
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * Get the rendering of this field type for static display, e.g. in a single
  73.      * item view (typically a "read" task).
  74.      *
  75.      * @since 2.0
  76.      *
  77.      * @return  string  The field HTML
  78.      */
  79.     public function getStatic()
  80.     {
  81.         return $this->getCalendar('static');
  82.     }
  83.  
  84.     /**
  85.      * Get the rendering of this field type for a repeatable (grid) display,
  86.      * e.g. in a view listing many item (typically a "browse" task)
  87.      *
  88.      * @since 2.0
  89.      *
  90.      * @return  string  The field HTML
  91.      */
  92.     public function getRepeatable()
  93.     {
  94.         return $this->getCalendar('repeatable');
  95.     }
  96.  
  97.     /**
  98.      * Method to get the calendar input markup.
  99.      *
  100.      * @param    string    $display    The display to render ('static' or 'repeatable')
  101.      *
  102.      * @return  string    The field input markup.
  103.      *
  104.      * @since   2.1.rc4
  105.      */
  106.     protected function getCalendar($display)
  107.     {
  108.         // Initialize some field attributes.
  109.         $format $this->element['format'? (string) $this->element['format''%Y-%m-%d';
  110.         $class  $this->element['class'? (string) $this->element['class''';
  111.  
  112.         // PHP date doesn't use percentages (%) for the format, but the calendar Javascript
  113.         // DOES use it (@see: calendar-uncompressed.js). Therefore we have to convert it.
  114.         $formatJS  $format;
  115.         $formatPHP str_replace('%'''$formatJS);
  116.  
  117.         // Get some system objects.
  118.         $config JFactory::getConfig();
  119.         $user JFactory::getUser();
  120.         $date JFactory::getDate($this->value'UTC');
  121.  
  122.         // If a known filter is given use it.
  123.         switch (strtoupper((string) $this->element['filter']))
  124.         {
  125.             case 'SERVER_UTC':
  126.                 // Convert a date to UTC based on the server timezone.
  127.                 if ((int) $this->value)
  128.                 {
  129.                     // Get a date object based on the correct timezone.
  130.                     $date->setTimezone(new DateTimeZone($config->get('offset')));
  131.                 }
  132.                 break;
  133.  
  134.             case 'USER_UTC':
  135.                 // Convert a date to UTC based on the user timezone.
  136.                 if ((int) $this->value)
  137.                 {
  138.                     // Get a date object based on the correct timezone.
  139.                     $date->setTimezone(new DateTimeZone($user->getParam('timezone'$config->get('offset'))));
  140.                 }
  141.                 break;
  142.  
  143.             default:
  144.                 break;
  145.         }
  146.  
  147.         // Transform the date string.
  148.         $this->value = $date->format($formatPHPtruefalse);
  149.  
  150.         if ($display == 'static')
  151.         {
  152.             // Build the attributes array.
  153.             $attributes array();
  154.  
  155.             if ($this->element['size'])
  156.             {
  157.                 $attributes['size'= (int) $this->element['size'];
  158.             }
  159.             if ($this->element['maxlength'])
  160.             {
  161.                 $attributes['maxlength'= (int) $this->element['maxlength'];
  162.             }
  163.             if ($this->element['class'])
  164.             {
  165.                 $attributes['class'= (string) $this->element['class'];
  166.             }
  167.             if ((string) $this->element['readonly'== 'true')
  168.             {
  169.                 $attributes['readonly''readonly';
  170.             }
  171.             if ((string) $this->element['disabled'== 'true')
  172.             {
  173.                 $attributes['disabled''disabled';
  174.             }
  175.             if ($this->element['onchange'])
  176.             {
  177.                 $attributes['onchange'= (string) $this->element['onchange'];
  178.             }
  179.             if ($this->required)
  180.             {
  181.                 $attributes['required''required';
  182.                 $attributes['aria-required''true';
  183.             }
  184.  
  185.             return JHtml::_('calendar'$this->value$this->name$this->id$formatJS$attributes);
  186.         }
  187.         else
  188.         {
  189.             return '<span class="' $this->id . ' ' $class '">' .
  190.             htmlspecialchars($this->valueENT_COMPAT'UTF-8'.
  191.             '</span>';
  192.         }
  193.     }
  194. }

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