[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_newsfeeds/models/ -> category.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: category.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * Newsfeeds Component Category Model
  22   *
  23   * @package        Joomla
  24   * @subpackage    Newsfeeds
  25   * @since 1.5
  26   */
  27  class NewsfeedsModelCategory extends JModel
  28  {
  29      /**
  30       * Category id
  31       *
  32       * @var int
  33       */
  34      var $_id = null;
  35  
  36      /**
  37       * Category data array
  38       *
  39       * @var array
  40       */
  41      var $_data = null;
  42  
  43      /**
  44       * Category total
  45       *
  46       * @var integer
  47       */
  48      var $_total = null;
  49  
  50      /**
  51       * Category data
  52       *
  53       * @var object
  54       */
  55      var $_category = null;
  56  
  57      /**
  58       * Constructor
  59       *
  60       * @since 1.5
  61       */
  62  	function __construct()
  63      {
  64          global $mainframe;
  65  
  66          parent::__construct();
  67  
  68          $config = JFactory::getConfig();
  69  
  70          // Get the pagination request variables
  71          $this->setState('limit', $mainframe->getUserStateFromRequest('com_newsfeeds.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
  72          $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
  73  
  74          $id = JRequest::getVar('id', 0, '', 'int');
  75          $this->setId((int)$id);
  76  
  77      }
  78  
  79      /**
  80       * Method to set the category id
  81       *
  82       * @access    public
  83       * @param    int    Category ID number
  84       */
  85  	function setId($id)
  86      {
  87          // Set category ID and wipe data
  88          $this->_id            = $id;
  89          $this->_category    = null;
  90      }
  91  
  92      /**
  93       * Method to get newsfeed item data for the category
  94       *
  95       * @access public
  96       * @return array
  97       */
  98  	function getData()
  99      {
 100          // Lets load the content if it doesn't already exist
 101          if (empty($this->_data))
 102          {
 103              $query = $this->_buildQuery();
 104  
 105              $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
 106  
 107              $total = count($this->_data);
 108              for($i = 0; $i < $total; $i++)
 109              {
 110                  $item =& $this->_data[$i];
 111                  $item->slug = $item->id.'-'.$item->alias;
 112              }
 113          }
 114  
 115          return $this->_data;
 116      }
 117  
 118      /**
 119       * Method to get the total number of newsfeed items for the category
 120       *
 121       * @access public
 122       * @return integer
 123       */
 124  	function getTotal()
 125      {
 126          // Lets load the content if it doesn't already exist
 127          if (empty($this->_total))
 128          {
 129              $query = $this->_buildQuery();
 130              $this->_total = $this->_getListCount($query);
 131          }
 132  
 133          return $this->_total;
 134      }
 135  
 136      /**
 137       * Method to get a pagination object of the newsfeeds items for the category
 138       *
 139       * @access public
 140       * @return integer
 141       */
 142  	function getPagination()
 143      {
 144          // Lets load the content if it doesn't already exist
 145          if (empty($this->_pagination))
 146          {
 147              jimport('joomla.html.pagination');
 148              $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
 149          }
 150  
 151          return $this->_pagination;
 152      }
 153  
 154      /**
 155       * Method to get category data for the current category
 156       *
 157       * @since 1.5
 158       */
 159  	function getCategory()
 160      {
 161          // Load the Category data
 162          if ($this->_loadCategory())
 163          {
 164              // Initialize some variables
 165              $user = &JFactory::getUser();
 166  
 167              // Make sure the category is published
 168              if (!$this->_category->published) {
 169                  JError::raiseError(404, JText::_("Resource Not Found"));
 170                  return false;
 171              }
 172              // check whether category access level allows access
 173              if ($this->_category->access > $user->get('aid', 0)) {
 174                  JError::raiseError(403, JText::_("ALERTNOTAUTH"));
 175                  return false;
 176              }
 177          }
 178          return $this->_category;
 179      }
 180  
 181      /**
 182       * Method to load category data if it doesn't exist.
 183       *
 184       * @access    private
 185       * @return    boolean    True on success
 186       */
 187  	function _loadCategory()
 188      {
 189          if (empty($this->_category))
 190          {
 191              // current category info
 192              $query = 'SELECT c.*,' .
 193                  ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug '.
 194                  ' FROM #__categories AS c' .
 195                  ' WHERE c.id = '. (int) $this->_id .
 196                  ' AND c.section = "com_newsfeeds"';
 197              $this->_db->setQuery($query, 0, 1);
 198              $this->_category = $this->_db->loadObject();
 199          }
 200          return true;
 201      }
 202  
 203  	function _buildQuery()
 204      {
 205          // We need to get a list of all weblinks in the given category
 206          $query = 'SELECT *' .
 207              ' FROM #__newsfeeds' .
 208              ' WHERE catid = '.(int) $this->_id.
 209              ' AND published = 1' .
 210              ' ORDER BY ordering';
 211  
 212          return $query;
 213      }
 214  }
 215  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1