/** * Method to get the list of content map options grouped by first level. * * @return array The field option objects as a nested array in groups. * * @since 3.6.0 */ protected function getGroups() { $groups = array(); // Get the database object and a new query object. $db = JFactory::getDbo(); // Levels subquery. $levelQuery = $db->getQuery(true); $levelQuery->select('title AS branch_title, 1 as level')->select($db->quoteName('id'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1'); $levelQuery2 = $db->getQuery(true); $levelQuery2->select('b.title AS branch_title, 2 as level')->select($db->quoteName('a.id'))->from($db->quoteName('#__finder_taxonomy', 'a'))->join('LEFT', $db->quoteName('#__finder_taxonomy', 'b') . ' ON ' . $db->qn('a.parent_id') . ' = ' . $db->qn('b.id'))->where($db->quoteName('a.parent_id') . ' NOT IN (0, 1)'); $levelQuery->union($levelQuery2); // Main query. $query = $db->getQuery(true)->select($db->quoteName('a.title', 'text'))->select($db->quoteName('a.id', 'value'))->select($db->quoteName('d.level'))->from($db->quoteName('#__finder_taxonomy', 'a'))->join('LEFT', '(' . $levelQuery . ') AS d ON ' . $db->qn('d.id') . ' = ' . $db->qn('a.id'))->where($db->quoteName('a.parent_id') . ' <> 0')->order('d.branch_title ASC, d.level ASC, a.title ASC'); $db->setQuery($query); try { $contentMap = $db->loadObjectList(); } catch (RuntimeException $e) { return; } // Build the grouped list array. if ($contentMap) { $lang = JFactory::getLanguage(); foreach ($contentMap as $branch) { if ((int) $branch->level === 1) { $name = $branch->text; } else { $levelPrefix = str_repeat('- ', max(0, $branch->level - 1)); if (trim($name, '**') == 'Language') { $text = FinderHelperLanguage::branchLanguageTitle($branch->text); } else { $key = FinderHelperLanguage::branchSingular($branch->text); $text = $lang->hasKey($key) ? JText::_($key) : $branch->text; } // Initialize the group if necessary. if (!isset($groups[$name])) { $groups[$name] = array(); } $groups[$name][] = JHtml::_('select.option', $branch->value, $levelPrefix . $text); } } } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
/** * Method to generate filters using select box dropdown controls. * * @param FinderIndexerQuery $idxQuery A FinderIndexerQuery object. * @param array $options An array of options. * * @return mixed A rendered HTML widget on success, null otherwise. * * @since 2.5 */ public static function select($idxQuery, $options) { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $filter = null; // Get the configuration options. $classSuffix = $options->get('class_suffix', null); $showDates = $options->get('show_date_filters', false); // Try to load the results from cache. $cache = JFactory::getCache('com_finder', ''); $cacheId = 'filter_select_' . serialize(array($idxQuery->filter, $options, $groups, JFactory::getLanguage()->getTag())); // Check the cached results. if (!($branches = $cache->get($cacheId))) { $db = JFactory::getDbo(); $query = $db->getQuery(true); // Load the predefined filter if specified. if (!empty($idxQuery->filter)) { $query->select('f.data, ' . $db->quoteName('f.params'))->from($db->quoteName('#__finder_filters') . ' AS f')->where('f.filter_id = ' . (int) $idxQuery->filter); // Load the filter data. $db->setQuery($query); try { $filter = $db->loadObject(); } catch (RuntimeException $e) { return null; } // Initialize the filter parameters. if ($filter) { $registry = new Registry(); $registry->loadString($filter->params); $filter->params = $registry; } } // Build the query to get the branch data and the number of child nodes. $query->clear()->select('t.*, count(c.id) AS children')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id')->where('t.parent_id = 1')->where('t.state = 1')->where('t.access IN (' . $groups . ')')->where('c.state = 1')->where('c.access IN (' . $groups . ')')->group($db->quoteName('t.id'))->order('t.ordering, t.title'); // Limit the branch children to a predefined filter. if (!empty($filter->data)) { $query->where('c.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($query); try { $branches = $db->loadObjectList('id'); } catch (RuntimeException $e) { return null; } // Check that we have at least one branch. if (count($branches) === 0) { return null; } // Iterate through the branches and build the branch groups. foreach ($branches as $bk => $bv) { // If the multi-lang plugin is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } // Build the query to get the child nodes for this branch. $query->clear()->select('t.*')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->where('t.parent_id = ' . (int) $bk)->where('t.state = 1')->where('t.access IN (' . $groups . ')')->order('t.ordering, t.title'); // Self-join to get the parent title. $query->select('e.title AS parent_title')->join('LEFT', $db->quoteName('#__finder_taxonomy', 'e') . ' ON ' . $db->quoteName('e.id') . ' = ' . $db->quoteName('t.parent_id')); // Limit the nodes to a predefined filter. if (!empty($filter->data)) { $query->where('t.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($query); try { $branches[$bk]->nodes = $db->loadObjectList('id'); } catch (RuntimeException $e) { return null; } // Translate branch nodes if possible. $language = JFactory::getLanguage(); foreach ($branches[$bk]->nodes as $node_id => $node) { if (trim($node->parent_title, '**') == 'Language') { $title = FinderHelperLanguage::branchLanguageTitle($node->title); } else { $key = FinderHelperLanguage::branchPlural($node->title); $title = $language->hasKey($key) ? JText::_($key) : $node->title; } $branches[$bk]->nodes[$node_id]->title = $title; } // Add the Search All option to the branch. array_unshift($branches[$bk]->nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL'))); } // Store the data in cache. $cache->store($branches, $cacheId); } $html = ''; // Add the dates if enabled. if ($showDates) { $html .= JHtml::_('filter.dates', $idxQuery, $options); } $html .= '<div class="filter-branch' . $classSuffix . ' control-group">'; // Iterate through all branches and build code. foreach ($branches as $bk => $bv) { // If the multi-lang plugin is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } $active = null; // Check if the branch is in the filter. if (array_key_exists($bv->title, $idxQuery->filters)) { // Get the request filters. $temp = JFactory::getApplication()->input->request->get('t', array(), 'array'); // Search for active nodes in the branch and get the active node. $active = array_intersect($temp, $idxQuery->filters[$bv->title]); $active = count($active) === 1 ? array_shift($active) : null; } // Build a node. $html .= '<div class="controls finder-selects">'; $html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '" class="control-label">'; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= '</label>'; $html .= '<br />'; $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox advancedSelect"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title)); $html .= '</div>'; } $html .= '</div>'; return $html; }
?> "> <td class="center"> <?php echo JHtml::_('grid.id', $i, $item->id); ?> </td> <td class="center nowrap"> <?php echo JHtml::_('jgrid.published', $item->state, $i, 'maps.', $canChange, 'cb'); ?> </td> <td> <?php if (trim($item->parent_title, '**') == 'Language') { $title = FinderHelperLanguage::branchLanguageTitle($item->title); } else { $key = FinderHelperLanguage::branchSingular($item->title); $title = $lang->hasKey($key) ? JText::_($key) : $item->title; } ?> <?php if ((int) $item->num_children === 0) { ?> <span class="gi">—</span> <?php } ?> <label for="cb<?php echo $i; ?>