Example #1
0
 /**
  * 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.
  */
 protected function getOptions()
 {
     // Initialize variables.
     $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 = App::get('db');
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Check for an error.
     if ($db->getErrorNum()) {
         return $options;
     }
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = Dropdown::option($item->{$key}, App::get('language')->txt($item->{$value}));
             } else {
                 $options[] = Dropdown::option($item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #2
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Initialize variables.
     $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;
     }
     // Build the options array.
     for ($i = $first; $i <= $last; $i += $step) {
         $options[] = Dropdown::option($i);
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #3
0
 /**
  * Method to get a list of options for a list input.
  *
  * @return  array  An array of Html options.
  */
 protected function getOptions()
 {
     // Initialise variables
     $folder = $this->element['folder'];
     if (!empty($folder)) {
         // Get list of plugins
         $db = App::get('db');
         $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 = App::get('language');
         foreach ($options as $i => $item) {
             $extension = 'plg_' . $folder . '_' . $item->value;
             $lang->load($extension . '.sys', PATH_APP . '/plugins/' . $folder . '/' . $item->value, null, false, true) || $lang->load($extension . '.sys', PATH_CORE . '/plugins/' . $folder . '/' . $item->value, null, false, true);
             $options[$i]->text = $lang->txt($item->text);
         }
         if ($db->getErrorMsg()) {
             return '';
         }
     } else {
         App::abort(500, App::get('language')->txt('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'));
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #4
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Convert to name => name array.
     foreach (Manager::getStores() as $store) {
         $options[] = Dropdown::option($store, App::get('language')->txt('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text');
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #5
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Initialize some field attributes.
     $client = (string) $this->element['client'];
     if ($client != 'site' && $client != 'administrator') {
         $client = 'site';
     }
     $path = PATH_APP . DS . 'bootstrap' . DS . $client;
     if (!is_dir($path)) {
         $path = PATH_CORE . DS . 'bootstrap' . DS . $client;
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), App::get('language')->getList($this->value, $path, true, true));
     return $options;
 }
Example #6
0
 /**
  * Method to get the field options for category
  * Use the extension attribute in a form to specify the.specific extension for
  * which categories should be displayed.
  * Use the show_root attribute to specify whether to show the global category root in the list.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Initialise variables.
     $options = array();
     $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope'];
     $published = (string) $this->element['published'];
     $name = (string) $this->element['name'];
     // Load the category options for a given extension.
     if (!empty($extension)) {
         // Filter over published state or not depending upon if it is present.
         if ($published) {
             $options = Cat::options($extension, array('filter.published' => explode(',', $published)));
         } else {
             $options = Cat::options($extension);
         }
         // Verify permissions.  If the action attribute is set, then we scan the options.
         if ((string) $this->element['action']) {
             // Get the current user object.
             $user = App::get('user')->getInstance();
             // For new items we want a list of categories you are allowed to create in.
             if (!$this->form->getValue($name)) {
                 foreach ($options as $i => $option) {
                     // To take save or create in a category you need to have create rights for that category
                     // unless the item is already in that category.
                     // Unset the option if the user isn't authorised for it. In this field assets are always categories.
                     if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true) {
                         unset($options[$i]);
                     }
                 }
             } else {
                 $categoryOld = $this->form->getValue($name);
                 foreach ($options as $i => $option) {
                     // If you are only allowed to edit in this category but not edit.state, you should not get any
                     // option to change the category.
                     if ($user->authorise('core.edit.state', $extension . '.category.' . $categoryOld) != true) {
                         if ($option->value != $categoryOld) {
                             unset($options[$i]);
                         }
                     } elseif ($user->authorise('core.create', $extension . '.category.' . $option->value) != true && $option->value != $categoryOld) {
                         unset($options[$i]);
                     }
                 }
             }
         }
         if (isset($this->element['show_root'])) {
             array_unshift($options, Dropdown::option('0', App::get('language')->txt('JGLOBAL_ROOT')));
         }
     } else {
         App::abort(500, App::get('language')->txt('JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY'));
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Example #7
0
 /**
  * Method to get the field options for content languages.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     // Merge any additional options in the XML definition.
     return array_merge(parent::getOptions(), ContentLang::existing());
 }
Example #8
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.
  */
 protected function getOptions()
 {
     // Initialize variables.
     $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 = PATH_ROOT . '/' . $path;
     }
     // Prepend some default options based on field attributes.
     if (!$hideNone) {
         $options[] = Dropdown::option('-1', App::get('filesystem')->alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)));
     }
     if (!$hideDefault) {
         $options[] = Dropdown::option('', App::get('filesystem')->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 = App::get('filesystem')->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 = App::get('filesystem')->name($file);
             }
             $options[] = Dropdown::option($file, $file);
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }