Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/classes/dblayer/TableOrder.php
<?php

/**
 * Product: Katyshop
 * @version 0.3.2.1
 * @author Catalin Hulea - hide@address.com
 * @copyright Copyright (C) 2007 Catalin Hulea
 * @license GNU General Public License version 3
 * 			You can find a copy of GNU GPL v3 at this path: /docs/LICENSE
 * @link https://sourceforge.net/projects/katyshop
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

class TableOrder extends MysqlTable
{
	function TableOrder(&$database, $tableName)
	{
		parent::MysqlTable($database, $tableName);
	}

	function createLogicObject()
	{
		return new Order();
	}

	function getStrictFields()
	{
		parent::getStrictFields();
		return array("id", "id_user", "value_without_vat", "value_vat", "value_total", "measuring_unit");
	}

	/**
	 * @return Order
	 */
	function getRecordById($id)
	{
		$ret = new Order();
		$q = "select * from {$this->name}
			where id = '" . $this->db->escape($id) . "' ";
		$res = $this->db->query($q);
		if($row = $this->db->fetch_array($res))
			$ret->copyFromArray($row);

		$ret->orderProducts = $this->db->tbOrderProduct->getRecordsByOrderId($ret->id);

		return $ret;
	}

	/**
	 * @return Order
	 */
	function getRecordByCode($code)
	{
		$ret = new Order();
		$q = "select * from {$this->name}
			where code = '" . $this->db->escape($code) . "' ";
		$res = $this->db->query($q);
		if($row = $this->db->fetch_array($res))
			$ret->copyFromArray($row);

		$ret->orderProducts = $this->db->tbOrderProduct->getRecordsByOrderId($ret->id);

		return $ret;
	}

	function orderExists($id)
	{
		$q = "select count(*) as total from {$this->name}
			where id = '" . $this->db->escape($id) . "' ";
		$res = $this->db->query($q);
		$row = $this->db->fetch_array($res);
		return (intval(@$row["total"]) > 0);
	}

	function changeStatus($id_order, $newStatus)
	{
		$q = "update {$this->name}
			set status = '" . $this->db->escape($newStatus) . "'
			where id = '" . $this->db->escape($id_order) . "' ";
		$this->db->query($q);
	}

	/**
	 * @param Order $o
	 * @return int id of the order
	 */
	function insertObj(&$o)
	{
		$o->computeValue();
		$o->status = "trimisa";
		parent::insertObj($o);
		$o->id = $this->db->lastInsertId();
		$o->generateCode();
		parent::updateObj($o);
		$o->setProductsIds();

		for($i = 0; $i < $o->getProductsCount(); $i++)
		{
			$op = $o->getOrderProduct($i + 1);
			$this->db->tbOrderProduct->insertObj($op);
		}

		$o->generateProforma();

		return $o->id;
	}


}

?>
Return current item: Katyshop