105 lines
3.3 KiB
PHP
105 lines
3.3 KiB
PHP
<?php
|
|
|
|
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsPost.php';
|
|
require_once _PS_MODULE_DIR_.'cmsps/classes/CmsPsCategory.php';
|
|
|
|
class CategoryCmsControllerCore extends FrontController
|
|
{
|
|
public $php_self = 'categorycms';
|
|
public $categorycms;
|
|
|
|
public $page;
|
|
public $order_by;
|
|
|
|
const PER_PAGE = 12;
|
|
|
|
public function canonicalRedirection($canonical_url = '') {
|
|
parent::canonicalRedirection($this->context->link->getCategoryCmsLink($this->categorycms->id));
|
|
}
|
|
|
|
public function init() {
|
|
$id_category_cms = Tools::getValue('id_category_cms', 0);
|
|
$this->categorycms = new CmsPsCategory($id_category_cms, $this->context->language->id);
|
|
|
|
if (!Validate::isLoadedObject($this->categorycms)
|
|
|| !$this->categorycms->active) {
|
|
header('HTTP/1.1 404 Not Found');
|
|
header('Status: 404 Not Found');
|
|
}
|
|
parent::init();
|
|
}
|
|
|
|
public function initContent() {
|
|
parent::initContent();
|
|
$id_lang = Context::getContext()->language->id;
|
|
|
|
$tipsDay = CmsPsCategory::getTipsofDay($this->categorycms->id, $id_lang);
|
|
|
|
$this->page = Tools::getValue('page', 1);
|
|
|
|
// Filter et orderBy
|
|
$filter_by = Tools::getValue('filter_by', '');
|
|
$this->order_by = Tools::getValue('order_by');
|
|
|
|
// url pagination
|
|
$url_pagination = strtok($_SERVER['REQUEST_URI'], '?');
|
|
$elem_url = array();
|
|
if (!empty($this->order_by)) {
|
|
$elem_url['order_by'] = $this->order_by;
|
|
}
|
|
if (!empty($filter_by)) {
|
|
$elem_url['filter_by'] = $filter_by;
|
|
}
|
|
if (!empty($elem_url)) {
|
|
$filter_url = http_build_query($elem_url);
|
|
} else {
|
|
$filter_url = '';
|
|
}
|
|
|
|
if ($this->order_by) {
|
|
$total = $this->categorycms->getArticles($id_lang, 9999999, 1, TRUE, $this->order_by, $filter_by);
|
|
$articles = $this->categorycms->getArticles($id_lang, self::PER_PAGE, $this->page, FALSE, $this->order_by, $filter_by);
|
|
} else {
|
|
$total = $this->categorycms->getArticles($id_lang, 9999999, 1, TRUE, 'date_add', $filter_by);
|
|
$articles = $this->categorycms->getArticles($id_lang, self::PER_PAGE, $this->page, FALSE, 'date_add', $filter_by);
|
|
}
|
|
|
|
$nb_page = ceil($total / self::PER_PAGE);
|
|
if($this->page > $nb_page) {
|
|
$this->page = $nb_page;
|
|
}
|
|
|
|
$rootCategory = CmsPsCategory::getRootCategory($this->categorycms->id);
|
|
|
|
$bestsTips = $rootCategory->getArticles($id_lang, 4, 1, FALSE, 'note');
|
|
// get all and exclude bestTips
|
|
$all_articles = $rootCategory->getArticles($id_lang, 999999, 1, FALSE, 'note');
|
|
$all_articles = array_slice($all_articles, 4, sizeof($all_articles));
|
|
|
|
$child_categories = $this->categorycms->getChildren($id_lang);
|
|
|
|
$this->context->smarty->assign(array(
|
|
'path' => Tools::getPath($this->categorycms->id, '', FALSE, 'categoriescms'),
|
|
'linkcategory' => $this->context->link->getCategoryCmsLink($this->categorycms->id),
|
|
'categorycms' => $this->categorycms,
|
|
'articles' => $articles,
|
|
'bestsTips' => $bestsTips,
|
|
'url_pagination' => $url_pagination,
|
|
'elem_url' => $elem_url,
|
|
'filter_url' => $filter_url,
|
|
'total' => $total,
|
|
'limit' => count($articles),
|
|
'nb_page' => $nb_page,
|
|
'p' => $this->page,
|
|
'tipsDay' => $tipsDay,
|
|
'all_articles' => $all_articles,
|
|
'child_categories' => $child_categories,
|
|
));
|
|
|
|
$this->setTemplate(_PS_THEME_DIR_.'categorycms.tpl');
|
|
}
|
|
|
|
public function removeqsvar($url, $varname) {
|
|
return preg_replace('/([?&])'.$varname.'=[^&]+(&|$)/','$1',$url);
|
|
}
|
|
} |