[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_finder/helpers/html/ -> filter.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Site
   4   * @subpackage  com_finder
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('_JEXEC') or die;
  11  
  12  JLoader::register('FinderHelperLanguage', JPATH_ADMINISTRATOR . '/components/com_finder/helpers/language.php');
  13  
  14  /**
  15   * Filter HTML Behaviors for Finder.
  16   *
  17   * @package     Joomla.Site
  18   * @subpackage  com_finder
  19   * @since       2.5
  20   */
  21  abstract class JHtmlFilter
  22  {
  23      /**
  24       * Method to generate filters using the slider widget and decorated
  25       * with the FinderFilter JavaScript behaviors.
  26       *
  27       * @param   array  $options  An array of configuration options. [optional]
  28       *
  29       * @return  mixed  A rendered HTML widget on success, null otherwise.
  30       *
  31       * @since   2.5
  32       */
  33  	public static function slider($options = array())
  34      {
  35          $db = JFactory::getDBO();
  36          $query = $db->getQuery(true);
  37          $user = JFactory::getUser();
  38          $groups = implode(',', $user->getAuthorisedViewLevels());
  39          $html = '';
  40          $in = '';
  41          $filter = null;
  42  
  43          // Get the configuration options.
  44          $filterId = array_key_exists('filter_id', $options) ? $options['filter_id'] : null;
  45          $activeNodes = array_key_exists('selected_nodes', $options) ? $options['selected_nodes'] : array();
  46          $activeDates = array_key_exists('selected_dates', $options) ? $options['selected_dates'] : array();
  47          $classSuffix = array_key_exists('class_suffix', $options) ? $options['class_suffix'] : '';
  48          $loadMedia = array_key_exists('load_media', $options) ? $options['load_media'] : true;
  49          $showDates = array_key_exists('show_date_filters', $options) ? $options['show_date_filters'] : false;
  50  
  51          // Load the predefined filter if specified.
  52          if (!empty($filterId))
  53          {
  54              $query->select('f.' . $db->quoteName('data') . ', f.' . $db->quoteName('params'));
  55              $query->from($db->quoteName('#__finder_filters') . ' AS f');
  56              $query->where($db->quoteName('f').'.' . $db->quoteName('filter_id') . ' = ' . (int) $filterId);
  57  
  58              // Load the filter data.
  59              $db->setQuery($query);
  60              $filter = $db->loadObject();
  61  
  62              // Check for an error.
  63              if ($db->getErrorNum())
  64              {
  65                  return null;
  66              }
  67  
  68              // Initialize the filter parameters.
  69              if ($filter)
  70              {
  71                  $registry = new JRegistry;
  72                  $registry->loadString($filter->params);
  73                  $filter->params = $registry;
  74              }
  75          }
  76  
  77          // Build the query to get the branch data and the number of child nodes.
  78          $query->clear();
  79          $query->select('t.*, count(c.id) AS children');
  80          $query->from($db->quoteName('#__finder_taxonomy') . ' AS t');
  81          $query->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id');
  82          $query->where($db->quoteName('t.parent_id') . ' = 1');
  83          $query->where($db->quoteName('t.state') . ' = 1');
  84          $query->where($db->quoteName('t.access') . ' IN (' . $groups . ')');
  85          $query->where($db->quoteName('c.state') . ' = 1');
  86          $query->where($db->quoteName('c.access') . ' IN (' . $groups . ')');
  87          $query->group('t.id, t.parent_id, t.state, t.access, t.ordering, t.title, c.parent_id');
  88          $query->order('t.ordering, t.title');
  89  
  90          // Limit the branch children to a predefined filter.
  91          if ($filter)
  92          {
  93              $query->where('c.id IN(' . $filter->data . ')');
  94          }
  95  
  96          // Load the branches.
  97          $db->setQuery($query);
  98          $branches = $db->loadObjectList('id');
  99  
 100          // Check for an error.
 101          if ($db->getErrorNum())
 102          {
 103              return null;
 104          }
 105  
 106          // Check that we have at least one branch.
 107          if (count($branches) === 0)
 108          {
 109              return null;
 110          }
 111  
 112          // Load the CSS/JS resources.
 113          if ($loadMedia)
 114          {
 115              JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
 116              JHtml::script('com_finder/sliderfilter.js', false, true);
 117          }
 118  
 119          // Load plug-in language files.
 120          FinderHelperLanguage::loadPluginLanguage();
 121  
 122          // Start the widget.
 123          $html .= '<div id="finder-filter-container">';
 124          $html .= '<dl id="branch-selectors">';
 125          $html .= '<dt>';
 126          $html .= '<label for="tax-select-all">';
 127          $html .= '<input type="checkbox" id="tax-select-all" />';
 128          $html .= JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL');
 129          $html .= '</label>';
 130          $html .= '</dt>';
 131  
 132          // Iterate through the branches to build the branch selector.
 133          foreach ($branches as $bk => $bv)
 134          {
 135              // If the multi-lang plug-in is enabled then drop the language branch.
 136              if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) {
 137                  continue;
 138              }
 139  
 140              $html .= '<dd>';
 141              $html .= '<label for="tax-' . $bk . '">';
 142              $html .= '<input type="checkbox" class="toggler" id="tax-' . $bk . '"/>';
 143              $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title)));
 144              $html .= '</label>';
 145              $html .= '</dd>';
 146          }
 147  
 148          $html .= '</dl>';
 149          $html .= '<div id="finder-filter-container">';
 150  
 151          // Iterate through the branches and build the branch groups.
 152          foreach ($branches as $bk => $bv)
 153          {
 154              // If the multi-lang plug-in is enabled then drop the language branch.
 155              if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) {
 156                  continue;
 157              }
 158  
 159              // Build the query to get the child nodes for this branch.
 160              $query->clear();
 161              $query->select('t.*');
 162              $query->from($db->quoteName('#__finder_taxonomy') . ' AS t');
 163              $query->where($db->quoteName('t.parent_id') . ' = ' . (int) $bk);
 164              $query->where($db->quoteName('t.state') . ' = 1');
 165              $query->where($db->quoteName('t.access') . ' IN (' . $groups . ')');
 166              $query->order('t.ordering, t.title');
 167  
 168              // Load the branches.
 169              $db->setQuery($query);
 170              $nodes = $db->loadObjectList('id');
 171  
 172              // Check for an error.
 173              if ($db->getErrorNum())
 174              {
 175                  return null;
 176              }
 177  
 178              // Translate node titles if possible.
 179              $lang = JFactory::getLanguage();
 180              foreach ($nodes as $nk => $nv) {
 181                  $key = FinderHelperLanguage::branchPlural($nv->title);
 182                  if ($lang->hasKey($key)) {
 183                      $nodes[$nk]->title = JText::_($key);
 184                  }
 185              }
 186  
 187              // Start the group.
 188              $html .= '<dl class="checklist" rel="tax-' . $bk . '">';
 189              $html .= '<dt>';
 190              $html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '">';
 191              $html .= '<input type="checkbox" class="branch-selector filter-branch' . $classSuffix . '" id="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '" />';
 192              $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title)));
 193              $html .= '</label>';
 194              $html .= '</dt>';
 195  
 196              // Populate the group with nodes.
 197              foreach ($nodes as $nk => $nv)
 198              {
 199                  // Determine if the node should be checked.
 200                  $checked = in_array($nk, $activeNodes) ? ' checked="checked"' : '';
 201  
 202                  // Build a node.
 203                  $html .= '<dd>';
 204                  $html .= '<label for="tax-' . $nk . '">';
 205                  $html .= '<input class="selector filter-node' . $classSuffix . '" type="checkbox" value="' . $nk . '" name="t[]" id="tax-' . $nk . '"' . $checked . ' />';
 206                  $html .= $nv->title;
 207                  $html .= '</label>';
 208                  $html .= '</dd>';
 209              }
 210  
 211              // Close the group.
 212              $html .= '</dl>';
 213          }
 214  
 215          // Close the widget.
 216          $html .= '<div class="clr"></div>';
 217          $html .= '</div>';
 218          $html .= '</div>';
 219  
 220          return $html;
 221      }
 222  
 223      /**
 224       * Method to generate filters using select box drop down controls.
 225       *
 226       * @param   FinderIndexerQuery  $query    A FinderIndexerQuery object.
 227       * @param   array               $options  An array of options.
 228       *
 229       * @return  mixed  A rendered HTML widget on success, null otherwise.
 230       *
 231       * @since   2.5
 232       */
 233  	public static function select($query, $options)
 234      {
 235          $user     = JFactory::getUser();
 236          $groups = implode(',', $user->getAuthorisedViewLevels());
 237          $filter = null;
 238  
 239          // Get the configuration options.
 240          $classSuffix = $options->get('class_suffix', null);
 241          $loadMedia = $options->get('load_media', true);
 242          $showDates = $options->get('show_date_filters', false);
 243  
 244          // Try to load the results from cache.
 245          $cache = JFactory::getCache('com_finder', '');
 246          $cacheId = 'filter_select_' . serialize(array($query->filter, $options, $groups, JFactory::getLanguage()->getTag()));
 247  
 248          // Check the cached results.
 249          if (!($branches = $cache->get($cacheId)))
 250          {
 251              $db = JFactory::getDBO();
 252              $sql = $db->getQuery(true);
 253  
 254              // Load the predefined filter if specified.
 255              if (!empty($query->filter))
 256              {
 257                  $sql->select($db->quoteName('f') . '.' . $db->quoteName('data') . ', '. $db->quoteName('f') . '.' . $db->quoteName('params'));
 258                  $sql->from($db->quoteName('#__finder_filters') . ' AS f');
 259                  $sql->where($db->quoteName('f') . '.' . $db->quoteName('filter_id') . ' = ' . (int) $query->filter);
 260  
 261                  // Load the filter data.
 262                  $db->setQuery($sql);
 263                  $filter = $db->loadObject();
 264  
 265                  // Check for an error.
 266                  if ($db->getErrorNum())
 267                  {
 268                      return null;
 269                  }
 270  
 271                  // Initialize the filter parameters.
 272                  if ($filter)
 273                  {
 274                      $registry = new JRegistry;
 275                      $registry->loadString($filter->params);
 276                      $filter->params = $registry;
 277                  }
 278              }
 279  
 280              // Build the query to get the branch data and the number of child nodes.
 281              $sql->clear();
 282              $sql->select('t.*, count(c.id) AS children');
 283              $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
 284              $sql->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id');
 285              $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = 1');
 286              $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
 287              $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
 288              $sql->where($db->quoteName('c') . '.' . $db->quoteName('state') . ' = 1');
 289              $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
 290              $sql->group($db->quoteName('t') . '.' . $db->quoteName('id'));
 291              $sql->order('t.ordering, t.title');
 292  
 293              // Limit the branch children to a predefined filter.
 294              if (!empty($filter->data))
 295              {
 296                  $sql->where('c.id IN(' . $filter->data . ')');
 297              }
 298  
 299              // Load the branches.
 300              $db->setQuery($sql);
 301              $branches = $db->loadObjectList('id');
 302  
 303              // Check for an error.
 304              if ($db->getErrorNum())
 305              {
 306                  return null;
 307              }
 308  
 309              // Check that we have at least one branch.
 310              if (count($branches) === 0)
 311              {
 312                  return null;
 313              }
 314  
 315  
 316              // Iterate through the branches and build the branch groups.
 317              foreach ($branches as $bk => $bv)
 318              {
 319                  // If the multi-lang plug-in is enabled then drop the language branch.
 320                  if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) {
 321                      continue;
 322                  }
 323  
 324                  // Build the query to get the child nodes for this branch.
 325                  $sql->clear();
 326                  $sql->select('t.*');
 327                  $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t');
 328                  $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = ' . (int) $bk);
 329                  $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1');
 330                  $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')');
 331                  $sql->order('t.ordering, t.title');
 332  
 333                  // Limit the nodes to a predefined filter.
 334                  if (!empty($filter->data))
 335                  {
 336                      $sql->where('t.id IN(' . $filter->data . ')');
 337                  }
 338  
 339                  // Load the branches.
 340                  $db->setQuery($sql);
 341                  $branches[$bk]->nodes = $db->loadObjectList('id');
 342  
 343                  // Check for an error.
 344                  if ($db->getErrorNum())
 345                  {
 346                      return null;
 347                  }
 348  
 349                  // Translate branch nodes if possible.
 350                  $language = JFactory::getLanguage();
 351                  foreach($branches[$bk]->nodes as $node_id => $node) {
 352                      $key = FinderHelperLanguage::branchPlural($node->title);
 353                      if ($language->hasKey($key)) {
 354                          $branches[$bk]->nodes[$node_id]->title = JText::_($key);
 355                      }
 356                  }
 357  
 358                  // Add the Search All option to the branch.
 359                  array_unshift($branches[$bk]->nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL')));
 360              }
 361  
 362              // Store the data in cache.
 363              $cache->store($branches, $cacheId);
 364          }
 365  
 366          $html = '';
 367  
 368          // Add the dates if enabled.
 369          if ($showDates)
 370          {
 371              $html .= JHtml::_('filter.dates', $query, $options);
 372          }
 373  
 374          $html .= '<ul id="finder-filter-select-list">';
 375  
 376          // Iterate through all branches and build code.
 377          foreach ($branches as $bk => $bv)
 378          {
 379              // If the multi-lang plug-in is enabled then drop the language branch.
 380              if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) {
 381                  continue;
 382              }
 383  
 384              $active = null;
 385  
 386              // Check if the branch is in the filter.
 387              if (array_key_exists($bv->title, $query->filters))
 388              {
 389                  // Get the request filters.
 390                  $temp = JFactory::getApplication()->input->request->get('t', array(), 'array');
 391  
 392                  // Search for active nodes in the branch and get the active node.
 393                  $active = array_intersect($temp, $query->filters[$bv->title]);
 394                  $active = count($active) === 1 ? array_shift($active) : null;
 395              }
 396  
 397              $html .= '<li class="filter-branch' . $classSuffix . '">';
 398              $html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '">';
 399              $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title)));
 400              $html .= '</label>';
 401              $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title));
 402              $html .= '</li>';
 403          }
 404  
 405          // Close the widget.
 406          $html .= '</ul>';
 407  
 408          // Load the CSS/JS resources.
 409          if ($loadMedia)
 410          {
 411              JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false);
 412          }
 413  
 414          return $html;
 415      }
 416  
 417      /**
 418       * Method to generate fields for filtering dates
 419       *
 420       * @param   FinderIndexerQuery  $query    A FinderIndexerQuery object.
 421       * @param   array               $options  An array of options.
 422       *
 423       * @return  mixed  A rendered HTML widget on success, null otherwise.
 424       *
 425       * @since   2.5
 426       */
 427  	public static function dates($query, $options)
 428      {
 429          $html = '';
 430  
 431          // Get the configuration options.
 432          $classSuffix = $options->get('class_suffix', null);
 433          $loadMedia = $options->get('load_media', true);
 434          $showDates = $options->get('show_date_filters', false);
 435  
 436          if (!empty($showDates))
 437          {
 438              // Build the date operators options.
 439              $operators = array();
 440              $operators[] = JHtml::_('select.option', 'before', JText::_('COM_FINDER_FILTER_DATE_BEFORE'));
 441              $operators[] = JHtml::_('select.option', 'exact', JText::_('COM_FINDER_FILTER_DATE_EXACTLY'));
 442              $operators[] = JHtml::_('select.option', 'after', JText::_('COM_FINDER_FILTER_DATE_AFTER'));
 443  
 444              // Load the CSS/JS resources.
 445              if ($loadMedia)
 446              {
 447                  JHtml::stylesheet('com_finder/dates.css', false, true, false);
 448              }
 449  
 450              // Open the widget.
 451              $html .= '<ul id="finder-filter-select-dates">';
 452  
 453              // Start date filter.
 454              $html .= '<li class="filter-date' . $classSuffix . '">';
 455              $html .= '<label for="filter_date1">';
 456              $html .= JText::_('COM_FINDER_FILTER_DATE1');
 457              $html .= '</label>';
 458              $html .= '<br />';
 459              $html .= JHtml::_('select.genericlist', $operators, 'w1', 'class="inputbox filter-date-operator"', 'value', 'text', $query->when1, 'finder-filter-w1');
 460              $html .= JHtml::calendar($query->date1, 'd1', 'filter_date1', '%Y-%m-%d', 'title="' . JText::_('COM_FINDER_FILTER_DATE1_DESC') . '"');
 461              $html .= '</li>';
 462  
 463              // End date filter.
 464              $html .= '<li class="filter-date' . $classSuffix . '">';
 465              $html .= '<label for="filter_date2">';
 466              $html .= JText::_('COM_FINDER_FILTER_DATE2');
 467              $html .= '</label>';
 468              $html .= '<br />';
 469              $html .= JHtml::_('select.genericlist', $operators, 'w2', 'class="inputbox filter-date-operator"', 'value', 'text', $query->when2, 'finder-filter-w2');
 470              $html .= JHtml::calendar($query->date2, 'd2', 'filter_date2', '%Y-%m-%d', 'title="' . JText::_('COM_FINDER_FILTER_DATE2_DESC') . '"');
 471              $html .= '</li>';
 472  
 473              // Close the widget.
 474              $html .= '</ul>';
 475          }
 476  
 477          return $html;
 478      }
 479  }
