Source for file fieldselectable.php

Documentation is available at fieldselectable.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. /**
  12.  * Generic field header, with drop down filters
  13.  *
  14.  * @package  FrameworkOnFramework
  15.  * @since    2.0
  16.  */
  17. {
  18.     /**
  19.      * Create objects for the options
  20.      *
  21.      * @return  array  The array of option objects
  22.      */
  23.     protected function getOptions()
  24.     {
  25.         $options array();
  26.  
  27.         // Do we have a class and method source for our options?
  28.         $source_file empty($this->element['source_file']'' : (string) $this->element['source_file'];
  29.         $source_class empty($this->element['source_class']'' : (string) $this->element['source_class'];
  30.         $source_method empty($this->element['source_method']'' : (string) $this->element['source_method'];
  31.         $source_key empty($this->element['source_key']'*' : (string) $this->element['source_key'];
  32.         $source_value empty($this->element['source_value']'*' : (string) $this->element['source_value'];
  33.         $source_translate empty($this->element['source_translate']'true' : (string) $this->element['source_translate'];
  34.         $source_translate in_array(strtolower($source_translate)array('true','yes','1','on')) true false;
  35.         $source_format empty($this->element['source_format']'' : (string) $this->element['source_format'];
  36.  
  37.         if ($source_class && $source_method)
  38.         {
  39.             // Maybe we have to load a file?
  40.             if (!empty($source_file))
  41.             {
  42.                 $source_file FOFTemplateUtils::parsePath($source_filetrue);
  43.  
  44.                 JLoader::import('joomla.filesystem.file');
  45.  
  46.                 if (JFile::exists($source_file))
  47.                 {
  48.                     include_once $source_file;
  49.                 }
  50.             }
  51.  
  52.             // Make sure the class exists
  53.             if (class_exists($source_classtrue))
  54.             {
  55.                 // ...and so does the option
  56.                 if (in_array($source_methodget_class_methods($source_class)))
  57.                 {
  58.                     // Get the data from the class
  59.                     if ($source_format == 'optionsobject')
  60.                     {
  61.                         $options $source_class::$source_method();
  62.                     }
  63.                     else
  64.                     {
  65.                         $source_data $source_class::$source_method();
  66.  
  67.                         // Loop through the data and prime the $options array
  68.                         foreach ($source_data as $k => $v)
  69.                         {
  70.                             $key (empty($source_key|| ($source_key == '*')) $k $v[$source_key];
  71.                             $value (empty($source_value|| ($source_value == '*')) $v $v[$source_value];
  72.  
  73.                             if ($source_translate)
  74.                             {
  75.                                 $value JText::_($value);
  76.                             }
  77.  
  78.                             $options[JHtml::_('select.option'$key$value'value''text');
  79.                         }
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.  
  85.         // Get the field $options
  86.         foreach ($this->element->children(as $option)
  87.         {
  88.             // Only add <option /> elements.
  89.             if ($option->getName(!= 'option')
  90.             {
  91.                 continue;
  92.             }
  93.  
  94.             // Create a new option object based on the <option /> element.
  95.             $options[JHtml::_(
  96.                 'select.option',
  97.                 (string) $option['value'],
  98.                 JText::alt(
  99.                     trim((string) $option),
  100.                     preg_replace('/[^a-zA-Z0-9_\-]/''_'$this->fieldname)
  101.                 ),
  102.                 'value''text'((string) $option['disabled'== 'true')
  103.             );
  104.         }
  105.  
  106.         reset($options);
  107.  
  108.         return $options;
  109.     }
  110. }

Documentation generated on Tue, 19 Nov 2013 15:03:00 +0100 by phpDocumentor 1.4.3