Source for file model.php

Documentation is available at model.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('JFormFieldSql'))
  12. {
  13.     require_once JPATH_LIBRARIES '/joomla/form/fields/sql.php';
  14. }
  15.  
  16. /**
  17.  * Form Field class for FOF
  18.  * Generic list from a model's results
  19.  *
  20.  * @package  FrameworkOnFramework
  21.  * @since    2.0
  22.  */
  23. {
  24.     /**
  25.      * Method to get the field options.
  26.      *
  27.      * @return  array  The field option objects.
  28.      */
  29.     protected function getOptions()
  30.     {
  31.         $options array();
  32.  
  33.         // Initialize some field attributes.
  34.         $key $this->element['key_field'? (string) $this->element['key_field''value';
  35.         $value $this->element['value_field'? (string) $this->element['value_field': (string) $this->element['name'];
  36.         $translate $this->element['translate'? (string) $this->element['translate'false;
  37.         $applyAccess $this->element['apply_access'? (string) $this->element['apply_access''false';
  38.         $modelName = (string) $this->element['model'];
  39.         $nonePlaceholder = (string) $this->element['none'];
  40.  
  41.         if (!empty($nonePlaceholder))
  42.         {
  43.             $options[JHtml::_('select.option'JText::_($nonePlaceholder)null);
  44.         }
  45.  
  46.         // Process field atrtibutes
  47.         $applyAccess strtolower($applyAccess);
  48.         $applyAccess in_array($applyAccessarray('yes''on''true''1'));
  49.  
  50.         // Explode model name into model name and prefix
  51.         $parts FOFInflector::explode($modelName);
  52.         $mName ucfirst(array_pop($parts));
  53.         $mPrefix FOFInflector::implode($parts);
  54.  
  55.         // Get the model object
  56.         $config array('savestate' => 0);
  57.         $model FOFModel::getTmpInstance($mName$mPrefix$config);
  58.  
  59.         if ($applyAccess)
  60.         {
  61.             $model->applyAccessFiltering();
  62.         }
  63.  
  64.         // Process state variables
  65.         foreach ($this->element->children(as $stateoption)
  66.         {
  67.             // Only add <option /> elements.
  68.             if ($stateoption->getName(!= 'state')
  69.             {
  70.                 continue;
  71.             }
  72.  
  73.             $stateKey = (string) $stateoption['key'];
  74.             $stateValue = (string) $stateoption;
  75.  
  76.             $model->setState($stateKey$stateValue);
  77.         }
  78.  
  79.         // Set the query and get the result list.
  80.         $items $model->getItemList(true);
  81.  
  82.         // Build the field options.
  83.         if (!empty($items))
  84.         {
  85.             foreach ($items as $item)
  86.             {
  87.                 if ($translate == true)
  88.                 {
  89.                     $options[JHtml::_('select.option'$item->$keyJText::_($item->$value));
  90.                 }
  91.                 else
  92.                 {
  93.                     $options[JHtml::_('select.option'$item->$key$item->$value);
  94.                 }
  95.             }
  96.         }
  97.  
  98.         // Merge any additional options in the XML definition.
  99.         $options array_merge(parent::getOptions()$options);
  100.  
  101.         return $options;
  102.     }
  103. }

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