54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
class AdvPictoProductClass extends ObjectModel
|
|
{
|
|
public $id_advpicto_product;
|
|
public $id_advpicto;
|
|
public $id_product;
|
|
public $highlight;
|
|
|
|
public static $definition = array(
|
|
'table' => 'advpicto_product',
|
|
'primary' => 'id_advpicto_product',
|
|
'multilang' => false,
|
|
'fields' => array(
|
|
'id_advpicto' => array(
|
|
'type' => ObjectModel :: TYPE_INT,
|
|
'validate' => 'isInt'
|
|
),
|
|
'id_product' => array(
|
|
'type' => ObjectModel :: TYPE_INT,
|
|
'validate' => 'isInt'
|
|
),
|
|
'highlight' => array(
|
|
'type' => ObjectModel :: TYPE_INT,
|
|
'validate' => 'isBool'
|
|
)
|
|
)
|
|
);
|
|
|
|
public function __construct($id = NULL, $id_lang = NULL, $id_shop = NULL) {
|
|
parent::__construct($id, $id_lang, $id_shop);
|
|
|
|
$this->image_dir = _PS_IMG_DIR_ . 'picto/';
|
|
}
|
|
|
|
public function add($auto_date = true, $null_values = false) {
|
|
if(AdvPictoProductClass::exist($this->id_product, $this->id_advpicto, $this->id)) {
|
|
throw new PrestaShopException('Existe déjà');
|
|
}
|
|
return parent::add($auto_date, $null_values);
|
|
}
|
|
|
|
public function update($null_values = false) {
|
|
if(AdvPictoProductClass::exist($this->id_product, $this->id_advpicto, $this->id)) {
|
|
throw new PrestaShopException('Existe déjà');
|
|
}
|
|
return parent::update($null_values);
|
|
}
|
|
|
|
public static function exist($id_product, $id_advpicto, $id_advpicto_product = null)
|
|
{
|
|
return Db::getInstance()->getValue('SELECT id_advpicto_product FROM '._DB_PREFIX_.'advpicto_product WHERE id_product = '.(int)$id_product.' AND id_advpicto = '.(int)$id_advpicto.(!is_null($id_advpicto_product) ? ' AND id_advpicto_product != '.(int)$id_advpicto_product : ''));
|
|
}
|
|
} |