<?php

	/**
	 * Oberklasse aller wpsg Modelle
	 * @author Daschmi
	 */
	class wpsg_model
	{
		
		/** @var array */
		public static $_objCache = array();
		
		/** @var wpsg_db */
		var $db = false;

		/** @var wpsg_ShopController */
		var $shop = false;
		
		var $id = false;		
		var $data = false;
		
		/**
		 * Konstruktor
		 */
		public function __construct()
		{
			
			$this->shop = $GLOBALS['wpsg_sc'];
			$this->db = $GLOBALS['wpsg_db'];
			
			$this->data = array();
			
		} // public function __construct()
		
		/**
		 * Lädt Daten des Objekts
		 */
		public function load($id)
		{
			
			$this->id = $id;
			
		} // public function load($id)
		
		/**
		 * Etwas im Datenarray ablegen
		 */
		public function __get($name)
		{

			if (array_key_exists($name, (array)$this->data))
			{
				
				return $this->data[$name];
				
			}
			
			return null;
			
		} // public function __get($name)
		
		/**
		 * Speichert etwas in einen Datenarry
		 */
		public function __set($name, $value)
		{
		
			$this->data[$name] = $value;
			 
		} // public function __set($name, $value)
		
		/**
		 * Gibt eine Instanz dieses Models zurück anhand des Primärschlüssels
		 * @param int $id
		 */
		public static function getInstance($id, $noCache = false)
		{
				
			$class_name = get_called_class();
			 
			if (!array_key_exists($class_name.'_'.$id, self::$_objCache) || $noCache === true)
			{
				
				$oObject = new $class_name(); 
				$bLoad = $oObject->load($id);

				if (!$bLoad) return false;
		
				self::$_objCache[$class_name.'_'.$id] = $oObject;
		
			}
				
			return self::$_objCache[$class_name.'_'.$id];
				
		} // public abstract static function getInstance($id)
				
	} // class wpsg_model

?>