129 lines
4.2 KiB
PHP
129 lines
4.2 KiB
PHP
<?php
|
|
|
|
class CmsPsCategory extends ObjectModel {
|
|
|
|
public $id_category;
|
|
public $id_parent;
|
|
public $date_add;
|
|
public $date_upd;
|
|
public $active;
|
|
|
|
public $title;
|
|
public $description;
|
|
public $slug;
|
|
public $meta_title;
|
|
public $meta_desc;
|
|
|
|
/**
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'cmsps_categories',
|
|
'primary' => 'id_category',
|
|
'multilang' => TRUE,
|
|
'multilang_shop' => TRUE,
|
|
'fields' => array(
|
|
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
|
|
|
// Lang fields
|
|
'title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName', 'required' => TRUE, 'size' => 255),
|
|
'slug' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
'description' => array('type' => self::TYPE_HTML, 'lang' => TRUE, 'validate' => 'isCleanHtml'),
|
|
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
'meta_desc' => array('type' => self::TYPE_STRING, 'lang' => TRUE, 'validate' => 'isGenericName'),
|
|
|
|
'date_add' => array('type' => self::TYPE_DATE),
|
|
'date_upd' => array('type' => self::TYPE_DATE)
|
|
),
|
|
);
|
|
|
|
public function __construct($id = NULL, $id_lang = NULL, $id_shop = NULL) {
|
|
parent::__construct($id, $id_lang, $id_shop);
|
|
$this->id_image = ($this->id && file_exists(_CMS_CAT_IMG_DIR_.(int)$this->id.'.jpg')) ? (int)$this->id : false;
|
|
$this->image_dir = _CMS_CAT_IMG_DIR_;
|
|
}
|
|
|
|
public static function getAllCategories($id_lang, $id_shop = NULL) {
|
|
$sql = '
|
|
SELECT c.*, lc.*
|
|
FROM `'._DB_PREFIX_.'cmsps_categories` c
|
|
LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_lang` lc ON c.`id_category` = lc.`id_category`
|
|
LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_shop` ls ON c.`id_category` = ls.`id_category`
|
|
WHERE lc.`id_lang` = '.(int)$id_lang;
|
|
|
|
if ($id_shop) {
|
|
$sql.= ' AND ls.`id_shop` = '.(int)$id_shop;
|
|
}
|
|
|
|
return Db::getInstance()->executeS($sql);
|
|
}
|
|
|
|
public static function getParentPossibility($id_lang, $id_shop = NULL, $id_category = NULL) {
|
|
$sql = '
|
|
SELECT c.*, lc.*
|
|
FROM `'._DB_PREFIX_.'cmsps_categories` c
|
|
LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_lang` lc ON c.`id_category` = lc.`id_category`
|
|
LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_shop` ls ON c.`id_category` = ls.`id_category`
|
|
WHERE lc.`id_lang` = '.(int)$id_lang;
|
|
|
|
if ($id_shop) {
|
|
$sql.= ' AND ls.`id_shop` = '.(int)$id_shop;
|
|
}
|
|
if ($id_category) {
|
|
$sql.= ' AND c.`id_category` != '.(int)$id_category
|
|
.' AND c.`id_parent` !='.(int)$id_category;
|
|
}
|
|
|
|
return Db::getInstance()->executeS($sql);
|
|
}
|
|
|
|
public function hasChildren() {
|
|
return (bool) Db::getInstance()->getValue('
|
|
SELECT c.`id_category`
|
|
FROM `'._DB_PREFIX_.'cmsps_categories` c
|
|
WHERE c.`id_parent` = '.(int)$this->id
|
|
);
|
|
}
|
|
|
|
public function hasPosts() {
|
|
return (bool) Db::getInstance()->getValue('
|
|
SELECT p.`id_post`
|
|
FROM `'._DB_PREFIX_.'cmsps_posts` p
|
|
WHERE p.`id_category` = '.(int)$this->id
|
|
);
|
|
}
|
|
|
|
public static function getTipsofDay($id_category, $id_lang) {
|
|
$collection_post = new Collection('CmsPsPost', $id_lang);
|
|
$collection_post->where('id_category', '=', $id_category);
|
|
$collection_post->where('active', '=', 1);
|
|
$collection_post->where('trick', '=', 1);
|
|
$collection_post->orderBy('date_add', 'DESC');
|
|
$collection_post->setPageSize(1);
|
|
$tips_category = $collection_post->getFirst();
|
|
return $tips_category;
|
|
}
|
|
|
|
public function getArticles($id_lang, $limit = 10, $num_page, $total = FALSE, $order_by = 'date_add', $filter_word = '') {
|
|
$collection_post = new Collection('CmsPsPost', $id_lang);
|
|
$collection_post->where('id_category', '=', $this->id_category);
|
|
$collection_post->where('active', '=', 1);
|
|
$collection_post->orderBy($order_by, 'DESC');
|
|
$collection_post->setPageSize($limit);
|
|
$collection_post->setPageNumber($num_page);
|
|
|
|
if ($filter_word) {
|
|
$collection_post->sqlWhere('title LIKE '.'"%'.$filter_word.'%"');
|
|
}
|
|
|
|
if($total) {
|
|
return $collection_post->count();
|
|
}
|
|
|
|
$articles = $collection_post->getResults();
|
|
return CmsPsPost::injectsData($articles, TRUE);
|
|
}
|
|
|
|
}
|