Source for file meter.php

Documentation is available at meter.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. /**
  14.  * Form Field class for the Joomla Platform.
  15.  * Provides a meter to show value in a range.
  16.  *
  17.  * @package     Joomla.Platform
  18.  * @subpackage  Form
  19.  * @link        http://www.w3.org/TR/html-markup/input.text.html#input.text
  20.  * @since       3.2
  21.  */
  22. {
  23.     /**
  24.      * The form field type.
  25.      *
  26.      * @var    string 
  27.      * @since  3.2
  28.      */
  29.     protected $type = 'Meter';
  30.  
  31.     /**
  32.      * The width of the field increased or decreased.
  33.      *
  34.      * @var    string 
  35.      * @since  3.2
  36.      */
  37.     protected $width;
  38.  
  39.     /**
  40.      * Whether the field is active or not.
  41.      *
  42.      * @var    boolean 
  43.      * @since  3.2
  44.      */
  45.     protected $active = false;
  46.  
  47.     /**
  48.      * Whether the field is animated or not.
  49.      *
  50.      * @var    boolean 
  51.      * @since  3.2
  52.      */
  53.     protected $animated = true;
  54.  
  55.     /**
  56.      * The color of the field
  57.      *
  58.      * @var    boolean 
  59.      * @since  3.2
  60.      */
  61.     protected $color;
  62.  
  63.     /**
  64.      * Method to get certain otherwise inaccessible properties from the form field object.
  65.      *
  66.      * @param   string  $name  The property name for which to the the value.
  67.      *
  68.      * @return  mixed  The property value or null.
  69.      *
  70.      * @since   3.2
  71.      */
  72.     public function __get($name)
  73.     {
  74.         switch ($name)
  75.         {
  76.             case 'active':
  77.             case 'width':
  78.             case 'animated':
  79.             case 'color':
  80.                 return $this->$name;
  81.         }
  82.  
  83.         return parent::__get($name);
  84.     }
  85.  
  86.     /**
  87.      * Method to set certain otherwise inaccessible properties of the form field object.
  88.      *
  89.      * @param   string  $name   The property name for which to the the value.
  90.      * @param   mixed   $value  The value of the property.
  91.      *
  92.      * @return  void 
  93.      *
  94.      * @since   3.2
  95.      */
  96.     public function __set($name$value)
  97.     {
  98.         switch ($name)
  99.         {
  100.             case 'width':
  101.             case 'color':
  102.                 $this->$name = (string) $value;
  103.                 break;
  104.  
  105.             case 'active':
  106.                 $value = (string) $value;
  107.                 $this->$name ($value === 'true' || $value === $name || $value === '1');
  108.                 break;
  109.  
  110.             case 'animated':
  111.                 $value = (string) $value;
  112.                 $this->$name !($value === 'false' || $value === 'off' || $value === '0');
  113.                 break;
  114.  
  115.             default:
  116.                 parent::__set($name$value);
  117.         }
  118.     }
  119.  
  120.     /**
  121.      * Method to attach a JForm object to the field.
  122.      *
  123.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  124.      * @param   mixed             $value    The form field value to validate.
  125.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  126.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  127.      *                                       full field name would end up being "bar[foo]".
  128.      *
  129.      * @return  boolean  True on success.
  130.      *
  131.      * @see     JFormField::setup()
  132.      * @since   3.2
  133.      */
  134.     public function setup(SimpleXMLElement $element$value$group null)
  135.     {
  136.         $return parent::setup($element$value$group);
  137.  
  138.         if ($return)
  139.         {
  140.             $this->width = isset($this->element['width']? (string) $this->element['width''';
  141.             $this->color = isset($this->element['color']? (string) $this->element['color''';
  142.  
  143.             $active       = (string) $this->element['active'];
  144.             $this->active = ($active == 'true' || $active == 'on' || $active == '1');
  145.  
  146.             $animated       = (string) $this->element['animated'];
  147.             $this->animated = !($animated == 'false' || $animated == 'off' || $animated == '0');
  148.         }
  149.  
  150.         return $return;
  151.     }
  152.  
  153.     /**
  154.      * Method to get the field input markup.
  155.      *
  156.      * @return  string  The field input markup.
  157.      *
  158.      * @since   3.2
  159.      */
  160.     protected function getInput()
  161.     {
  162.         // Initialize some field attributes.
  163.         $width !empty($this->width' style="width:' $this->width . ';"' '';
  164.         $color !empty($this->color' background-color:' $this->color . ';' '';
  165.  
  166.         $data '';
  167.         $data .= ' data-max="' $this->max . '"';
  168.         $data .= ' data-min="' $this->min . '"';
  169.         $data .= ' data-step="' $this->step . '"';
  170.  
  171.         $class 'progress ' $this->class;
  172.         $class .= $this->animated ? ' progress-striped' '';
  173.         $class .= $this->active ? ' active' '';
  174.         $class ' class="' $class '"';
  175.  
  176.         $value = (float) $this->value;
  177.         $value $value $this->min ? $this->min : $value;
  178.         $value $value $this->max ? $this->max : $value;
  179.  
  180.         $data .= ' data-value="' $this->value . '"';
  181.  
  182.         $value ((float) ($value $this->min100($this->max - $this->min);
  183.  
  184.         $html['<div ' $class $width $data ' >';
  185.         $html['        <div class="bar" style="width: ' strval($value'%;' $color '"></div>';
  186.         $html['</div>';
  187.  
  188.         return implode(''$html);
  189.     }
  190. }

Documentation generated on Tue, 19 Nov 2013 15:08:10 +0100 by phpDocumentor 1.4.3