예제 #1
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     $options = array();
     $this->value = array();
     $value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
     $input = new FOFInput();
     $component = ucfirst(str_replace('com_', '', $input->getString('option')));
     $view = ucfirst($input->getString('view'));
     $relation = FOFInflector::pluralize((string) $this->element['name']);
     $model = FOFModel::getTmpInstance(ucfirst($relation), $component . 'Model');
     $table = $model->getTable();
     $key = $table->getKeyName();
     $value = $table->getColumnAlias($value_field);
     foreach ($model->getItemList(true) as $option) {
         $options[] = JHtml::_('select.option', $option->{$key}, $option->{$value});
     }
     if ($id = FOFModel::getAnInstance($view)->getId()) {
         $table = FOFTable::getInstance($view, $component . 'Table');
         $table->load($id);
         $relations = $table->getRelations()->getMultiple($relation);
         foreach ($relations as $item) {
             $this->value[] = $item->getId();
         }
     }
     return $options;
 }