7
« il: 25 Lug 2012, 15:49:38 »
Ciao a tutti!
sto testando il nuovo motore di ricerca Finder, gran balzo in avanti, non c'è che dire.
Adesso sto provando a far visualizzare il modulo di ricerca. Mi compare: il form di ricerca e il link a "ricerca avanzata". Fra le opzioni non c'è un campo che mi consenta di richiamare la funzione filtro che vedo invece comparire nel componente.
La cosa invece mi pare interessante e stavo cercando un modo per risolvere.
Non conosco il PHP, ma solo HTML/CSS, a lume di naso mi viene da pensare che basterà richiamare la funzione nel file del modulo "motore di ricerca", credo default.php nella cartella tmpl
o incollare la parte di codice nella giusta posizione prelevandola dal componente.
E qui viene il busillibus per un ignorante di php.
Qui c'è il codice di filter.php (dal componente finder), quale porzione mi interessa, ma soprattutto, è giusto il mio ragionamento?
Grazie a tutti e spero sia utile anche ad altri.
getQuery(true); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $html = ''; $in = ''; $filter = null; // Get the configuration options. $filterId = array_key_exists('filter_id', $options) ? $options['filter_id'] : null; $activeNodes = array_key_exists('selected_nodes', $options) ? $options['selected_nodes'] : array(); $activeDates = array_key_exists('selected_dates', $options) ? $options['selected_dates'] : array(); $classSuffix = array_key_exists('class_suffix', $options) ? $options['class_suffix'] : ''; $loadMedia = array_key_exists('load_media', $options) ? $options['load_media'] : true; $showDates = array_key_exists('show_date_filters', $options) ? $options['show_date_filters'] : false; // Load the predefined filter if specified. if (!empty($filterId)) { $query->select('f.' . $db->quoteName('data') . ', f.' . $db->quoteName('params')); $query->from($db->quoteName('#__finder_filters') . ' AS f'); $query->where($db->quoteName('f').'.' . $db->quoteName('filter_id') . ' = ' . (int) $filterId); // Load the filter data. $db->setQuery($query); $filter = $db->loadObject(); // Check for an error. if ($db->getErrorNum()) { return null; } // Initialize the filter parameters. if ($filter) { $registry = new JRegistry; $registry->loadString($filter->params); $filter->params = $registry; } } // Build the query to get the branch data and the number of child nodes. $query->clear(); $query->select('t.*, count(c.id) AS children'); $query->from($db->quoteName('#__finder_taxonomy') . ' AS t'); $query->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id'); $query->where($db->quoteName('t.parent_id') . ' = 1'); $query->where($db->quoteName('t.state') . ' = 1'); $query->where($db->quoteName('t.access') . ' IN (' . $groups . ')'); $query->where($db->quoteName('c.state') . ' = 1'); $query->where($db->quoteName('c.access') . ' IN (' . $groups . ')'); $query->group('t.id, t.parent_id, t.state, t.access, t.ordering, t.title, c.parent_id'); $query->order('t.ordering, t.title'); // Limit the branch children to a predefined filter. if ($filter) { $query->where('c.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($query); $branches = $db->loadObjectList('id'); // Check for an error. if ($db->getErrorNum()) { return null; } // Check that we have at least one branch. if (count($branches) === 0) { return null; } // Load the CSS/JS resources. if ($loadMedia) { JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false); JHtml::script('com_finder/sliderfilter.js', false, true); } // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); // Start the widget. $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL'); $html .= ''; $html .= ''; // Iterate through the branches to build the branch selector. foreach ($branches as $bk => $bv) { // If the multi-lang plug-in is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } $html .= ''; $html .= ''; $html .= ''; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= ''; $html .= ''; } $html .= ''; $html .= ''; // Iterate through the branches and build the branch groups. foreach ($branches as $bk => $bv) { // If the multi-lang plug-in 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(); $query->select('t.*'); $query->from($db->quoteName('#__finder_taxonomy') . ' AS t'); $query->where($db->quoteName('t.parent_id') . ' = ' . (int) $bk); $query->where($db->quoteName('t.state') . ' = 1'); $query->where($db->quoteName('t.access') . ' IN (' . $groups . ')'); $query->order('t.ordering, t.title'); // Load the branches. $db->setQuery($query); $nodes = $db->loadObjectList('id'); // Check for an error. if ($db->getErrorNum()) { return null; } // Translate node titles if possible. $lang = JFactory::getLanguage(); foreach ($nodes as $nk => $nv) { $key = FinderHelperLanguage::branchPlural($nv->title); if ($lang->hasKey($key)) { $nodes[$nk]->title = JText::_($key); } } // Start the group. $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= ''; $html .= ''; // Populate the group with nodes. foreach ($nodes as $nk => $nv) { // Determine if the node should be checked. $checked = in_array($nk, $activeNodes) ? ' checked="checked"' : ''; // Build a node. $html .= ''; $html .= ''; $html .= 'title) . '">'; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= ''; $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title)); $html .= ''; } // Close the widget. $html .= ''; // Load the CSS/JS resources. if ($loadMedia) { JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false); } return $html; } /** * Method to generate fields for filtering dates * * @param FinderIndexerQuery $query 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 dates($query, $options) { $html = ''; // Get the configuration options. $classSuffix = $options->get('class_suffix', null); $loadMedia = $options->get('load_media', true); $showDates = $options->get('show_date_filters', false); if (!empty($showDates)) { // Build the date operators options. $operators = array(); $operators[] = JHtml::_('select.option', 'before', JText::_('COM_FINDER_FILTER_DATE_BEFORE')); $operators[] = JHtml::_('select.option', 'exact', JText::_('COM_FINDER_FILTER_DATE_EXACTLY')); $operators[] = JHtml::_('select.option', 'after', JText::_('COM_FINDER_FILTER_DATE_AFTER')); // Load the CSS/JS resources. if ($loadMedia) { JHtml::stylesheet('com_finder/dates.css', false, true, false); } // Open the widget. $html .= ''; // Start date filter. $html .= ''; $html .= ''; $html .= JText::_('COM_FINDER_FILTER_DATE1'); $html .= ''; $html .= '
'; $html .= JHtml::_('select.genericlist', $operators, 'w1', 'class="inputbox filter-date-operator"', 'value', 'text', $query->when1, 'finder-filter-w1'); $html .= JHtml::calendar($query->date1, 'd1', 'filter_date1', '%Y-%m-%d', 'title="' . JText::_('COM_FINDER_FILTER_DATE1_DESC') . '"'); $html .= ''; // End date filter. $html .= ''; $html .= ''; $html .= JText::_('COM_FINDER_FILTER_DATE2'); $html .= ''; $html .= '
'; $html .= JHtml::_('select.genericlist', $operators, 'w2', 'class="inputbox filter-date-operator"', 'value', 'text', $query->when2, 'finder-filter-w2'); $html .= JHtml::calendar($query->date2, 'd2', 'filter_date2', '%Y-%m-%d', 'title="' . JText::_('COM_FINDER_FILTER_DATE2_DESC') . '"'); $html .= ''; // Close the widget. $html .= ''; } return $html; } }