88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
|
|
class PrivateSalesStatsStates extends ObjectModel
|
|
{
|
|
|
|
public $id;
|
|
public $id_privatesale_stats_states;
|
|
public $states = array();
|
|
public $name;
|
|
|
|
static $states_static;
|
|
|
|
public static $definition = array(
|
|
'table' => 'privatesale_stats_states',
|
|
'primary' => 'id_privatesale_stats_states',
|
|
'fields' => array(
|
|
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
|
)
|
|
);
|
|
|
|
public function __construct($id = null, $id_lang = null, $id_shop = null)
|
|
{
|
|
parent::__construct($id, $id_lang, $id_shop);
|
|
$this->loadOrderStates();
|
|
}
|
|
|
|
public function loadOrderStates()
|
|
{
|
|
if(Validate::isLoadedObject($this))
|
|
{
|
|
$res = Db::getInstance()->executeS('SELECT id_order_state FROM '._DB_PREFIX_.'privatesale_stats_states_states WHERE id_privatesale_stats_states = '.(int)$this->id);
|
|
|
|
$this->states = array();
|
|
if($res && count($res) > 0)
|
|
foreach($res as $r)
|
|
$this->states[] = $r['id_order_state'];
|
|
|
|
return $this->states;
|
|
}
|
|
}
|
|
|
|
public static function getOrderStates()
|
|
{
|
|
if(self::$states_static === null)
|
|
{
|
|
self::$states_static = OrderState::getOrderStates(Context::getContext()->language->id);
|
|
}
|
|
return self::$states_static;
|
|
}
|
|
|
|
public function add($autodate = true, $null_values = false)
|
|
{
|
|
$res = parent::add($autodate, $null_values);
|
|
$this->updateStates();
|
|
|
|
return $res;
|
|
}
|
|
|
|
public function update($null_values = false)
|
|
{
|
|
$res = parent::update($null_values);
|
|
$this->updateStates();
|
|
|
|
return $res;
|
|
}
|
|
|
|
public function updateStates()
|
|
{
|
|
if(Validate::isLoadedObject($this))
|
|
{
|
|
Db::getInstance()->delete('privatesale_stats_states_states', 'id_privatesale_stats_states = '.$this->id);
|
|
|
|
$insert = array();
|
|
foreach($this->states as $state)
|
|
$insert[] = array('id_privatesale_stats_states' => $this->id, 'id_order_state' => $state);
|
|
|
|
|
|
if(count($insert) > 0)
|
|
$res = Db::getInstance()->insert('privatesale_stats_states_states', $insert);
|
|
}
|
|
}
|
|
|
|
public static function getStatsStates()
|
|
{
|
|
$collection = new Collection('PrivateSalesStatsStates');
|
|
return $collection;
|
|
}
|
|
} |