128 lines
3.8 KiB
PHP
128 lines
3.8 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Description of SaleCategory
|
||
|
*
|
||
|
* @company Antadis
|
||
|
*/
|
||
|
|
||
|
class SaleCategory extends ObjectModel{
|
||
|
|
||
|
public $id_privatesales_category;
|
||
|
public $id_parent = 0;
|
||
|
public $active;
|
||
|
public $title;
|
||
|
public $alias;
|
||
|
public $description;
|
||
|
public $sales;
|
||
|
public $link_rewrite;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @var type
|
||
|
*/
|
||
|
public static $definition = array(
|
||
|
'table' => 'privatesales_category',
|
||
|
'primary' => 'id_privatesales_category',
|
||
|
'multilang' => true,
|
||
|
'fields' => array(
|
||
|
'id_parent' => array(
|
||
|
'type' => ObjectModel :: TYPE_INT,
|
||
|
'validate' => 'isInt'
|
||
|
),
|
||
|
'active' => array(
|
||
|
'type' => ObjectModel :: TYPE_INT,
|
||
|
'validate' => 'isBool'
|
||
|
),
|
||
|
'title' => array(
|
||
|
'type' => ObjectModel :: TYPE_STRING,
|
||
|
'lang' => true,
|
||
|
'validate' => 'isString',
|
||
|
'required' => TRUE
|
||
|
),
|
||
|
'alias' => array(
|
||
|
'type' => ObjectModel :: TYPE_STRING,
|
||
|
'lang' => true,
|
||
|
'validate' => 'isString',
|
||
|
'required' => TRUE
|
||
|
),
|
||
|
'description' => array(
|
||
|
'type' => ObjectModel :: TYPE_STRING,
|
||
|
'lang' => true,
|
||
|
'validate' => 'isString'
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public function __construct($id = null, $id_lang = null, $id_shop = null){
|
||
|
|
||
|
parent::__construct($id, $id_lang, $id_shop);
|
||
|
|
||
|
$this->initExtra($id_lang);
|
||
|
|
||
|
}
|
||
|
public function getSales()
|
||
|
{
|
||
|
if (!isset($this->sales)) {
|
||
|
$this->sales = array();
|
||
|
foreach (Db::getInstance()->executeS('
|
||
|
SELECT `id_privatesales`
|
||
|
FROM `' . _DB_PREFIX_ . 'privatesales_category_sales`
|
||
|
WHERE `id_privatesales_category` = ' . $this->id . '
|
||
|
') as $sales) {
|
||
|
$this->sales[] = $sales['id_privatesales'];
|
||
|
}
|
||
|
}
|
||
|
return $this->sales;
|
||
|
}
|
||
|
|
||
|
public static function getCategoryTab($id_lang, $active = true)
|
||
|
{
|
||
|
if (!Validate::isBool($active))
|
||
|
die(Tools::displayError());
|
||
|
|
||
|
$query = 'SELECT c.`id_privatesales_category`, cl.`title`, cl.`alias`
|
||
|
FROM `'._DB_PREFIX_.'privatesales_category` c
|
||
|
LEFT JOIN `'._DB_PREFIX_.'privatesales_category_lang` cl ON (c.`id_privatesales_category` = cl.`id_privatesales_category` AND `id_lang` = '.(int)$id_lang.')
|
||
|
'.($active ? 'WHERE `active` = 1' : '').'
|
||
|
GROUP BY c.`id_privatesales_category`';
|
||
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public static function getCategory(){
|
||
|
$collection = new Collection('SaleCategory', Context::getContext()->language->id);
|
||
|
|
||
|
return $collection->getAll();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public function hydrate(array $data, $id_lang = null){
|
||
|
|
||
|
parent::hydrate($data, $id_lang);
|
||
|
$this->initExtra($id_lang);
|
||
|
}
|
||
|
|
||
|
public function initExtra($id_lang){
|
||
|
if ($id_lang !== NULL) {
|
||
|
$c = Db::getInstance()->getRow('
|
||
|
SELECT `alias`
|
||
|
FROM `' . _DB_PREFIX_ . 'privatesales_category_lang`
|
||
|
WHERE `id_privatesales_category` = ' . (int)$this->id. '
|
||
|
AND `id_lang` = ' . (int)$id_lang . '
|
||
|
');
|
||
|
$this->link_rewrite = Context::getContext()->link->getModuleLink('privatesales', 'homecat', array( 'id_sale_category' => $this->id, 'alias' => $c['alias']));
|
||
|
} else {
|
||
|
$this->link_rewrite = Context::getContext()->link->getModuleLink('privatesales', 'homecat', array( 'id_sale_category' => $this->id, 'alias' => $this->alias));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|