Source for file modules.php

Documentation is available at modules.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_modules
  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.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * @package     Joomla.Administrator
  14.  * @subpackage  com_modules
  15.  * @since       1.6
  16.  */
  17. abstract class JHtmlModules
  18. {
  19.     /**
  20.      * Builds an array of template options
  21.      *
  22.      * @param   integer  $clientId  The client id.
  23.      * @param   string   $state     The state of the template.
  24.      *
  25.      * @return  array 
  26.      */
  27.     public static function templates($clientId 0$state '')
  28.     {
  29.         $options   array();
  30.         $templates ModulesHelper::getTemplates($clientId$state);
  31.  
  32.         foreach ($templates as $template)
  33.         {
  34.             $options[]    JHtml::_('select.option'$template->element$template->name);
  35.         }
  36.  
  37.         return $options;
  38.     }
  39.  
  40.     /**
  41.      * Builds an array of template type options
  42.      *
  43.      * @return  array 
  44.      */
  45.     public static function types()
  46.     {
  47.         $options array();
  48.         $options[JHtml::_('select.option''user''COM_MODULES_OPTION_POSITION_USER_DEFINED');
  49.         $options[JHtml::_('select.option''template''COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED');
  50.  
  51.         return $options;
  52.     }
  53.  
  54.     /**
  55.      * Builds an array of template state options
  56.      *
  57.      * @return  array 
  58.      */
  59.     public static function templateStates()
  60.     {
  61.         $options array();
  62.         $options[JHtml::_('select.option''1''JENABLED');
  63.         $options[JHtml::_('select.option''0''JDISABLED');
  64.  
  65.         return $options;
  66.     }
  67.  
  68.     /**
  69.      * Returns a published state on a grid
  70.      *
  71.      * @param   integer  $value     The state value.
  72.      * @param   integer  $i         The row index
  73.      * @param   boolean  $enabled   An optional setting for access control on the action.
  74.      * @param   string   $checkbox  An optional prefix for checkboxes.
  75.      *
  76.      * @return  string        The Html code
  77.      *
  78.      * @see     JHtmlJGrid::state
  79.      * @since   1.7.1
  80.      */
  81.     public static function state($value$i$enabled true$checkbox 'cb')
  82.     {
  83.         $states    array(
  84.             => array(
  85.                 'unpublish',
  86.                 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
  87.                 'COM_MODULES_HTML_UNPUBLISH_ENABLED',
  88.                 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
  89.                 true,
  90.                 'publish',
  91.                 'publish'
  92.             ),
  93.             => array(
  94.                 'publish',
  95.                 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
  96.                 'COM_MODULES_HTML_PUBLISH_ENABLED',
  97.                 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
  98.                 true,
  99.                 'unpublish',
  100.                 'unpublish'
  101.             ),
  102.             -=> array(
  103.                 'unpublish',
  104.                 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
  105.                 'COM_MODULES_HTML_UNPUBLISH_DISABLED',
  106.                 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
  107.                 true,
  108.                 'warning',
  109.                 'warning'
  110.             ),
  111.             -=> array(
  112.                 'publish',
  113.                 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
  114.                 'COM_MODULES_HTML_PUBLISH_DISABLED',
  115.                 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
  116.                 true,
  117.                 'unpublish',
  118.                 'unpublish'
  119.             ),
  120.         );
  121.  
  122.         return JHtml::_('jgrid.state'$states$value$i'modules.'$enabledtrue$checkbox);
  123.     }
  124.  
  125.     /**
  126.      * Display a batch widget for the module position selector.
  127.      *
  128.      * @param   integer  $clientId          The client ID.
  129.      * @param   integer  $state             The state of the module (enabled, unenabled, trashed).
  130.      * @param   string   $selectedPosition  The currently selected position for the module.
  131.      *
  132.      * @return  string   The necessary positions for the widget.
  133.      *
  134.      * @since   2.5
  135.      */
  136.  
  137.     public static function positions($clientId$state 1$selectedPosition '')
  138.     {
  139.         require_once JPATH_ADMINISTRATOR '/components/com_templates/helpers/templates.php';
  140.         $templates      array_keys(ModulesHelper::getTemplates($clientId$state));
  141.         $templateGroups array();
  142.  
  143.         // Add an empty value to be able to deselect a module position
  144.         $option ModulesHelper::createOption();
  145.         $templateGroups[''ModulesHelper::createOptionGroup(''array($option));
  146.  
  147.         // Add positions from templates
  148.         $isTemplatePosition false;
  149.         foreach ($templates as $template)
  150.         {
  151.             $options array();
  152.  
  153.             $positions TemplatesHelper::getPositions($clientId$template);
  154.             if (is_array($positions)) foreach ($positions as $position)
  155.             {
  156.                 $text ModulesHelper::getTranslatedModulePosition($clientId$template$position' [' $position ']';
  157.                 $options[ModulesHelper::createOption($position$text);
  158.  
  159.                 if (!$isTemplatePosition && $selectedPosition === $position)
  160.                 {
  161.                     $isTemplatePosition true;
  162.                 }
  163.             }
  164.  
  165.             $templateGroups[$templateModulesHelper::createOptionGroup(ucfirst($template)$options);
  166.         }
  167.  
  168.         // Add custom position to options
  169.         $customGroupText JText::_('COM_MODULES_CUSTOM_POSITION');
  170.  
  171.         $editPositions true;
  172.         $customPositions ModulesHelper::getPositions($clientId$editPositions);
  173.         $templateGroups[$customGroupTextModulesHelper::createOptionGroup($customGroupText$customPositions);
  174.  
  175.         return $templateGroups;
  176.     }
  177.  
  178.     public static function batchOptions()
  179.     {
  180.         // Create the copy/move options.
  181.         $options array(
  182.             JHtml::_('select.option''c'JText::_('JLIB_HTML_BATCH_COPY')),
  183.             JHtml::_('select.option''m'JText::_('JLIB_HTML_BATCH_MOVE'))
  184.         );
  185.  
  186.         echo JHtml::_('select.radiolist'$options'batch[move_copy]''''value''text''m');
  187.     }
  188.  
  189.     /**
  190.      * Method to get the field options.
  191.      *
  192.      * @param   integer  $clientId  The client ID
  193.      *
  194.      * @return  array  The field option objects.
  195.      *
  196.      * @since   2.5
  197.      */
  198.     public static function positionList($clientId 0)
  199.     {
  200.         $db        JFactory::getDbo();
  201.         $query    $db->getQuery(true)
  202.             ->select('DISTINCT(position) as value')
  203.             ->select('position as text')
  204.             ->from($db->quoteName('#__modules'))
  205.             ->where($db->quoteName('client_id'' = ' . (int) $clientId)
  206.             ->order('position');
  207.  
  208.         // Get the options.
  209.         $db->setQuery($query);
  210.  
  211.         try
  212.         {
  213.             $options $db->loadObjectList();
  214.         }
  215.         catch (RuntimeException $e)
  216.         {
  217.             JError::raiseWarning(500$e->getMessage());
  218.         }
  219.  
  220.         // Pop the first item off the array if it's blank
  221.         if (count($options))
  222.         {
  223.             if (strlen($options[0]->text1)
  224.             {
  225.                 array_shift($options);
  226.             }
  227.         }
  228.  
  229.         return $options;
  230.     }
  231. }

Documentation generated on Tue, 19 Nov 2013 15:08:54 +0100 by phpDocumentor 1.4.3