/**
  * Test the getInput method.
  *
  * @return void
  */
 public function testGetInput()
 {
     $form = new JFormInspector('form1');
     $this->assertThat($form->load('<form><field name="list" type="list" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
     $field = new Field_List($form);
     $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.');
     $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.');
     // TODO: Should check all the attributes have come in properly.
 }
 /**
  * Method to get a list of options for a list input.
  *
  * @return	array		An array of JHtml options.
  *
  * @since   11.4
  */
 protected function getOptions()
 {
     $folder = $this->element['folder'];
     if (!empty($folder)) {
         // Get list of plugins
         $db = Factory::getDbo();
         $query = $db->getQuery(true);
         $query->select('element AS value, name AS text');
         $query->from('#__extensions');
         $query->where('folder = ' . $db->q($folder));
         $query->where('enabled = 1');
         $query->order('ordering, name');
         $db->setQuery($query);
         $options = $db->loadObjectList();
         $lang = Factory::getLanguage();
         foreach ($options as $i => $item) {
             $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value;
             $extension = 'plg_' . $folder . '_' . $item->value;
             $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, null, false, false) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
             $options[$i]->text = Text::_($item->text);
         }
     } else {
         Log::add(Text::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), Log::WARNING, 'jerror');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * Method to get the custom field options.
  * Use the query attribute to supply a query to generate the list.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 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'];
     $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
     $query = (string) $this->element['query'];
     // Get the database object.
     $db = Factory::getDBO();
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = Html::_('select.option', $item->{$key}, JText::_($item->{$value}));
             } else {
                 $options[] = Html::_('select.option', $item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
示例#4
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   1.0
  */
 protected function getOptions()
 {
     $options = array();
     // Initialize some field attributes.
     $first = (int) $this->element['first'];
     $last = (int) $this->element['last'];
     $step = (int) $this->element['step'];
     // Sanity checks.
     if ($step == 0) {
         // Step of 0 will create an endless loop.
         return $options;
     } elseif ($first < $last && $step < 0) {
         // A negative step will never reach the last number.
         return $options;
     } elseif ($first > $last && $step > 0) {
         // A position step will never reach the last number.
         return $options;
     } elseif ($step < 0) {
         // Build the options array backwards.
         for ($i = $first; $i >= $last; $i += $step) {
             $options[] = HtmlSelect::option($i);
         }
     } else {
         // Build the options array.
         for ($i = $first; $i <= $last; $i += $step) {
             $options[] = HtmlSelect::option($i);
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
示例#5
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   1.0
  */
 protected function getOptions()
 {
     $basePath = $this->element['base_path'] ? (string) $this->element['base_path'] : JPATH_ROOT;
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $this->createLanguageList($this->value, $basePath));
     return $options;
 }
 /**
  * Method to get the field options.
  *
  * @return  array    The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Convert to name => name array.
     foreach (Cache::getStores() as $store) {
         $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text');
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * Method to get the session handler field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Get the options from JSession.
     foreach (Session::getStores() as $store) {
         $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     // Initialize some field attributes.
     $client = (string) $this->element['client'];
     if ($client != 'site' && $client != 'administrator') {
         $client = 'site';
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), LanguageHelper::createLanguageList($this->value, constant('JPATH_' . strtoupper($client)), true, true));
     return $options;
 }
示例#9
0
 /**
  * Method to get the list of files for the field options.
  * Specify the target directory with a directory attribute
  * Attributes allow an exclude mask and stripping of extensions from file name.
  * Default attribute may optionally be set to null (no file) or -1 (use a default).
  *
  * @return  array  The field option objects.
  *
  * @since   1.0
  */
 protected function getOptions()
 {
     $options = array();
     // Initialize some field attributes.
     $filter = (string) $this->element['filter'];
     $exclude = (string) $this->element['exclude'];
     $stripExt = (string) $this->element['stripext'];
     $hideNone = (string) $this->element['hide_none'];
     $hideDefault = (string) $this->element['hide_default'];
     // Get the path in which to search for file options.
     $path = (string) $this->element['directory'];
     if (!is_dir($path)) {
         $path = JPATH_ROOT . '/' . $path;
     }
     // Prepend some default options based on field attributes.
     if (!$hideNone) {
         $options[] = HtmlSelect::option('-1', Text::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)));
     }
     if (!$hideDefault) {
         $options[] = HtmlSelect::option('', Text::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)));
     }
     // Get a list of files in the search path with the given filter.
     $files = Folder::files($path, $filter);
     // Build the options list from the list of files.
     if (is_array($files)) {
         foreach ($files as $file) {
             // Check to see if the file is in the exclude mask.
             if ($exclude) {
                 if (preg_match(chr(1) . $exclude . chr(1), $file)) {
                     continue;
                 }
             }
             // If the extension is to be stripped, do it.
             if ($stripExt) {
                 $file = File::stripExt($file);
             }
             $options[] = HtmlSelect::option($file, $file);
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }