<?php
/**
 * Virtuemart Waitinglist table
 *
 * @package		CSVIVirtueMart
 * @author 		Roland Dalmulder
 * @link 		http://www.csvimproved.com
 * @copyright 	Copyright (C) 2006 - 2012 RolandD Cyber Produksi
 * @license 	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 * @version 	$Id: vm_waiting_list.php 1892 2012-02-11 11:01:09Z RolandD $
 */

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

/**
 * @package CSVIVirtueMart
 */
class TableVm_waiting_list extends JTable {
	
	// Sets whether the database columns have been loaded
	private $_loaded = false;
	
	/**
	 * @param database A database connector object
	 */
	function __construct($db) {
		$this->reset();
		parent::__construct('#__vm_waiting_list', 'waiting_list_id', $db );
	}
	
	/**
	 * Resets the default properties 
	 * 
	 * @copyright 
	 * @author 		RolandD
	 * @todo 
	 * @see 
	 * @access 		public
	 * @param 
	 * @return 		void
	 * @since 		3.1
	 */
	function reset() {
		if (!$this->_loaded) {
			$this->setProperties(CsvivirtuemartModelAvailablefields::DbFields('vm_waiting_list'));
			$this->_loaded = true;
		}
		else {
			$class_vars = get_class_vars(get_class($this));
			foreach ($this as $name => $value) {
				if (substr($name, 0, 1) != '_') {
					$this->$name = null;
				}
			}
		}
	}
	
	/**
	 * Check if there is already a waiting list entry 
	 * 
	 * @copyright 
	 * @author 		RolandD
	 * @todo 
	 * @see 
	 * @access 		public
	 * @param 
	 * @return 		
	 * @since 		3.1
	 */
	public function check() {
		if (empty($this->waiting_list_id)) {
			$db = JFactory::getDBO();
			$csvilog = JRequest::getVar('csvilog');
			$q = "SELECT waiting_list_id
				FROM #__vm_waiting_list
				WHERE product_id = ".$this->product_id."
				AND user_id = ".$this->user_id;
			$db->setQuery($q);
			$this->waiting_list_id = $db->loadResult();
			$csvilog->addDebug(JText::_('COM_CSVIVIRTUEMART_CHECKING_WAITINGLIST_EXISTS'), true);
		}
	}
}
?>
