Esempio n. 1
0
 /**
  * Method to get the field options.
  *
  * Ordering is disabled by default. You can enable ordering by setting the
  * 'order' element in your form field. The other order values are optional.
  *
  * - order					What to order.			Possible values: 'name' or 'value' (default = false)
  * - order_dir				Order direction.		Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
  * - order_case_sensitive	Order case sensitive.	Possible values: 'true' or 'false' (default = false)
  *
  * @return  array  The field option objects.
  *
  * @since	Ordering is available since F0F 2.1.b2.
  */
 protected function getOptions()
 {
     // Ordering is disabled by default for backward compatibility
     $order = false;
     // Set default order direction
     $order_dir = 'asc';
     // Set default value for case sensitive sorting
     $order_case_sensitive = false;
     if ($this->element['order'] && $this->element['order'] !== 'false') {
         $order = $this->element['order'];
     }
     if ($this->element['order_dir']) {
         $order_dir = $this->element['order_dir'];
     }
     if ($this->element['order_case_sensitive']) {
         // Override default setting when the form element value is 'true'
         if ($this->element['order_case_sensitive'] == 'true') {
             $order_case_sensitive = true;
         }
     }
     // Create a $sortOptions array in order to apply sorting
     $i = 0;
     $sortOptions = array();
     foreach ($this->element->children() as $option) {
         $name = JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname));
         $sortOptions[$i] = new stdClass();
         $sortOptions[$i]->option = $option;
         $sortOptions[$i]->value = $option['value'];
         $sortOptions[$i]->name = $name;
         $i++;
     }
     // Only order if it's set
     if ($order) {
         jimport('joomla.utilities.arrayhelper');
         F0FUtilsArray::sortObjects($sortOptions, $order, $order_dir == 'asc' ? 1 : -1, $order_case_sensitive, false);
     }
     // Initialise the options
     $options = array();
     // Get the field $options
     foreach ($sortOptions as $sortOption) {
         $option = $sortOption->option;
         $name = $sortOption->name;
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         $tmp = JHtml::_('select.option', (string) $option['value'], $name, 'value', 'text', (string) $option['disabled'] == 'true');
         // Set some option attributes.
         $tmp->class = (string) $option['class'];
         // Set some JavaScript option attributes.
         $tmp->onclick = (string) $option['onclick'];
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     // Do we have a class and method source for our options?
     $source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file'];
     $source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class'];
     $source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method'];
     $source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
     $source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
     $source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
     $source_translate = in_array(strtolower($source_translate), array('true', 'yes', '1', 'on')) ? true : false;
     $source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
     if ($source_class && $source_method) {
         // Maybe we have to load a file?
         if (!empty($source_file)) {
             $source_file = F0FTemplateUtils::parsePath($source_file, true);
             if (F0FPlatform::getInstance()->getIntegrationObject('filesystem')->fileExists($source_file)) {
                 include_once $source_file;
             }
         }
         // Make sure the class exists
         if (class_exists($source_class, true)) {
             // ...and so does the option
             if (in_array($source_method, get_class_methods($source_class))) {
                 // Get the data from the class
                 if ($source_format == 'optionsobject') {
                     $options = array_merge($options, $source_class::$source_method());
                 } else {
                     // Get the data from the class
                     $source_data = $source_class::$source_method();
                 }
             }
         }
     }
     //to avoid jquery error
     foreach ($source_data as $cat) {
         $cat->title = str_replace(' ', '_', $cat->title);
     }
     return $source_data;
 }
Esempio n. 2
0
 /**
  * Automatically detects all views of the component
  *
  * @return  array  A list of all views, in the order to be displayed in the toolbar submenu
  */
 protected function getMyViews()
 {
     $views = array();
     $t_views = array();
     $using_meta = false;
     $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($this->component);
     $searchPath = $componentPaths['main'] . '/views';
     $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
     $allFolders = $filesystem->folderFolders($searchPath);
     if (!empty($allFolders)) {
         foreach ($allFolders as $folder) {
             $view = $folder;
             // View already added
             if (in_array(F0FInflector::pluralize($view), $t_views)) {
                 continue;
             }
             // Do we have a 'skip.xml' file in there?
             $files = $filesystem->folderFiles($searchPath . '/' . $view, '^skip\\.xml$');
             if (!empty($files)) {
                 continue;
             }
             // Do we have extra information about this view? (ie. ordering)
             $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\\.xml$');
             // Not found, do we have it inside the plural one?
             if (!$meta) {
                 $plural = F0FInflector::pluralize($view);
                 if (in_array($plural, $allFolders)) {
                     $view = $plural;
                     $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\\.xml$');
                 }
             }
             if (!empty($meta)) {
                 $using_meta = true;
                 $xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]);
                 $order = (int) $xml->foflib->ordering;
             } else {
                 // Next place. It's ok since the index are 0-based and count is 1-based
                 if (!isset($to_order)) {
                     $to_order = array();
                 }
                 $order = count($to_order);
             }
             $view = F0FInflector::pluralize($view);
             $t_view = new stdClass();
             $t_view->ordering = $order;
             $t_view->view = $view;
             $to_order[] = $t_view;
             $t_views[] = $view;
         }
     }
     F0FUtilsArray::sortObjects($to_order, 'ordering');
     $views = F0FUtilsArray::getColumn($to_order, 'view');
     // If not using the metadata file, let's put the cpanel view on top
     if (!$using_meta) {
         $cpanel = array_search('cpanels', $views);
         if ($cpanel !== false) {
             unset($views[$cpanel]);
             array_unshift($views, 'cpanels');
         }
     }
     return $views;
 }