Source for file groupedlist.php

Documentation is available at groupedlist.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('JFormFieldGroupedList'))
  12. {
  13.     require_once JPATH_LIBRARIES '/joomla/form/fields/groupedlist.php';
  14. }
  15.  
  16. /**
  17.  * Form Field class for FOF
  18.  * Supports a generic list of options.
  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.             case 'static':
  48.                 if (empty($this->static))
  49.                 {
  50.                     $this->static = $this->getStatic();
  51.                 }
  52.  
  53.                 return $this->static;
  54.                 break;
  55.  
  56.             case 'repeatable':
  57.                 if (empty($this->repeatable))
  58.                 {
  59.                     $this->repeatable = $this->getRepeatable();
  60.                 }
  61.  
  62.                 return $this->static;
  63.                 break;
  64.  
  65.             default:
  66.                 return parent::__get($name);
  67.         }
  68.     }
  69.  
  70.     /**
  71.      * Get the rendering of this field type for static display, e.g. in a single
  72.      * item view (typically a "read" task).
  73.      *
  74.      * @since 2.0
  75.      *
  76.      * @return  string  The field HTML
  77.      */
  78.     public function getStatic()
  79.     {
  80.         $class $this->element['class'? (string) $this->element['class''';
  81.  
  82.         $selected self::getOptionName($this->getOptions()$this->value);
  83.  
  84.         if (is_null($selected))
  85.         {
  86.             $selected array(
  87.                 'group'     => '',
  88.                 'item'     => ''
  89.             );
  90.         }
  91.  
  92.         return '<span id="' $this->id . '-group" class="fof-groupedlist-group ' $class '>' .
  93.             htmlspecialchars($selected['group']ENT_COMPAT'UTF-8'.
  94.             '</span>' .
  95.             '<span id="' $this->id . '-item" class="fof-groupedlist-item ' $class '>' .
  96.             htmlspecialchars($selected['item']ENT_COMPAT'UTF-8'.
  97.             '</span>';
  98.     }
  99.  
  100.     /**
  101.      * Get the rendering of this field type for a repeatable (grid) display,
  102.      * e.g. in a view listing many item (typically a "browse" task)
  103.      *
  104.      * @since 2.0
  105.      *
  106.      * @return  string  The field HTML
  107.      */
  108.     public function getRepeatable()
  109.     {
  110.         $class $this->element['class'? (string) $this->element['class''';
  111.  
  112.         $selected self::getOptionName($this->getOptions()$this->value);
  113.  
  114.         if (is_null($selected))
  115.         {
  116.             $selected array(
  117.                 'group'     => '',
  118.                 'item'     => ''
  119.             );
  120.         }
  121.  
  122.         return '<span class="' $this->id . '-group fof-groupedlist-group ' $class '">' .
  123.             htmlspecialchars($selected['group']ENT_COMPAT'UTF-8'.
  124.             '</span>' .
  125.             '<span class="' $this->id . '-item fof-groupedlist-item ' $class '">' .
  126.             htmlspecialchars($selected['item']ENT_COMPAT'UTF-8'.
  127.             '</span>';
  128.     }
  129.  
  130.     /**
  131.      * Gets the active option's label given an array of JHtml options
  132.      *
  133.      * @param   array   $data      The JHtml options to parse
  134.      * @param   mixed   $selected  The currently selected value
  135.      * @param   string  $groupKey  Group name
  136.      * @param   string  $optKey    Key name
  137.      * @param   string  $optText   Value name
  138.      *
  139.      * @return  mixed   The label of the currently selected option
  140.      */
  141.     public static function getOptionName($data$selected null$groupKey 'items'$optKey 'value'$optText 'text')
  142.     {
  143.         $ret null;
  144.  
  145.         foreach ($data as $dataKey => $group)
  146.         {
  147.             $label $dataKey;
  148.             $noGroup is_int($dataKey);
  149.  
  150.             if (is_array($group))
  151.             {
  152.                 $subList $group[$groupKey];
  153.                 $label $group[$optText];
  154.                 $noGroup false;
  155.             }
  156.             elseif (is_object($group))
  157.             {
  158.                 // Sub-list is in a property of an object
  159.                 $subList $group->$groupKey;
  160.                 $label $group->$optText;
  161.                 $noGroup false;
  162.             }
  163.             else
  164.             {
  165.                 throw new RuntimeException('Invalid group contents.'1);
  166.             }
  167.  
  168.             if ($noGroup)
  169.             {
  170.                 $label '';
  171.             }
  172.  
  173.             $match FOFFormFieldList::getOptionName($data$selected$optKey$optText);
  174.  
  175.             if (!is_null($match))
  176.             {
  177.                 $ret array(
  178.                     'group'     => $label,
  179.                     'item'     => $match
  180.                 );
  181.                 break;
  182.             }
  183.         }
  184.  
  185.         return $ret;
  186.     }
  187. }

Documentation generated on Tue, 19 Nov 2013 15:04:07 +0100 by phpDocumentor 1.4.3