element ', [['libraries/joomla/html','html.php',587],['libraries/joomla','methods.php',359]], 46], 'store': ['store', 'Store the data to WINCACHE by id and group ', [['libraries/joomla/cache/storage','wincache.php',99],['components/com_finder/models','search.php',1269],['administrator/components/com_newsfeeds/tables','newsfeed.php',104],['libraries/joomla/cache/storage','xcache.php',92],['libraries/joomla/cache/storage','apc.php',84],['libraries/joomla/cache','controller.php',200],['libraries/joomla/database','tablenested.php',712],['administrator/components/com_redirect/tables','link.php',78],['libraries/joomla/database/table','usergroup.php',119],['libraries/joomla/database/table','menu.php',133],['libraries/joomla/database/table','content.php',231],['libraries/joomla/database/table','language.php',53],['libraries/joomla/client','ftp.php',966],['libraries/joomla/cache','cache.php',207],['libraries/joomla/database/table','category.php',192],['administrator/components/com_finder/tables','filter.php',184],['libraries/joomla/cache','storage.php',180],['libraries/joomla/database','table.php',576],['administrator/components/com_templates/tables','style.php',67],['administrator/components/com_banners/tables','banner.php',117],['administrator/components/com_weblinks/tables','weblink.php',54],['libraries/joomla/database/table','menutype.php',75],['administrator/components/com_contact/tables','contact.php',54],['libraries/joomla/cache/storage','file.php',112],['libraries/joomla/database/table','user.php',267],['libraries/joomla/cache/storage','cachelite.php',135],['libraries/joomla/cache/storage','memcache.php',168],['libraries/joomla/cache/controller','page.php',113],['libraries/joomla/cache/storage','eaccelerator.php',101],['administrator/components/com_users/tables','note.php',33]], 211], 'register': ['register', 'Method to save the form data. ', [['components/com_users/models','registration.php',289],['libraries/joomla/session','storage.php',79],['components/com_users/controllers','user.php',100],['libraries/joomla/session/storage','none.php',22],['libraries','loader.php',198],['media/editors/codemirror/js','parsejavascript.js',182],['libraries/joomla/html','html.php',144],['libraries/joomla/event','dispatcher.php',88],['components/com_users/controllers','registration.php',91]], 108], 'setquery': ['setquery', 'Sets the SQL statement string for later execution. ', [['libraries/joomla/database','database.php',1463],['libraries/joomla/environment','uri.php',470]], 592], 'getapplication': ['getapplication', 'Get a application object. ', [['libraries/joomla','factory.php',79]], 529], 'loadstring': ['loadstring', 'Load a string into the registry ', [['libraries/joomla/registry','registry.php',263],['libraries/joomla/utilities','simplexml.php',141]], 83], 'count': ['count', '', [], 795], 'in_array': ['in_array', '', [], 276], 'array_shift': ['array_shift', '', [], 48], 'implode': ['implode', '', [], 429], 'array_unshift': ['array_unshift', '', [], 43], 'array_key_exists': ['array_key_exists', '', [], 202], 'array_intersect': ['array_intersect', '', [], 8], 'defined': ['defined', '', [], 1514], 'serialize': ['serialize', '', [], 88]}; CLASS_DATA={ 'finderhelperlanguage': ['finderhelperlanguage', 'Finder language helper class. ', [['administrator/components/com_finder/helpers','language.php',12]], 24], 'jfilteroutput': ['jfilteroutput', 'JFilterOutput ', [['libraries/joomla/filter','output.php',12]], 11], 'jlanguagemultilang': ['jlanguagemultilang', 'Utitlity class for multilang ', [['libraries/cms/language','multilang.php',12]], 13], 'jtext': ['jtext', 'Text handling class. ', [['libraries/joomla','methods.php',97]], 5132], 'jregistry': ['jregistry', 'JRegistry class ', [['libraries/joomla/registry','registry.php',15]], 158]}; CONST_DATA={ 'JPATH_ADMINISTRATOR': ['JPATH_ADMINISTRATOR', '', [['includes','defines.php',25],['installation','index.php',35],['administrator/includes','defines.php',21]], 180], '_JEXEC': ['_JEXEC', '', [['','index.php',9],['administrator','index.php',9],['cli','update_cron.php',19],['cli','garbagecron.php',13],['installation','index.php',16],['cli','finder_indexer.php',20]], 1070]};


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1