[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_newsfeeds/models/ -> newsfeeds.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.modellist');
  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  class NewsfeedsModelNewsfeeds extends JModelList
  20  {
  21      /**
  22       * Constructor.
  23       *
  24       * @param    array    An optional associative array of configuration settings.
  25       * @see        JController
  26       * @since    1.6
  27       */
  28  	public function __construct($config = array())
  29      {
  30          if (empty($config['filter_fields'])) {
  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  
  51          parent::__construct($config);
  52      }
  53  
  54      /**
  55       * Method to auto-populate the model state.
  56       *
  57       * Note. Calling getState in this method will result in recursion.
  58       *
  59       * @since    1.6
  60       */
  61  	protected function populateState($ordering = null, $direction = null)
  62      {
  63          // Initialise variables.
  64          $app = JFactory::getApplication('administrator');
  65  
  66          // Load the filter state.
  67          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  68          $this->setState('filter.search', $search);
  69  
  70          $accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int');
  71          $this->setState('filter.access', $accessId);
  72  
  73          $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string');
  74          $this->setState('filter.state', $state);
  75  
  76          $categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id', null);
  77          $this->setState('filter.category_id', $categoryId);
  78  
  79          $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', '');
  80          $this->setState('filter.language', $language);
  81  
  82          // Load the parameters.
  83          $params = JComponentHelper::getParams('com_newsfeeds');
  84          $this->setState('params', $params);
  85  
  86          // List state information.
  87          parent::populateState('a.name', 'asc');
  88      }
  89  
  90      /**
  91       * Method to get a store id based on model configuration state.
  92       *
  93       * This is necessary because the model is used by the component and
  94       * different modules that might need different sets of data or different
  95       * ordering requirements.
  96       *
  97       * @param    string    A prefix for the store id.
  98       *
  99       * @return    string    A store id.
 100       */
 101  	protected function getStoreId($id = '')
 102      {
 103          // Compile the store id.
 104          $id    .= ':'.$this->getState('filter.search');
 105          $id    .= ':'.$this->getState('filter.access');
 106          $id    .= ':'.$this->getState('filter.state');
 107          $id    .= ':'.$this->getState('filter.category_id');
 108          $id .= ':'.$this->getState('filter.language');
 109  
 110          return parent::getStoreId($id);
 111      }
 112  
 113      /**
 114       * Build an SQL query to load the list data.
 115       *
 116       * @return    JDatabaseQuery
 117       */
 118  	protected function getListQuery()
 119      {
 120          // Create a new query object.
 121          $db        = $this->getDbo();
 122          $query    = $db->getQuery(true);
 123          $user    = JFactory::getUser();
 124  
 125          // Select the required fields from the table.
 126          $query->select(
 127              $this->getState(
 128                  'list.select',
 129                  'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
 130                  'a.numarticles, a.cache_time, ' .
 131                  ' a.published, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
 132              )
 133          );
 134          $query->from($db->quoteName('#__newsfeeds').' AS a');
 135  
 136          // Join over the language
 137          $query->select('l.title AS language_title');
 138          $query->join('LEFT', $db->quoteName('#__languages').' AS l ON l.lang_code = a.language');
 139  
 140          // Join over the users for the checked out user.
 141          $query->select('uc.name AS editor');
 142          $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
 143  
 144          // Join over the asset groups.
 145          $query->select('ag.title AS access_level');
 146          $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
 147  
 148          // Join over the categories.
 149          $query->select('c.title AS category_title');
 150          $query->join('LEFT', '#__categories AS c ON c.id = a.catid');
 151  
 152          // Filter by access level.
 153          if ($access = $this->getState('filter.access')) {
 154              $query->where('a.access = '.(int) $access);
 155          }
 156  
 157          // Implement View Level Access
 158          if (!$user->authorise('core.admin'))
 159          {
 160              $groups    = implode(',', $user->getAuthorisedViewLevels());
 161              $query->where('a.access IN ('.$groups.')');
 162          }
 163  
 164          // Filter by published state.
 165          $published = $this->getState('filter.state');
 166          if (is_numeric($published)) {
 167              $query->where('a.published = '.(int) $published);
 168          }
 169          elseif ($published === '') {
 170              $query->where('(a.published IN (0, 1))');
 171          }
 172  
 173          // Filter by category.
 174          $categoryId = $this->getState('filter.category_id');
 175          if (is_numeric($categoryId)) {
 176              $query->where('a.catid = ' . (int) $categoryId);
 177          }
 178  
 179          // Filter by search in title
 180          $search = $this->getState('filter.search');
 181          if (!empty($search))
 182          {
 183              if (stripos($search, 'id:') === 0) {
 184                  $query->where('a.id = '.(int) substr($search, 3));
 185              }
 186              else
 187              {
 188                  $search = $db->Quote('%'.$db->escape($search, true).'%');
 189                  $query->where('(a.name LIKE '.$search.' OR a.alias LIKE '.$search.')');
 190              }
 191          }
 192  
 193          // Filter on the language.
 194          if ($language = $this->getState('filter.language')) {
 195              $query->where('a.language = ' . $db->quote($language));
 196          }
 197  
 198          // Add the list ordering clause.
 199          $orderCol    = $this->state->get('list.ordering');
 200          $orderDirn    = $this->state->get('list.direction');
 201          if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
 202              $orderCol = 'c.title '.$orderDirn.', a.ordering';
 203          }
 204          $query->order($db->escape($orderCol.' '.$orderDirn));
 205  
 206          //echo nl2br(str_replace('#__','jos_',$query));
 207          return $query;
 208      }
 209  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1