<?php defined('_JEXEC') or die();
/**
 * @version		1.1.1
 * @package		Read More, Basic
 * @copyright	2009 Rockford Solutions, Inc. All rights reserved.
 * @license		GNU/GPL
 */

jimport('joomla.application.component.model');

/**
 * Readmore Model
 *
 * @package		Read More, Basic
 */
class ReadmoreModelReadmore extends JModel {
	/**
	 * Database record id
	 *
	 * @access	protected
	 * @var		int
	 */
	protected $_id = 0;
	
	/**
	 * Database record data
	 *
	 * @access	protected
	 * @var		object
	 */
	protected $_data = null;
	
	/**
	 * Constructor
	 */
	public function __construct() {
		parent::__construct();
		
		$this->setId(JRequest::getVar('id', 0));
	}
	
	/**
	 * Sets record id and initializes record data
	 *
	 * @param	int		database record id
	 */
	public function setId($id) {
		$this->_id = (int) $id;
		$this->_data = null;
	}
	
	/**
	 * Builds a database query based on selected record id
	 *
	 * @return	string	database query
	 */
	protected function _buildQuery() {
		$query = 'SELECT * FROM #__content WHERE id = ' . $this->_id;
		
		return $query;
	}
	
	/**
	 * Returns database record data, performing database query if necessary
	 *
	 * @return	object	Record data
	 */
	public function &getData() {
		if (empty($this->_data)) {
			$query = $this->_buildQuery();
			
			$this->_db->setQuery($query);
			$this->_data = $this->_db->loadObject();
		}
		
		return $this->_data;
	}
}
