<?php
class Game
{
	var $bLoaded=false;
	var $gid = 0;
	var $gname = '';
	var $gwords = '';
	var $gcount = 0;
	var $gtitle = '';
	var $bgcolor = '';
	var $active = 0;
	var $gwidth = 0;
	var $gheight = 0;
	var $position = 0;
	var $cat_id = 0;
	var $object = '';
	var $gkeys = '';
	var $date_added = 0;
	function Game($db_row=false)
	{
		if($db_row)
		{
			$this->gid = $db_row->gid;
			$this->gname = $db_row->gname;
			$this->gwords = $db_row->gwords;
			$this->gcount = $db_row->gcount;
			$this->gtitle = $db_row->gtitle;
			$this->bgcolor = $db_row->bgcolor;
			$this->active = $db_row->active;
			$this->gwidth = $db_row->gwidth;
			$this->gheight = $db_row->gheight;
			$this->position = $db_row->position;
			$this->cat_id = $db_row->cat_id;
			$this->object = $db_row->object;
			$this->gkeys = $db_row->gkeys;
			$this->date_added = $db_row->date_added;
			$this->bLoaded=true;
		}
	}
	function &getByID($id)
	{
		global $db;
		$sql = 'SELECT * FROM '.$db->prefix('arcade_games').' WHERE gid='.$id;
		$ret = false;
		if($result = $db->query($sql))
		{
			if($row = $db->fetch_object($result))
			{
				$ret = new Game($row);
			}
		}
		return $ret;
	}
	function &getAllWhere($arrConditions=false, $order_by='', $limit=0, $offset=0)
	{
		global $db;
		$sql = 'SELECT * FROM '.$db->prefix('arcade_games');
		if($arrConditions && count($arrConditions) > 0)	
		{
			$sql .= " WHERE ";
			for ($i=0; $i<count($arrConditions); $i++)
			{
				if ($i < count($arrConditions)-1)
					$sql .= $arrConditions[$i].' AND ';
				else
					$sql .= $arrConditions[$i].' ';
			}
		}
		if($order_by!='')
		{
			$sql .= " ORDER BY $order_by ";
		}
		$ret = array();
		if($result = $db->query($sql, intval($limit), intval($offset)))
		{
			while($row = $db->fetch_object($result))
			{
				$ret[] = new Game($row);
			}
		}
		return $ret;
	}
	function store()
	{
		global $db;
		$sql = '';
		if($this->bLoaded)
		{
			$sql = "UPDATE ".$db->prefix('arcade_games')." SET ";
			$sql .= " gname='$this->gname',";
			$sql .= " gwords='$this->gwords',";
			$sql .= " gcount='$this->gcount',";
			$sql .= " gtitle='$this->gtitle',";
			$sql .= " bgcolor='$this->bgcolor',";
			$sql .= " active='$this->active',";
			$sql .= " gwidth='$this->gwidth',";
			$sql .= " gheight='$this->gheight',";
			$sql .= " position='$this->position',";
			$sql .= " cat_id='$this->cat_id',";
			$sql .= " object='$this->object',";
			$sql .= " gkeys='$this->gkeys',";
			$sql .= " date_added='$this->date_added'";
			$sql .= " WHERE gid='$this->gid'";
		}
		else
		{
			$sql = "INSERT INTO ".$db->prefix('arcade_games')." SET ";
			$sql .= " gid='$this->gid',";
			$sql .= " gname='$this->gname',";
			$sql .= " gwords='$this->gwords',";
			$sql .= " gcount='$this->gcount',";
			$sql .= " gtitle='$this->gtitle',";
			$sql .= " bgcolor='$this->bgcolor',";
			$sql .= " active='$this->active',";
			$sql .= " gwidth='$this->gwidth',";
			$sql .= " gheight='$this->gheight',";
			$sql .= " position='$this->position',";
			$sql .= " cat_id='$this->cat_id',";
			$sql .= " object='$this->object',";
			$sql .= " gkeys='$this->gkeys',";
			$sql .= " date_added='$this->date_added'";
		}
		$result = $db->query($sql);
		if($result) $this->gid = $db->getInsertId();
		return $result;
	}
	function delete()
	{
		global $db;
		$sql = 'DELETE FROM '.$db->prefix('arcade_games').' WHERE gid='.$this->gid;
		$result = $db->query($sql);
		if($result) $this->bloaded = false;
		return $result;
	}
}
?>
