* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision$ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ /** * @since 1.5.0 */ class WarehouseCore extends ObjectModel { public $id; public $id_address; public $reference; public $name; public $id_employee; public $management_type; protected $fieldsRequired = array( 'id_address', 'reference', 'name', 'id_employee', 'management_type' ); protected $fieldsSize = array( 'stock_management' => 32, 'reference' => 45, 'name' => 45 ); protected $fieldsValidate = array( 'id_address' => 'isUnsignedId', 'reference' => 'isString', 'name' => 'isString', 'id_employee' => 'isUnsignedId', 'management_type' => 'isStockManagement' ); protected $table = 'warehouse'; protected $identifier = 'id_warehouse'; public function getFields() { $this->validateFields(); $fields['id_address'] = (int)$this->id_address; $fields['reference'] = $this->reference; $fields['name'] = pSQL($this->name); $fields['id_employee'] = (int)$this->id_employee; $fields['management_type'] = pSQL($this->management_type); return $fields; } /** * For the current warehouse, gets the shops it is associated to * * @return array */ public function getShops() { $query = new DbQuery(); $query->select('ws.id_shop'); $query->from('warehouse_shop ws'); $query->where($this->identifier.' = '.(int)$this->id); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); } /** * For the current warehouse, sets the shops it is associated to * * @param array $id_shop_list List of shop ids */ public function setShops($id_shop_list) { $row_to_insert = array(); foreach ($id_shop_list as $id_shop) $row_to_insert = array($this->reference => $this->id, 'id_shop' => $id_shop); Db::getInstance()->execute('DELETE FROM `warehouse_shop` ws WHERE ws.'.$this->identifier.' = '.(int)$this->id); Db::getInstance()->autoExecute('warehouse_shop', $row_to_insert, 'INSERT'); } /** * For a given warehouse, checks if it exists * * @param int $id_warehouse * @return bool */ public static function exists($id_warehouse) { return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT w.id_warehouse FROM `warehouse` w WHERE w.id_warehouse = '.(int)$id_warehouse.' LIMIT 1'); } }