Source for file positions.php

Documentation is available at positions.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.  * Modules Component Positions Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_modules
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   array  An optional associative array of configuration settings.
  24.      * @see     JController
  25.      * @since   1.6
  26.      */
  27.     public function __construct($config array())
  28.     {
  29.         if (empty($config['filter_fields']))
  30.         {
  31.             $config['filter_fields'array(
  32.                 'value',
  33.                 'templates',
  34.             );
  35.         }
  36.  
  37.         parent::__construct($config);
  38.     }
  39.  
  40.     /**
  41.      * Method to auto-populate the model state.
  42.      *
  43.      * Note. Calling getState in this method will result in recursion.
  44.      *
  45.      * @since   1.6
  46.      */
  47.     protected function populateState($ordering null$direction null)
  48.     {
  49.         $app JFactory::getApplication('administrator');
  50.  
  51.         // Load the filter state.
  52.         $search $this->getUserStateFromRequest($this->context.'.filter.search''filter_search');
  53.         $this->setState('filter.search'$search);
  54.  
  55.         $state $this->getUserStateFromRequest($this->context.'.filter.state''filter_state''''string');
  56.         $this->setState('filter.state'$state);
  57.  
  58.         $clientId $app->input->getInt('client_id'0);
  59.         $this->setState('filter.client_id'$clientId);
  60.  
  61.         $template $this->getUserStateFromRequest($this->context.'.filter.template''filter_template''''string');
  62.         $this->setState('filter.template'$template);
  63.  
  64.         $type $this->getUserStateFromRequest($this->context.'.filter.type''filter_type''''string');
  65.         $this->setState('filter.type'$type);
  66.  
  67.         // Load the parameters.
  68.         $params JComponentHelper::getParams('com_modules');
  69.         $this->setState('params'$params);
  70.  
  71.         // List state information.
  72.         parent::populateState('value''asc');
  73.     }
  74.  
  75.     /**
  76.      * Method to get an array of data items.
  77.      *
  78.      * @return  mixed  An array of data items on success, false on failure.
  79.      * @since   1.6
  80.      */
  81.     public function getItems()
  82.     {
  83.         if (!isset($this->items))
  84.         {
  85.             $lang            JFactory::getLanguage();
  86.             $search          $this->getState('filter.search');
  87.             $state           $this->getState('filter.state');
  88.             $clientId        $this->getState('filter.client_id');
  89.             $filter_template $this->getState('filter.template');
  90.             $type            $this->getState('filter.type');
  91.             $ordering        $this->getState('list.ordering');
  92.             $direction       $this->getState('list.direction');
  93.             $limitstart      $this->getState('list.start');
  94.             $limit           $this->getState('list.limit');
  95.             $client          JApplicationHelper::getClientInfo($clientId);
  96.  
  97.             if ($type != 'template')
  98.             {
  99.                 // Get the database object and a new query object.
  100.                 $query    $this->_db->getQuery(true)
  101.                     ->select('DISTINCT(position) as value')
  102.                     ->from('#__modules')
  103.                     ->where($this->_db->quoteName('client_id').' = '.(int) $clientId);
  104.                 if ($search)
  105.                 {
  106.                     $query->where('position LIKE '.$this->_db->quote('%'.$this->_db->escape($searchtrue).'%'));
  107.                 }
  108.  
  109.                 $this->_db->setQuery($query);
  110.  
  111.                 try
  112.                 {
  113.                     $positions $this->_db->loadObjectList('value');
  114.                 }
  115.                 catch (RuntimeException $e)
  116.                 {
  117.                     $this->setError($e->getMessage());
  118.                     return false;
  119.                 }
  120.                 foreach ($positions as $value => $position)
  121.                 {
  122.                     $positions[$valuearray();
  123.                 }
  124.             }
  125.             else
  126.             {
  127.                 $positions array();
  128.             }
  129.  
  130.             // Load the positions from the installed templates.
  131.             foreach (ModulesHelper::getTemplates($clientIdas $template)
  132.             {
  133.                 $path JPath::clean($client->path.'/templates/'.$template->element.'/templateDetails.xml');
  134.  
  135.                 if (file_exists($path))
  136.                 {
  137.                     $xml simplexml_load_file($path);
  138.                     if (isset($xml->positions[0]))
  139.                     {
  140.                         $lang->load('tpl_'.$template->element.'.sys'$client->pathnullfalsetrue)
  141.                     ||    $lang->load('tpl_'.$template->element.'.sys'$client->path.'/templates/'.$template->elementnullfalsetrue);
  142.                         foreach ($xml->positions[0as $position)
  143.                         {
  144.                             $value = (string) $position['value'];
  145.                             $label = (string) $position;
  146.                             if (!$value)
  147.                             {
  148.                                 $value $label;
  149.                                 $label preg_replace('/[^a-zA-Z0-9_\-]/''_''TPL_'.$template->element.'_POSITION_'.$value);
  150.                                 $altlabel preg_replace('/[^a-zA-Z0-9_\-]/''_''COM_MODULES_POSITION_'.$value);
  151.                                 if (!$lang->hasKey($label&& $lang->hasKey($altlabel))
  152.                                 {
  153.                                     $label $altlabel;
  154.                                 }
  155.                             }
  156.                             if ($type == 'user' || ($state != '' && $state != $template->enabled))
  157.                             {
  158.                                 unset($positions[$value]);
  159.                             }
  160.                             elseif (preg_match(chr(1$search chr(1'i'$value&& ($filter_template == '' || $filter_template == $template->element))
  161.                             {
  162.                                 if (!isset($positions[$value]))
  163.                                 {
  164.                                     $positions[$valuearray();
  165.                                 }
  166.                                 $positions[$value][$template->name$label;
  167.                             }
  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.             $this->total count($positions);
  173.             if ($limitstart >= $this->total)
  174.             {
  175.                 $limitstart $limitstart $limit $limitstart $limit;
  176.                 $this->setState('list.start'$limitstart);
  177.             }
  178.             if ($ordering == 'value')
  179.             {
  180.                 if ($direction == 'asc')
  181.                 {
  182.                     ksort($positions);
  183.                 }
  184.                 else {
  185.                     krsort($positions);
  186.                 }
  187.             }
  188.             else {
  189.                 if ($direction == 'asc')
  190.                 {
  191.                     asort($positions);
  192.                 }
  193.                 else {
  194.                     arsort($positions);
  195.                 }
  196.             }
  197.             $this->items array_slice($positions$limitstart$limit $limit null);
  198.         }
  199.         return $this->items;
  200.     }
  201.  
  202.     /**
  203.      * Method to get the total number of items.
  204.      *
  205.      * @return  int    The total number of items.
  206.      * @since   1.6
  207.      */
  208.     public function getTotal()
  209.     {
  210.         if (!isset($this->total))
  211.         {
  212.             $this->getItems();
  213.         }
  214.         return $this->total;
  215.     }
  216. }

Documentation generated on Tue, 19 Nov 2013 15:11:00 +0100 by phpDocumentor 1.4.3