Source for file newsfeeds.php

Documentation is available at newsfeeds.php

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

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