Location: PHPKode > projects > injooosm > administrator/components/com_injooosm/models/cats.php
<?php
/**
 * Joomla! 1.5 component injooosm
 *
 * @version $Id: cats.php 2009-11-22 14:03:00$
 * @author Christian Knorr
 * @package injooosm
 * @subpackage backend
 * @license GNU/GPL
 * @filesource
 *
 * 
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');
/**
 * Model Class Categories
 */
class injooosmModelCats extends JModel {

	/**
	 * Category ata array
	 *
	 * @var array
	 */
	var $_data = null;

	/**
	 * Category total
	 *
	 * @var integer
	 */
	var $_total = null;

	/**
	 * Pagination object
	 *
	 * @var object
	 */
	var $_pagination = null;
    /**
     *
     * @global object $mainframe
     * @global string $option
     */
    function __construct() {
            parent::__construct();
            global $mainframe, $option;

            // Get the pagination request variables
            $limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
            $limitstart	= $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );

            // In case limit has been changed, adjust limitstart accordingly
//		$limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
            $limitstart = JRequest::getVar('limitstart',0);

            $this->setState('limit', $limit);
            $this->setState('limitstart', $limitstart);
    }

        /**
         *
         * @return object
         */
	function getData()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_data))
		{
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
		}

		return $this->_data;
	}
    /**
     *
     * @return array $pagination
     */
 	function getPagination()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_pagination))
		{
			jimport('joomla.html.pagination');
			$this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
		}

		return $this->_pagination;
	}

    /**
     *
     * @return int
     */
    function getTotal()  {

		// Lets load the content if it doesn't already exist
		if (empty($this->_total))
		{
			$query = $this->_buildQuery();
			$this->_total = $this->_getListCount($query);
		}

		return $this->_total;
    }

    /**
     *
     * @global object $mainframe
     * @return string
     */

    function _buildQuery()  {
        global $mainframe;
        $db =& JFactory::getDBO();
        $query = "SELECT * FROM #__osm_cats ORDER BY ordering";
        return $query;
    }

    /**
     *
     * @global object $mainframe
     * @param int $id
     * @return object
     */
    function getCat($id)  {
        global $mainframe;

        $db =& JFactory::getDBO();

        $query = "SELECT * FROM #__osm_cats"
                . "\n WHERE id='" . $id . "'";

        $db->setQuery($query);
        $result = $db->loadObject();

        if ($db->getErrorNum()) {
			echo $db->stderr();
			return false;
		}

        return $result;
    }


    function getParent()  {
        global $mainframe;

        $db = JFactory::getDBO();

        $query = "SELECT id, title FROM #__osm_cats"
                . "\n WHERE parent=0"
                . "\n ORDER BY title ASC"
                ;

        $db->setQuery($query);
        $result = $db->loadObjectList();

        return $result;
    }
}
Return current item: injooosm