#Crowdfunding

<?php
/*
	This SQL query will create the table to store your object.

	CREATE TABLE `crowdfunding app` (
	`crowdfunding appid` int(11) NOT NULL auto_increment,
	`name` TEXT NOT NULL,
	`contact` DECIMAL NOT NULL,
	`amount` DECIMAL NOT NULL, PRIMARY KEY  (`crowdfunding appid`)) ENGINE=MyISAM;
*/

/**
* <b>Crowdfunding app</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.2 / PHP5
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5&wrapper=pog&objectName=Crowdfunding+app&attributeList=array+%28%0A++0+%3D%3E+%27Name%27%2C%0A++1+%3D%3E+%27Contact%27%2C%0A++2+%3D%3E+%27Amount%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27TEXT%27%2C%0A++1+%3D%3E+%27DECIMAL%27%2C%0A++2+%3D%3E+%27DECIMAL%27%2C%0A%29
*/
include_once('class.pog_base.php');
class Crowdfunding app extends POG_Base
{
	public $crowdfunding appId = '';

	/**
	 * @var TEXT
	 */
	public $Name;
	
	/**
	 * @var DECIMAL
	 */
	public $Contact;
	
	/**
	 * @var DECIMAL
	 */
	public $Amount;
	
	public $pog_attribute_type = array(
		"crowdfunding appId" => array('db_attributes' => array("NUMERIC", "INT")),
		"Name" => array('db_attributes' => array("TEXT", "TEXT")),
		"Contact" => array('db_attributes' => array("NUMERIC", "DECIMAL")),
		"Amount" => array('db_attributes' => array("NUMERIC", "DECIMAL")),
		);
	public $pog_query;
	
	
	/**
	* Getter for some private attributes
	* @return mixed $attribute
	*/
	public function __get($attribute)
	{
		if (isset($this->{"_".$attribute}))
		{
			return $this->{"_".$attribute};
		}
		else
		{
			return false;
		}
	}
	
	function Crowdfunding app($Name='', $Contact='', $Amount='')
	{
		$this->Name = $Name;
		$this->Contact = $Contact;
		$this->Amount = $Amount;
	}
	
	
	/**
	* Gets object from database
	* @param integer $crowdfunding appId 
	* @return object $Crowdfunding app
	*/
	function Get($crowdfunding appId)
	{
		$connection = Database::Connect();
		$this->pog_query = "select * from `crowdfunding app` where `crowdfunding appid`='".intval($crowdfunding appId)."' LIMIT 1";
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$this->crowdfunding appId = $row['crowdfunding appid'];
			$this->Name = $this->Unescape($row['name']);
			$this->Contact = $this->Unescape($row['contact']);
			$this->Amount = $this->Unescape($row['amount']);
		}
		return $this;
	}
	
	
	/**
	* Returns a sorted array of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param string $sortBy 
	* @param boolean $ascending 
	* @param int limit 
	* @return array $crowdfunding appList
	*/
	function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$connection = Database::Connect();
		$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
		$this->pog_query = "select * from `crowdfunding app` ";
		$crowdfunding appList = Array();
		if (sizeof($fcv_array) > 0)
		{
			$this->pog_query .= " where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$this->pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
					{
						$this->pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						if ($GLOBALS['configuration']['db_encoding'] == 1)
						{
							$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
							$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
						}
						else
						{
							$value =  POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
							$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
						}
					}
					else
					{
						$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
						$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
					}
				}
			}
		}
		if ($sortBy != '')
		{
			if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
			{
				if ($GLOBALS['configuration']['db_encoding'] == 1)
				{
					$sortBy = "BASE64_DECODE($sortBy) ";
				}
				else
				{
					$sortBy = "$sortBy ";
				}
			}
			else
			{
				$sortBy = "$sortBy ";
			}
		}
		else
		{
			$sortBy = "crowdfunding appid";
		}
		$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
		$thisObjectName = get_class($this);
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$crowdfunding app = new $thisObjectName();
			$crowdfunding app->crowdfunding appId = $row['crowdfunding appid'];
			$crowdfunding app->Name = $this->Unescape($row['name']);
			$crowdfunding app->Contact = $this->Unescape($row['contact']);
			$crowdfunding app->Amount = $this->Unescape($row['amount']);
			$crowdfunding appList[] = $crowdfunding app;
		}
		return $crowdfunding appList;
	}
	
	
	/**
	* Saves the object to the database
	* @return integer $crowdfunding appId
	*/
	function Save()
	{
		$connection = Database::Connect();
		$rows = 0;
		if ($this->crowdfunding appId!=''){
			$this->pog_query = "select `crowdfunding appid` from `crowdfunding app` where `crowdfunding appid`='".$this->crowdfunding appId."' LIMIT 1";
			$rows = Database::Query($this->pog_query, $connection);
		}
		if ($rows > 0)
		{
			$this->pog_query = "update `crowdfunding app` set 
			`name`='".$this->Escape($this->Name)."', 
			`contact`='".$this->Escape($this->Contact)."', 
			`amount`='".$this->Escape($this->Amount)."' where `crowdfunding appid`='".$this->crowdfunding appId."'";
		}
		else
		{
			$this->pog_query = "insert into `crowdfunding app` (`name`, `contact`, `amount` ) values (
			'".$this->Escape($this->Name)."', 
			'".$this->Escape($this->Contact)."', 
			'".$this->Escape($this->Amount)."' )";
		}
		$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
		if ($this->crowdfunding appId == "")
		{
			$this->crowdfunding appId = $insertId;
		}
		return $this->crowdfunding appId;
	}
	
	
	/**
	* Clones the object and saves it to the database
	* @return integer $crowdfunding appId
	*/
	function SaveNew()
	{
		$this->crowdfunding appId = '';
		return $this->Save();
	}
	
	
	/**
	* Deletes the object from the database
	* @return boolean
	*/
	function Delete()
	{
		$connection = Database::Connect();
		$this->pog_query = "delete from `crowdfunding app` where `crowdfunding appid`='".$this->crowdfunding appId."'";
		return Database::NonQuery($this->pog_query, $connection);
	}
	
	
	/**
	* Deletes a list of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param bool $deep 
	* @return 
	*/
	function DeleteList($fcv_array)
	{
		if (sizeof($fcv_array) > 0)
		{
			$connection = Database::Connect();
			$pog_query = "delete from `crowdfunding app` where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
					{
						$pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
					}
					else
					{
						$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
					}
				}
			}
			return Database::NonQuery($pog_query, $connection);
		}
	}
}
?>