217 lines
8.7 KiB
PHP
217 lines
8.7 KiB
PHP
<?php
|
|
/**
|
|
* Copyright ETS Software Technology Co., Ltd
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This file is not open source! Each license that you purchased is only available for 1 website only.
|
|
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
|
|
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future.
|
|
*
|
|
* @author ETS Software Technology Co., Ltd
|
|
* @copyright ETS Software Technology Co., Ltd
|
|
* @license Valid for 1 website (or project) for each purchase of license
|
|
*/
|
|
|
|
class Ets_reviewsAllModuleFrontController extends ModuleFrontController
|
|
{
|
|
/**
|
|
* @var Ets_reviews
|
|
*/
|
|
public $module;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
if (!$this->module->is17) {
|
|
if (isset($this->display_column_right)) $this->display_column_right = false;
|
|
if (isset($this->display_column_left)) $this->display_column_left = false;
|
|
}
|
|
}
|
|
|
|
public function setMedia()
|
|
{
|
|
parent::setMedia();
|
|
if (!(int)Configuration::get('ETS_RV_SLICK_LIBRARY_DISABLED')) {
|
|
//$this->addCSS($this->module->getPathUri() . 'views/css/slick.css');
|
|
//$this->addJS($this->module->getPathUri() . 'views/js/slick.js');
|
|
}
|
|
$this->addCSS($this->module->getPathUri() . 'views/css/all.css');
|
|
$this->addJS($this->module->getPathUri() . 'views/js/all.js');
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
parent::init(); // TODO: Change the autogenerated stub
|
|
if ((int)Configuration::get('ETS_RV_REVIEW_ENABLED') <= 0)
|
|
Tools::redirectLink($this->context->link->getPageLink('index', (int)Configuration::get('PS_SSL_ENABLED_EVERYWHERE')));
|
|
}
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
|
|
$list_per_pages = [
|
|
5 => '',
|
|
50 => '',
|
|
100 => '',
|
|
300 => '',
|
|
1000 => ''
|
|
];
|
|
$page = (int)Tools::getValue('page') ?: 1;
|
|
$min_per_page = 5;
|
|
$per_page = (int)Tools::getValue('per_page') ?: $min_per_page;
|
|
if ($per_page < $min_per_page)
|
|
$per_page = $min_per_page;
|
|
$currentSortBy = trim(Tools::getValue('sort_by'));
|
|
if ($currentSortBy == '' || !EtsRVDefines::getInstance()->getSortBy($currentSortBy))
|
|
$currentSortBy = 'date_add.desc';
|
|
$currentGrade = Tools::getValue('grade');
|
|
$list = EtsRVProductComment::getAllReviews($this->module->name, $currentGrade, 0, $page, $per_page, $currentSortBy, $this->context);
|
|
$total_records = EtsRVProductComment::getAllReviews($this->module->name, $currentGrade, 1, 0, 0, $currentSortBy, $this->context);
|
|
$params = [];
|
|
if ($currentGrade)
|
|
$params['grade'] = $currentGrade;
|
|
if ($currentSortBy)
|
|
$params['sort_by'] = $currentSortBy;
|
|
$paginates = EtsRVLink::getPagination($this->module->name, 'all', $total_records, $page, $per_page, $params, 7, $this->context);
|
|
if ($list_per_pages) {
|
|
foreach ($list_per_pages as $n => &$item) {
|
|
$item = $this->context->link->getModuleLink($this->module->name, 'all', ['per_page' => $n, 'page' => 1] + $params);
|
|
}
|
|
}
|
|
$page_title = $this->module->l('All Reviews', 'all');
|
|
if ($this->module->is17) {
|
|
$this->context->smarty->assign([
|
|
'page' => [
|
|
'title' => $page_title,
|
|
'canonical' => $this->getCanonicalURL(),
|
|
'meta' => array(
|
|
'title' => $page_title,
|
|
'description' => '',
|
|
'keywords' => '',
|
|
'robots' => 'index',
|
|
),
|
|
'page_name' => 'activity',
|
|
'body_classes' => array('activity-list'),
|
|
'admin_notifications' => array(),
|
|
]
|
|
]);
|
|
} else {
|
|
$breadcrumb = $this->getBreadcrumb();
|
|
$this->context->smarty->assign([
|
|
'meta_title' => $page_title,
|
|
'meta_description' => '',
|
|
'meta_keywords' => '',
|
|
'robots' => 'index',
|
|
'breadcrumb' => $breadcrumb,
|
|
'path' => $breadcrumb
|
|
]);
|
|
}
|
|
if (!$this->ajax) {
|
|
$stats = array(
|
|
'5' => array(
|
|
'id' => 'excellent',
|
|
'name' => $this->module->l('Excellent', 'all'),
|
|
'color' => '#38b6a0',
|
|
),
|
|
'4' => array(
|
|
'id' => 'good',
|
|
'name' => $this->module->l('Good', 'all'),
|
|
'color' => '#df80ff',
|
|
),
|
|
'3' => array(
|
|
'id' => 'medium',
|
|
'name' => $this->module->l('Medium', 'all'),
|
|
'color' => '#f5bf45',
|
|
),
|
|
'2' => array(
|
|
'id' => 'poor',
|
|
'name' => $this->module->l('Poor', 'all'),
|
|
'color' => '#3bbdf1',
|
|
),
|
|
'1' => array(
|
|
'id' => 'terrible',
|
|
'name' => $this->module->l('Terrible', 'all'),
|
|
'color' => '#fe8421',
|
|
),
|
|
);
|
|
$averageGrade = EtsRVProductComment::getAverageGrade();
|
|
$reviewsNb = EtsRVProductComment::getCommentsNumber();
|
|
$gradesNb = EtsRVProductComment::getGradesNumber();
|
|
foreach ($stats as $grade => &$stat) {
|
|
$gradeNbItem = EtsRVProductComment::getGradesNumber($grade);
|
|
$stat['grade_percent'] = $gradesNb > 0 ? $gradeNbItem * 100 / $gradesNb : 0;
|
|
$stat['grade_total'] = $gradeNbItem;
|
|
}
|
|
$this->context->smarty->assign([
|
|
'nb_grade' => $gradesNb,
|
|
'nb_reviews' => $reviewsNb,
|
|
'average_grade' => $averageGrade,
|
|
'grade_stats' => $stats,
|
|
'sort_by' => EtsRVDefines::getInstance()->getSortBy(),
|
|
]);
|
|
}
|
|
|
|
$this->context->smarty->assign([
|
|
'path_uri' => $this->context->link->getMediaLink(_PS_IMG_ . $this->module->name . '/r/'),
|
|
'currentIndex' => $this->context->link->getModuleLink($this->module->name, 'all', ['per_page' => $per_page, 'page' => 1], $this->ssl),
|
|
'currentGrade' => $currentGrade,
|
|
'currentSortBy' => EtsRVDefines::getInstance()->getSortBy($currentSortBy),
|
|
'list' => $list,
|
|
'total_records' => $total_records,
|
|
'paginates' => $paginates,
|
|
'list_per_pages' => $list_per_pages,
|
|
'current_per_page' => $per_page,
|
|
'show_footer_btn' => ceil($total_records / $min_per_page) > 1,
|
|
'ETS_RV_DESIGN_COLOR2' => Configuration::get('ETS_RV_DESIGN_COLOR2'),
|
|
'ETS_RV_DESIGN_COLOR1' => Configuration::get('ETS_RV_DESIGN_COLOR1'),
|
|
'ETS_RV_DESIGN_COLOR3' => Configuration::get('ETS_RV_DESIGN_COLOR3'),
|
|
'ETS_RV_DESIGN_COLOR4' => Configuration::get('ETS_RV_DESIGN_COLOR4'),
|
|
'ETS_RV_DESIGN_COLOR5' => Configuration::get('ETS_RV_DESIGN_COLOR5'),
|
|
]);
|
|
|
|
$this->setTemplate(($this->module->is17 ? 'module:' . $this->module->name . '/views/templates/front/' : '') . 'all-reviews' . ($this->module->is17 ? '' : '-16') . '.tpl');
|
|
}
|
|
|
|
public function getBreadcrumb()
|
|
{
|
|
$breadcrumb = $this->getBreadcrumbLinks();
|
|
$breadcrumb['count'] = count($breadcrumb['links']);
|
|
if ($this->module->is17)
|
|
return $breadcrumb;
|
|
else
|
|
return $this->displayBreadcrumb($breadcrumb);
|
|
}
|
|
|
|
public function displayBreadcrumb($breadcrumb)
|
|
{
|
|
$this->context->smarty->assign('breadcrumb', $breadcrumb);
|
|
return $this->context->smarty->fetch($this->module->getLocalPath() . '/views/templates/front/breadcrumb.tpl');
|
|
}
|
|
|
|
public function getBreadcrumbLinks()
|
|
{
|
|
$breadcrumb = array();
|
|
if ($this->module->is17) {
|
|
$breadcrumb['links'][] = array(
|
|
'title' => $this->module->l('Home', 'all'),
|
|
'url' => $this->context->link->getPageLink('index', true),
|
|
);
|
|
}
|
|
if (trim(Tools::getValue('controller')) == 'all') {
|
|
$breadcrumb['links'][] = array(
|
|
'title' => $this->module->l('Customer reviews', 'all'),
|
|
'url' => $this->context->link->getModuleLink('ets_reviews', 'all'),
|
|
);
|
|
}
|
|
return $breadcrumb;
|
|
}
|
|
}
|