Source for file jgrid.php

Documentation is available at jgrid.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.  * Utility class for creating HTML Grids
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.6
  18.  */
  19. abstract class JHtmlJGrid
  20. {
  21.     /**
  22.      * Returns an action on a grid
  23.      *
  24.      * @param   integer       $i               The row index
  25.      * @param   string        $task            The task to fire
  26.      * @param   string|array $prefix          An optional task prefix or an array of options
  27.      * @param   string        $text            An optional text to display [unused - @deprecated 4.0]
  28.      * @param   string        $active_title    An optional active tooltip to display if $enable is true
  29.      * @param   string        $inactive_title  An optional inactive tooltip to display if $enable is true
  30.      * @param   boolean       $tip             An optional setting for tooltip
  31.      * @param   string        $active_class    An optional active HTML class
  32.      * @param   string        $inactive_class  An optional inactive HTML class
  33.      * @param   boolean       $enabled         An optional setting for access control on the action.
  34.      * @param   boolean       $translate       An optional setting for translation.
  35.      * @param   string        $checkbox           An optional prefix for checkboxes.
  36.      *
  37.      * @return  string  The HTML markup
  38.      *
  39.      * @since   1.6
  40.      */
  41.     public static function action($i$task$prefix ''$text ''$active_title ''$inactive_title ''$tip false$active_class '',
  42.         $inactive_class ''$enabled true$translate true$checkbox 'cb')
  43.     {
  44.         if (is_array($prefix))
  45.         {
  46.             $options $prefix;
  47.             $active_title array_key_exists('active_title'$options$options['active_title'$active_title;
  48.             $inactive_title array_key_exists('inactive_title'$options$options['inactive_title'$inactive_title;
  49.             $tip array_key_exists('tip'$options$options['tip'$tip;
  50.             $active_class array_key_exists('active_class'$options$options['active_class'$active_class;
  51.             $inactive_class array_key_exists('inactive_class'$options$options['inactive_class'$inactive_class;
  52.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  53.             $translate array_key_exists('translate'$options$options['translate'$translate;
  54.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  55.             $prefix array_key_exists('prefix'$options$options['prefix''';
  56.         }
  57.  
  58.         if ($tip)
  59.         {
  60.             JHtml::_('bootstrap.tooltip');
  61.  
  62.             $title $enabled $active_title $inactive_title;
  63.             $title $translate JText::_($title$title;
  64.             $title JHtml::tooltipText($title''0);
  65.         }
  66.  
  67.         if ($enabled)
  68.         {
  69.             $html['<a class="btn btn-micro ' ($active_class == "publish" 'active' ''' ' ($tip 'hasTooltip"' '''"';
  70.             $html[' href="javascript:void(0);" onclick="return listItemTask(\'' $checkbox $i '\',\'' $prefix $task '\')"';
  71.             $html[$tip ' title="' $title '"' '';
  72.             $html['>';
  73.             $html['<i class="icon-' $active_class '">';
  74.             $html['</i>';
  75.             $html['</a>';
  76.         }
  77.         else
  78.         {
  79.             $html['<a class="btn btn-micro disabled jgrid ' ($tip 'hasTooltip' '''"';
  80.             $html[$tip ' title="' $title '"' '';
  81.             $html['>';
  82.  
  83.             if ($active_class == "protected")
  84.             {
  85.                 $html['<i class="icon-lock"></i>';
  86.             }
  87.             else
  88.             {
  89.                 $html['<i class="icon-' $inactive_class '"></i>';
  90.             }
  91.  
  92.             $html['</a>';
  93.         }
  94.  
  95.         return implode($html);
  96.     }
  97.  
  98.     /**
  99.      * Returns a state on a grid
  100.      *
  101.      * @param   array         $states     array of value/state. Each state is an array of the form
  102.      *                                     (task, text, title,html active class, HTML inactive class)
  103.      *                                     or ('task'=>task, 'text'=>text, 'active_title'=>active title,
  104.      *                                     'inactive_title'=>inactive title, 'tip'=>boolean, 'active_class'=>html active class,
  105.      *                                     'inactive_class'=>html inactive class)
  106.      * @param   integer       $value      The state value.
  107.      * @param   integer       $i          The row index
  108.      * @param   string|array $prefix     An optional task prefix or an array of options
  109.      * @param   boolean       $enabled    An optional setting for access control on the action.
  110.      * @param   boolean       $translate  An optional setting for translation.
  111.      * @param   string        $checkbox   An optional prefix for checkboxes.
  112.      *
  113.      * @return  string  The HTML markup
  114.      *
  115.      * @since   1.6
  116.      */
  117.     public static function state($states$value$i$prefix ''$enabled true$translate true$checkbox 'cb')
  118.     {
  119.         if (is_array($prefix))
  120.         {
  121.             $options $prefix;
  122.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  123.             $translate array_key_exists('translate'$options$options['translate'$translate;
  124.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  125.             $prefix array_key_exists('prefix'$options$options['prefix''';
  126.         }
  127.         $state JArrayHelper::getValue($states(int) $value$states[0]);
  128.         $task array_key_exists('task'$state$state['task'$state[0];
  129.         $text array_key_exists('text'$state$state['text'(array_key_exists(1$state$state[1'');
  130.         $active_title array_key_exists('active_title'$state$state['active_title'(array_key_exists(2$state$state[2'');
  131.         $inactive_title array_key_exists('inactive_title'$state$state['inactive_title'(array_key_exists(3$state$state[3'');
  132.         $tip array_key_exists('tip'$state$state['tip'(array_key_exists(4$state$state[4false);
  133.         $active_class array_key_exists('active_class'$state$state['active_class'(array_key_exists(5$state$state[5'');
  134.         $inactive_class array_key_exists('inactive_class'$state$state['inactive_class'(array_key_exists(6$state$state[6'');
  135.  
  136.         return static::action(
  137.             $i$task$prefix$text$active_title$inactive_title$tip,
  138.             $active_class$inactive_class$enabled$translate$checkbox
  139.         );
  140.     }
  141.  
  142.     /**
  143.      * Returns a published state on a grid
  144.      *
  145.      * @param   integer       $value         The state value.
  146.      * @param   integer       $i             The row index
  147.      * @param   string|array $prefix        An optional task prefix or an array of options
  148.      * @param   boolean       $enabled       An optional setting for access control on the action.
  149.      * @param   string        $checkbox      An optional prefix for checkboxes.
  150.      * @param   string        $publish_up    An optional start publishing date.
  151.      * @param   string        $publish_down  An optional finish publishing date.
  152.      *
  153.      * @return  string  The HTML markup
  154.      *
  155.      * @see     JHtmlJGrid::state()
  156.      * @since   1.6
  157.      */
  158.     public static function published($value$i$prefix ''$enabled true$checkbox 'cb'$publish_up null$publish_down null)
  159.     {
  160.         if (is_array($prefix))
  161.         {
  162.             $options $prefix;
  163.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  164.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  165.             $prefix array_key_exists('prefix'$options$options['prefix''';
  166.         }
  167.  
  168.         $states array(=> array('unpublish''JPUBLISHED''JLIB_HTML_UNPUBLISH_ITEM''JPUBLISHED'true'publish''publish'),
  169.             => array('publish''JUNPUBLISHED''JLIB_HTML_PUBLISH_ITEM''JUNPUBLISHED'true'unpublish''unpublish'),
  170.             => array('unpublish''JARCHIVED''JLIB_HTML_UNPUBLISH_ITEM''JARCHIVED'true'archive''archive'),
  171.             -=> array('publish''JTRASHED''JLIB_HTML_PUBLISH_ITEM''JTRASHED'true'trash''trash'));
  172.  
  173.         // Special state for dates
  174.         if ($publish_up || $publish_down)
  175.         {
  176.             $nullDate JFactory::getDbo()->getNullDate();
  177.             $nowDate JFactory::getDate()->toUnix();
  178.  
  179.             $tz new DateTimeZone(JFactory::getUser()->getParam('timezone'JFactory::getConfig()->get('offset')));
  180.  
  181.             $publish_up ($publish_up != $nullDateJFactory::getDate($publish_up'UTC')->setTimeZone($tzfalse;
  182.             $publish_down ($publish_down != $nullDateJFactory::getDate($publish_down'UTC')->setTimeZone($tzfalse;
  183.  
  184.             // Create tip text, only we have publish up or down settings
  185.             $tips array();
  186.  
  187.             if ($publish_up)
  188.             {
  189.                 $tips[JText::sprintf('JLIB_HTML_PUBLISHED_START'$publish_up->format(JDate::$formattrue));
  190.             }
  191.  
  192.             if ($publish_down)
  193.             {
  194.                 $tips[JText::sprintf('JLIB_HTML_PUBLISHED_FINISHED'$publish_down->format(JDate::$formattrue));
  195.             }
  196.  
  197.             $tip empty($tipsfalse implode('<br/>'$tips);
  198.  
  199.             // Add tips and special titles
  200.             foreach ($states as $key => $state)
  201.             {
  202.                 // Create special titles for published items
  203.                 if ($key == 1)
  204.                 {
  205.                     $states[$key][2$states[$key][3'JLIB_HTML_PUBLISHED_ITEM';
  206.  
  207.                     if ($publish_up $nullDate && $nowDate $publish_up->toUnix())
  208.                     {
  209.                         $states[$key][2$states[$key][3'JLIB_HTML_PUBLISHED_PENDING_ITEM';
  210.                         $states[$key][5$states[$key][6'pending';
  211.                     }
  212.  
  213.                     if ($publish_down $nullDate && $nowDate $publish_down->toUnix())
  214.                     {
  215.                         $states[$key][2$states[$key][3'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
  216.                         $states[$key][5$states[$key][6'expired';
  217.                     }
  218.                 }
  219.  
  220.                 // Add tips to titles
  221.                 if ($tip)
  222.                 {
  223.                     $states[$key][1JText::_($states[$key][1]);
  224.                     $states[$key][2JText::_($states[$key][2]'<br />' $tip;
  225.                     $states[$key][3JText::_($states[$key][3]'<br />' $tip;
  226.                     $states[$key][4true;
  227.                 }
  228.             }
  229.  
  230.             return static::state($states$value$iarray('prefix' => $prefix'translate' => !$tip)$enabledtrue$checkbox);
  231.         }
  232.  
  233.         return static::state($states$value$i$prefix$enabledtrue$checkbox);
  234.     }
  235.  
  236.     /**
  237.      * Returns a isDefault state on a grid
  238.      *
  239.      * @param   integer       $value     The state value.
  240.      * @param   integer       $i         The row index
  241.      * @param   string|array $prefix    An optional task prefix or an array of options
  242.      * @param   boolean       $enabled   An optional setting for access control on the action.
  243.      * @param   string        $checkbox  An optional prefix for checkboxes.
  244.      *
  245.      * @return  string  The HTML markup
  246.      *
  247.      * @see     JHtmlJGrid::state()
  248.      * @since   1.6
  249.      */
  250.     public static function isdefault($value$i$prefix ''$enabled true$checkbox 'cb')
  251.     {
  252.         if (is_array($prefix))
  253.         {
  254.             $options $prefix;
  255.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  256.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  257.             $prefix array_key_exists('prefix'$options$options['prefix''';
  258.         }
  259.  
  260.         $states array(
  261.             => array('setDefault''''JLIB_HTML_SETDEFAULT_ITEM'''1'unfeatured''unfeatured'),
  262.             => array('unsetDefault''JDEFAULT''JLIB_HTML_UNSETDEFAULT_ITEM''JDEFAULT'1'featured''featured'),
  263.         );
  264.  
  265.         return static::state($states$value$i$prefix$enabledtrue$checkbox);
  266.     }
  267.  
  268.     /**
  269.      * Returns an array of standard published state filter options.
  270.      *
  271.      * @param   array  $config  An array of configuration options.
  272.      *                           This array can contain a list of key/value pairs where values are boolean
  273.      *                           and keys can be taken from 'published', 'unpublished', 'archived', 'trash', 'all'.
  274.      *                           These pairs determine which values are displayed.
  275.      *
  276.      * @return  string  The HTML markup
  277.      *
  278.      * @since   1.6
  279.      */
  280.     public static function publishedOptions($config array())
  281.     {
  282.         // Build the active state filter options.
  283.         $options array();
  284.  
  285.         if (!array_key_exists('published'$config|| $config['published'])
  286.         {
  287.             $options[JHtml::_('select.option''1''JPUBLISHED');
  288.         }
  289.  
  290.         if (!array_key_exists('unpublished'$config|| $config['unpublished'])
  291.         {
  292.             $options[JHtml::_('select.option''0''JUNPUBLISHED');
  293.         }
  294.  
  295.         if (!array_key_exists('archived'$config|| $config['archived'])
  296.         {
  297.             $options[JHtml::_('select.option''2''JARCHIVED');
  298.         }
  299.  
  300.         if (!array_key_exists('trash'$config|| $config['trash'])
  301.         {
  302.             $options[JHtml::_('select.option''-2''JTRASHED');
  303.         }
  304.  
  305.         if (!array_key_exists('all'$config|| $config['all'])
  306.         {
  307.             $options[JHtml::_('select.option''*''JALL');
  308.         }
  309.  
  310.         return $options;
  311.     }
  312.  
  313.     /**
  314.      * Returns a checked-out icon
  315.      *
  316.      * @param   integer       $i           The row index.
  317.      * @param   string        $editorName  The name of the editor.
  318.      * @param   string        $time        The time that the object was checked out.
  319.      * @param   string|array $prefix      An optional task prefix or an array of options
  320.      * @param   boolean       $enabled     True to enable the action.
  321.      * @param   string        $checkbox    An optional prefix for checkboxes.
  322.      *
  323.      * @return  string  The HTML markup
  324.      *
  325.      * @since   1.6
  326.      */
  327.     public static function checkedout($i$editorName$time$prefix ''$enabled false$checkbox 'cb')
  328.     {
  329.         JHtml::_('bootstrap.tooltip');
  330.  
  331.         if (is_array($prefix))
  332.         {
  333.             $options $prefix;
  334.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  335.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  336.             $prefix array_key_exists('prefix'$options$options['prefix''';
  337.         }
  338.  
  339.         $text $editorName '<br />' JHtml::_('date'$timeJText::_('DATE_FORMAT_LC')) '<br />' JHtml::_('date'$time'H:i');
  340.         $active_title JHtml::tooltipText(JText::_('JLIB_HTML_CHECKIN')$text0);
  341.         $inactive_title JHtml::tooltipText(JText::_('JLIB_HTML_CHECKED_OUT')$text0);
  342.  
  343.         return static::action(
  344.             $i'checkin'$prefixJText::_('JLIB_HTML_CHECKED_OUT')$active_title$inactive_titletrue'checkedout',
  345.             'checkedout'$enabledfalse$checkbox
  346.         );
  347.     }
  348.  
  349.     /**
  350.      * Creates a order-up action icon.
  351.      *
  352.      * @param   integer       $i         The row index.
  353.      * @param   string        $task      An optional task to fire.
  354.      * @param   string|array $prefix    An optional task prefix or an array of options
  355.      * @param   string        $text      An optional text to display
  356.      * @param   boolean       $enabled   An optional setting for access control on the action.
  357.      * @param   string        $checkbox  An optional prefix for checkboxes.
  358.      *
  359.      * @return  string  The HTML markup
  360.      *
  361.      * @since   1.6
  362.      */
  363.     public static function orderUp($i$task 'orderup'$prefix ''$text 'JLIB_HTML_MOVE_UP'$enabled true$checkbox 'cb')
  364.     {
  365.         if (is_array($prefix))
  366.         {
  367.             $options $prefix;
  368.             $text array_key_exists('text'$options$options['text'$text;
  369.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  370.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  371.             $prefix array_key_exists('prefix'$options$options['prefix''';
  372.         }
  373.         return static::action($i$task$prefix$text$text$textfalse'uparrow''uparrow_disabled'$enabledtrue$checkbox);
  374.     }
  375.  
  376.     /**
  377.      * Creates a order-down action icon.
  378.      *
  379.      * @param   integer       $i         The row index.
  380.      * @param   string        $task      An optional task to fire.
  381.      * @param   string|array $prefix    An optional task prefix or an array of options
  382.      * @param   string        $text      An optional text to display
  383.      * @param   boolean       $enabled   An optional setting for access control on the action.
  384.      * @param   string        $checkbox  An optional prefix for checkboxes.
  385.      *
  386.      * @return  string  The HTML markup
  387.      *
  388.      * @since   1.6
  389.      */
  390.     public static function orderDown($i$task 'orderdown'$prefix ''$text 'JLIB_HTML_MOVE_DOWN'$enabled true$checkbox 'cb')
  391.     {
  392.         if (is_array($prefix))
  393.         {
  394.             $options $prefix;
  395.             $text array_key_exists('text'$options$options['text'$text;
  396.             $enabled array_key_exists('enabled'$options$options['enabled'$enabled;
  397.             $checkbox array_key_exists('checkbox'$options$options['checkbox'$checkbox;
  398.             $prefix array_key_exists('prefix'$options$options['prefix''';
  399.         }
  400.  
  401.         return static::action($i$task$prefix$text$text$textfalse'downarrow''downarrow_disabled'$enabledtrue$checkbox);
  402.     }
  403. }

Documentation generated on Tue, 19 Nov 2013 15:06:04 +0100 by phpDocumentor 1.4.3