Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/classes/logic/Address.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 Address extends LogicObject
{
	var $id = 0;
	var $id_user = 0;

	var $delivery = 0;
	var $invoiceing = 0;
	var $primary_addr = 0;

	var $county = "";
	var $city = "";
	var $address = "";

	function Address()
	{
		parent::LogicObject();
	}

	function getInstanceProps($myClass = "")
	{
		if(empty($myClass))
			$myClass = __CLASS__;
		return parent::getInstanceProps($myClass);
	}

	function validate()
	{
		$errors = array();
		$db = Application::getDb();
		if(!$db->tbUser->idExists($this->id_user))
			$errors[] = "Nu am putut gasi utilizatorul care are aceasta adresa";
		if(strlen($this->county) < 3 || strlen($this->county) > 255)
			$errors[] = "Numele judetului trebuie sa aiba intre 3 si 255 caractere";
		if(strlen($this->city) < 3 || strlen($this->city) > 255)
			$errors[] = "Va rugam sa alegeti orasul";

		if($this->id > 0)
		{
			$user = Application::getUser();
			$a = $db->tbAddress->getRecordById($this->id);
			if($a->id == 0)
				$errors[] = "Nu am putut gasi aceasta adresa pentru a o actualiza";
			elseif ($a->id_user != $user->id)
				$errors[] = "Adresa aceasta nu va apartine";
		}

		Application::appendErrors($errors);
		return (count($errors) == 0);
	}

	function toStr($humanReadable = false)
	{
		if($humanReadable)
		{
			$s = "Judetul: $this->county
Orasul: $this->city
Addresa: $this->address";
			return $s;
		}
		else
		{
			return parent::toStr();
		}
	}
}

?>
Return current item: Katyshop