示例#1
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     $options = array();
     // Initialize some field attributes.
     $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
     $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
     $applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
     $modelName = (string) $this->element['model'];
     $nonePlaceholder = (string) $this->element['none'];
     $translate = empty($this->element['translate']) ? 'true' : (string) $this->element['translate'];
     $translate = in_array(strtolower($translate), array('true', 'yes', '1', 'on')) ? true : false;
     if (!empty($nonePlaceholder)) {
         $options[] = JHtml::_('select.option', JText::_($nonePlaceholder), null);
     }
     // Process field atrtibutes
     $applyAccess = strtolower($applyAccess);
     $applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
     // Explode model name into model name and prefix
     $parts = FOFInflector::explode($modelName);
     $mName = ucfirst(array_pop($parts));
     $mPrefix = FOFInflector::implode($parts);
     // Get the model object
     $config = array('savestate' => 0);
     $model = FOFModel::getTmpInstance($mName, $mPrefix, $config);
     if ($applyAccess) {
         $model->applyAccessFiltering();
     }
     // Process state variables
     foreach ($this->element->children() as $stateoption) {
         // Only add <option /> elements.
         if ($stateoption->getName() != 'state') {
             continue;
         }
         $stateKey = (string) $stateoption['key'];
         $stateValue = (string) $stateoption;
         $model->setState($stateKey, $stateValue);
     }
     // Set the query and get the result list.
     $items = $model->getItemList(true);
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = JHtml::_('select.option', $item->{$key}, JText::_($item->{$value}));
             } else {
                 $options[] = JHtml::_('select.option', $item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
示例#2
0
 /**
  * Normalises the format of a relation name
  *
  * @param   string   $itemName   The raw relation name
  * @param   boolean  $pluralise  Should I pluralise the name? If not, I will singularise it
  *
  * @return  string  The normalised relation key name
  */
 protected function normaliseItemName($itemName, $pluralise = false)
 {
     // Explode the item name
     $itemNameParts = explode('_', $itemName);
     // If we have multiple parts the first part is considered to be the component name
     if (count($itemNameParts) > 1) {
         $prefix = array_shift($itemNameParts);
     } else {
         $prefix = null;
     }
     // If we still have multiple parts we need to pluralise/singularise the last part and join everything in
     // CamelCase format
     if (count($itemNameParts) > 1) {
         $name = array_pop($itemNameParts);
         $name = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name);
         $itemNameParts[] = $name;
         $itemName = FOFInflector::implode($itemNameParts);
     } else {
         $name = array_pop($itemNameParts);
         $itemName = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name);
     }
     if (!empty($prefix)) {
         $itemName = $prefix . '_' . $itemName;
     }
     return $itemName;
 }
 /**
  * Returns current view object
  *
  * @param   array  $config  Configuration variables for the model
  *
  * @return  FOFView  The global instance of the view object (singleton)
  */
 public final function getThisView($config = array())
 {
     if (!is_object($this->_viewObject)) {
         // Make sure $config is an array
         if (is_object($config)) {
             $config = (array) $config;
         } elseif (!is_array($config)) {
             $config = array();
         }
         $prefix = null;
         $viewName = null;
         $viewType = null;
         if (!empty($this->viewName)) {
             $parts = FOFInflector::explode($this->viewName);
             $viewName = ucfirst(array_pop($parts));
             $prefix = FOFInflector::implode($parts);
         } else {
             $prefix = ucfirst($this->bareComponent) . 'View';
             $viewName = ucfirst($this->view);
         }
         $document = FOFPlatform::getInstance()->getDocument();
         if ($document instanceof JDocument) {
             $viewType = $document->getType();
         } else {
             $viewType = $this->input->getCmd('format', 'html');
         }
         if ($viewType == 'html' && $this->hasForm) {
             $viewType = 'form';
         }
         if (!array_key_exists('input', $config) || !$config['input'] instanceof FOFInput) {
             $config['input'] = $this->input;
         }
         $config['input']->set('base_path', $this->basePath);
         $this->_viewObject = $this->getView($viewName, $viewType, $prefix, $config);
     }
     return $this->_viewObject;
 }