* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBShop' , 'WBShop_Config'); /** * Shop Article * * * @version 0.1.0 * @package WB * @subpackage base */ class WBShop_Article extends WBStdClass { /** * Shop config * @var WBShop_Config */ private $sc; /** * Database access * @var WBDatasource_Table */ private $table; /** * id of current cart * @var string */ private $id = '__none'; /** * the article's data * @var array */ private $data = array(); /** * primary key of article in table * @var string */ private $primary = null; /** * constructor * * Instantiate table object */ public function __construct() { $this->sc = WBShop_Config::singleton(); $this->table = WBClass::create('WBDatasource_Table'); $this->primary = $this->table->getIdentifier($this->sc->getItemTable()); } /** * Get primary key * * Receive primary column name of article table * * @return string */ public function getIdentifer() { return $this->primary; } /** * Load article data * * Try to load article data from database * * @return WBShop_Article */ public function load($id) { $this->data = array(); if (empty($id)) { return $this; } $list = $this->table->get($this->sc->getItemTable(), $id); if (1 == count($list)) { $this->data = $list[0]; } return $this; } /** * Get Id of current article * * Receive id of loaded article or null, if no article was loaded * * @return string|null */ public function getId() { if (isset($this->data[$this->primary])) { return $this->data[$this->primary]; } return null; } /** * receive article data * * @return array */ public function get() { return $this->data; } }