Source for file weblinks.php

Documentation is available at weblinks.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_weblinks
  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.  * Methods supporting a list of weblink records.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_weblinks
  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.                 'id''a.id',
  33.                 'title''a.title',
  34.                 'alias''a.alias',
  35.                 'checked_out''a.checked_out',
  36.                 'checked_out_time''a.checked_out_time',
  37.                 'catid''a.catid''category_title',
  38.                 'state''a.state',
  39.                 'access''a.access''access_level',
  40.                 'created''a.created',
  41.                 'created_by''a.created_by',
  42.                 'ordering''a.ordering',
  43.                 'featured''a.featured',
  44.                 'language''a.language',
  45.                 'hits''a.hits',
  46.                 'publish_up''a.publish_up',
  47.                 'publish_down''a.publish_down',
  48.                 'url''a.url',
  49.             );
  50.         }
  51.  
  52.         parent::__construct($config);
  53.     }
  54.  
  55.     /**
  56.      * Method to auto-populate the model state.
  57.      *
  58.      * Note. Calling getState in this method will result in recursion.
  59.      *
  60.      * @since   1.6
  61.      */
  62.     protected function populateState($ordering null$direction null)
  63.     {
  64.         // Load the filter state.
  65.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  66.         $this->setState('filter.search'$search);
  67.  
  68.         $accessId $this->getUserStateFromRequest($this->context . '.filter.access''filter_access'null'int');
  69.         $this->setState('filter.access'$accessId);
  70.  
  71.         $published $this->getUserStateFromRequest($this->context . '.filter.state''filter_state''''string');
  72.         $this->setState('filter.state'$published);
  73.  
  74.         $categoryId $this->getUserStateFromRequest($this->context . '.filter.category_id''filter_category_id''');
  75.         $this->setState('filter.category_id'$categoryId);
  76.  
  77.         $language $this->getUserStateFromRequest($this->context . '.filter.language''filter_language''');
  78.         $this->setState('filter.language'$language);
  79.  
  80.         $tag $this->getUserStateFromRequest($this->context . '.filter.tag''filter_tag''');
  81.         $this->setState('filter.tag'$tag);
  82.  
  83.         // Load the parameters.
  84.         $params JComponentHelper::getParams('com_weblinks');
  85.         $this->setState('params'$params);
  86.  
  87.         // List state information.
  88.         parent::populateState('a.title''asc');
  89.     }
  90.  
  91.     /**
  92.      * Method to get a store id based on model configuration state.
  93.      *
  94.      * This is necessary because the model is used by the component and
  95.      * different modules that might need different sets of data or different
  96.      * ordering requirements.
  97.      *
  98.      * @param   string  $id    A prefix for the store id.
  99.      * @return  string  A store id.
  100.      * @since   1.6
  101.      */
  102.     protected function getStoreId($id '')
  103.     {
  104.         // Compile the store id.
  105.         $id .= ':' $this->getState('filter.search');
  106.         $id .= ':' $this->getState('filter.access');
  107.         $id .= ':' $this->getState('filter.state');
  108.         $id .= ':' $this->getState('filter.category_id');
  109.         $id .= ':' $this->getState('filter.language');
  110.  
  111.         return parent::getStoreId($id);
  112.     }
  113.  
  114.     /**
  115.      * Build an SQL query to load the list data.
  116.      *
  117.      * @return  JDatabaseQuery 
  118.      * @since   1.6
  119.      */
  120.     protected function getListQuery()
  121.     {
  122.         // Create a new query object.
  123.         $db $this->getDbo();
  124.         $query $db->getQuery(true);
  125.         $user JFactory::getUser();
  126.  
  127.         // Select the required fields from the table.
  128.         $query->select(
  129.             $this->getState(
  130.                 'list.select',
  131.                 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
  132.                     'a.hits,' .
  133.                     'a.state, a.access, a.ordering,' .
  134.                     'a.language, a.publish_up, a.publish_down'
  135.             )
  136.         );
  137.         $query->from($db->quoteName('#__weblinks'' AS a');
  138.  
  139.         // Join over the language
  140.         $query->select('l.title AS language_title')
  141.             ->join('LEFT'$db->quoteName('#__languages'' AS l ON l.lang_code = a.language');
  142.  
  143.         // Join over the users for the checked out user.
  144.         $query->select('uc.name AS editor')
  145.             ->join('LEFT''#__users AS uc ON uc.id=a.checked_out');
  146.  
  147.         // Join over the asset groups.
  148.         $query->select('ag.title AS access_level')
  149.             ->join('LEFT''#__viewlevels AS ag ON ag.id = a.access');
  150.  
  151.         // Join over the categories.
  152.         $query->select('c.title AS category_title')
  153.             ->join('LEFT''#__categories AS c ON c.id = a.catid');
  154.  
  155.         // Filter by access level.
  156.         if ($access $this->getState('filter.access'))
  157.         {
  158.             $query->where('a.access = ' . (int) $access);
  159.         }
  160.  
  161.         // Implement View Level Access
  162.         if (!$user->authorise('core.admin'))
  163.         {
  164.             $groups implode(','$user->getAuthorisedViewLevels());
  165.             $query->where('a.access IN (' $groups ')');
  166.         }
  167.  
  168.         // Filter by published state
  169.         $published $this->getState('filter.state');
  170.         if (is_numeric($published))
  171.         {
  172.             $query->where('a.state = ' . (int) $published);
  173.         }
  174.         elseif ($published === '')
  175.         {
  176.             $query->where('(a.state IN (0, 1))');
  177.         }
  178.  
  179.         // Filter by category.
  180.         $categoryId $this->getState('filter.category_id');
  181.         if (is_numeric($categoryId))
  182.         {
  183.             $query->where('a.catid = ' . (int) $categoryId);
  184.         }
  185.  
  186.         // Filter by search in title
  187.         $search $this->getState('filter.search');
  188.         if (!empty($search))
  189.         {
  190.             if (stripos($search'id:'=== 0)
  191.             {
  192.                 $query->where('a.id = ' . (int) substr($search3));
  193.             }
  194.             else
  195.             {
  196.                 $search $db->quote('%' $db->escape($searchtrue'%');
  197.                 $query->where('(a.title LIKE ' $search ' OR a.alias LIKE ' $search ')');
  198.             }
  199.         }
  200.  
  201.         // Filter on the language.
  202.         if ($language $this->getState('filter.language'))
  203.         {
  204.             $query->where('a.language = ' $db->quote($language));
  205.         }
  206.  
  207.         $tagId $this->getState('filter.tag');
  208.         // Filter by a single tag.
  209.         if (is_numeric($tagId))
  210.         {
  211.             $query->where($db->quoteName('tagmap.tag_id'' = ' . (int) $tagId)
  212.                 ->join(
  213.                     'LEFT'$db->quoteName('#__contentitem_tag_map''tagmap')
  214.                     . ' ON ' $db->quoteName('tagmap.content_item_id'' = ' $db->quoteName('a.id')
  215.                     . ' AND ' $db->quoteName('tagmap.type_alias'' = ' $db->quote('com_weblinks.weblink')
  216.                 );
  217.         }
  218.  
  219.         // Add the list ordering clause.
  220.         $orderCol $this->state->get('list.ordering');
  221.         $orderDirn $this->state->get('list.direction');
  222.         if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
  223.         {
  224.             $orderCol 'c.title ' $orderDirn ', a.ordering';
  225.         }
  226.         $query->order($db->escape($orderCol ' ' $orderDirn));
  227.  
  228.         //echo nl2br(str_replace('#__','jos_',$query));
  229.         return $query;
  230.     }
  231. }

Documentation generated on Tue, 19 Nov 2013 15:18:30 +0100 by phpDocumentor 1.4.3