Source for file searchtools.php

Documentation is available at searchtools.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Searchtools elements.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       3.2
  18.  */
  19. abstract class JHtmlSearchtools
  20. {
  21.     /**
  22.      * @var    array  Array containing information for loaded files
  23.      * @since  3.2
  24.      */
  25.     protected static $loaded array();
  26.  
  27.     /**
  28.      * Load the main Searchtools libraries
  29.      *
  30.      * @return  void 
  31.      *
  32.      * @since   3.2
  33.      */
  34.     public static function main()
  35.     {
  36.         // Only load once
  37.         if (empty(static::$loaded[__METHOD__]))
  38.         {
  39.             // Requires jQuery but allows to skip its loading
  40.             if ($loadJquery (!isset($options['loadJquery']|| $options['loadJquery'!= 0))
  41.             {
  42.                 JHtml::_('jquery.framework');
  43.             }
  44.  
  45.             // Load the jQuery plugin && CSS
  46.             JHtml::_('script''jui/jquery.searchtools.min.js'falsetrue);
  47.             JHtml::_('stylesheet''jui/jquery.searchtools.css'falsetrue);
  48.  
  49.             static::$loaded[__METHOD__true;
  50.         }
  51.  
  52.         return;
  53.     }
  54.  
  55.     /**
  56.      * Load searchtools for a specific form
  57.      *
  58.      * @param   mixed  $selector  Is debugging mode on? [optional]
  59.      * @param   array  $options   Optional array of parameters for search tools
  60.      *
  61.      * @return  void 
  62.      *
  63.      * @since   3.2
  64.      */
  65.     public static function form($selector '.js-stools-form'$options array())
  66.     {
  67.         $sig md5(serialize(array($selector$options)));
  68.  
  69.         // Only load once
  70.         if (!isset(static::$loaded[__METHOD__][$sig]))
  71.         {
  72.             // Include Bootstrap framework
  73.             static::main();
  74.  
  75.             // Add the form selector to the search tools options
  76.             $options['formSelector'$selector;
  77.  
  78.             // Generate options with default values
  79.             $options static::options2Jregistry($options);
  80.  
  81.             $doc JFactory::getDocument();
  82.             $script "
  83.                 (function($){
  84.                     $(document).ready(function() {
  85.                         $('" $selector "').searchtools(
  86.                             " $options->toString("
  87.                         );
  88.                     });
  89.                 })(jQuery);
  90.             ";
  91.             $doc->addScriptDeclaration($script);
  92.  
  93.             static::$loaded[__METHOD__][$sigtrue;
  94.         }
  95.  
  96.         return;
  97.     }
  98.  
  99.     /**
  100.      * Function to receive & pre-process javascript options
  101.      *
  102.      * @param   mixed  $options  Associative array/JRegistry object with options
  103.      *
  104.      * @return  JRegistry        Options converted to JRegistry object
  105.      */
  106.     private static function options2Jregistry($options)
  107.     {
  108.         // Support options array
  109.         if (is_array($options))
  110.         {
  111.             $options new JRegistry($options);
  112.         }
  113.  
  114.         if (!($options instanceof Jregistry))
  115.         {
  116.             $options new JRegistry;
  117.         }
  118.  
  119.         return $options;
  120.     }
  121.  
  122.     /**
  123.      * Method to sort a column in a grid
  124.      *
  125.      * @param   string  $title          The link title
  126.      * @param   string  $order          The order field for the column
  127.      * @param   string  $direction      The current direction
  128.      * @param   mixed   $selected       The selected ordering
  129.      * @param   string  $task           An optional task override
  130.      * @param   string  $new_direction  An optional direction for the new column
  131.      * @param   string  $tip            An optional text shown as tooltip title instead of $title
  132.      * @param   string  $icon           Icon to show
  133.      * @param   string  $formName       Name of the form to submit
  134.      *
  135.      * @return  string 
  136.      */
  137.     public static function sort($title$order$direction 'asc'$selected 0$task null$new_direction 'asc'$tip ''$icon null$formName 'adminForm')
  138.     {
  139.         $direction strtolower($direction);
  140.         $orderIcons array('icon-arrow-up-3''icon-arrow-down-3');
  141.         $index = (int) ($direction == 'desc');
  142.  
  143.         if ($order != $selected)
  144.         {
  145.             $direction $new_direction;
  146.         }
  147.         else
  148.         {
  149.             $direction ($direction == 'desc''asc' 'desc';
  150.         }
  151.  
  152.         // Create an object to pass it to the layouts
  153.         $data            new stdClass;
  154.         $data->order     $order;
  155.         $data->direction $direction;
  156.         $data->selected  $selected;
  157.         $data->task      $task;
  158.         $data->tip       $tip;
  159.         $data->title     $title;
  160.         $data->orderIcon $orderIcons[$index];
  161.         $data->icon      $icon;
  162.         $data->formName  $formName;
  163.  
  164.         return JLayoutHelper::render('joomla.searchtools.grid.sort'$data);
  165.     }
  166. }

Documentation generated on Tue, 19 Nov 2013 15:12:47 +0100 by phpDocumentor 1.4.3