Source for file fieldsql.php

Documentation is available at fieldsql.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 based on a SQL query
  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.         // Initialize some field attributes.
  28.         $key       $this->element['key_field'? (string) $this->element['key_field''value';
  29.         $value     $this->element['value_field'? (string) $this->element['value_field': (string) $this->element['name'];
  30.         $translate $this->element['translate'? (string) $this->element['translate'false;
  31.         $query     = (string) $this->element['query'];
  32.  
  33.         // Get the database object.
  34.         $db JFactory::getDBO();
  35.  
  36.         // Set the query and get the result list.
  37.         $db->setQuery($query);
  38.         $items $db->loadObjectlist();
  39.  
  40.         // Build the field options.
  41.         if (!empty($items))
  42.         {
  43.             foreach ($items as $item)
  44.             {
  45.                 if ($translate == true)
  46.                 {
  47.                     $options[JHtml::_('select.option'$item->$keyJText::_($item->$value));
  48.                 }
  49.                 else
  50.                 {
  51.                     $options[JHtml::_('select.option'$item->$key$item->$value);
  52.                 }
  53.             }
  54.         }
  55.  
  56.         // Merge any additional options in the XML definition.
  57.         $options array_merge(parent::getOptions()$options);
  58.  
  59.         return $options;
  60.     }
  61. }

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