260 lines
8.6 KiB
PHP
260 lines
8.6 KiB
PHP
<?php
|
|
/**
|
|
* Please read the terms of the CLUF license attached to this module(cf "licences" folder)
|
|
*
|
|
* @author Línea Gráfica E.C.E. S.L.
|
|
* @copyright Lineagrafica.es - Línea Gráfica E.C.E. S.L. all rights reserved.
|
|
* @license https://www.lineagrafica.es/licenses/license_en.pdf
|
|
* https://www.lineagrafica.es/licenses/license_es.pdf
|
|
* https://www.lineagrafica.es/licenses/license_fr.pdf
|
|
*/
|
|
|
|
class LGStoreComment extends ObjectModel
|
|
{
|
|
public $id_order;
|
|
public $id_customer;
|
|
public $id_lang;
|
|
public $stars;
|
|
public $nick;
|
|
public $title;
|
|
public $comment;
|
|
public $answer;
|
|
public $active;
|
|
public $position;
|
|
public $date;
|
|
|
|
/**a
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'lgcomments_storecomments',
|
|
'primary' => 'id_storecomment',
|
|
'multilang' => false,
|
|
'fields' => array(
|
|
'id_order' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'id_customer' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'id_lang' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'stars' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'nick' => array('type' => self::TYPE_STRING, 'size' => 255),
|
|
'title' => array('type' => self::TYPE_STRING, 'size' => 255),
|
|
'comment' => array('type' => self::TYPE_HTML),
|
|
'answer' => array('type' => self::TYPE_HTML),
|
|
'active' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'position' => array('type' => self::TYPE_INT, 'required' => true),
|
|
'date' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'required' => true),
|
|
)
|
|
);
|
|
|
|
public static function getSumShopCommentsByLang($id_lang = null)
|
|
{
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$sumL = Db::getInstance()->getValue(
|
|
'SELECT SUM(stars) AS totalcomentarios '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1'.
|
|
' AND id_lang = '.(int)$id_lang
|
|
);
|
|
return $sumL;
|
|
}
|
|
|
|
public static function getCountShopCommentsByLang($id_lang = null)
|
|
{
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$countL = Db::getInstance()->getValue(
|
|
'SELECT COUNT(id_storecomment) AS total '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1 '.
|
|
'AND id_lang = '.(int)$id_lang.''
|
|
);
|
|
return $countL;
|
|
}
|
|
|
|
public static function getRandomShopCommentByLang($id_lang = null)
|
|
{
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$randomL = Db::getInstance()->executeS(
|
|
'SELECT comment '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1 '.
|
|
'AND stars > 6 '.
|
|
'AND id_lang = '.(int)$id_lang.' '.
|
|
'ORDER BY RAND()'
|
|
);
|
|
return $randomL;
|
|
}
|
|
|
|
public static function getSumShopComments()
|
|
{
|
|
$sum = Db::getInstance()->getValue(
|
|
'SELECT SUM(stars) AS totalcomentarios '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1'
|
|
);
|
|
return $sum;
|
|
}
|
|
|
|
public static function getCountShopComments()
|
|
{
|
|
$count = Db::getInstance()->getValue(
|
|
'SELECT COUNT(id_storecomment) AS total '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1'
|
|
);
|
|
return $count;
|
|
}
|
|
|
|
public static function getRandomShopComment()
|
|
{
|
|
$random = Db::getInstance()->executeS(
|
|
'SELECT comment '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1 '.
|
|
'AND stars > 6 '.
|
|
'ORDER BY RAND()'
|
|
);
|
|
return $random;
|
|
}
|
|
|
|
/**
|
|
* @param null $min
|
|
* @param null $max
|
|
* @param int $offset
|
|
* @param null $limit
|
|
* @param null $id_lang
|
|
* @return array|false|mysqli_result|null|PDOStatement|resource
|
|
*/
|
|
public static function getReviewsByRatings($min = null, $max = null, $offset = 0, $limit = null, $id_lang = null)
|
|
{
|
|
// CARLOS: Aunque parecza absurdo la columna position (innecesaria por cierto porque va a coincidir con
|
|
// la columna id_storecomment que es la key) está ordenada por orden de inserccion
|
|
// Por lo que para que salgan ordenados por fecha, hay que invertir los órdenes
|
|
$sort_order = ((int)Configuration::get('PS_LGCOMMENTS_DISPLAY_ORDER') == 2)?'ASC':'DESC';
|
|
// if (!Tools::getIsset('ajax') && !Tools::getIsset('from-xhr')) {
|
|
// Tools::dieObject((int)Configuration::get('PS_LGCOMMENTS_DISPLAY_ORDER'), false);
|
|
// }
|
|
$sql = 'SELECT st.*'.
|
|
'FROM `'._DB_PREFIX_.'lgcomments_storecomments` st '.
|
|
'WHERE st.active = 1 ';
|
|
if (Configuration::get('PS_LGCOMMENTS_DISPLAY_LANGUAGE') == 1) {
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$sql .= 'AND st.id_lang = '.(int)$id_lang;
|
|
}
|
|
if (!is_null($min)) {
|
|
$sql .= ' AND st.stars >= '.(int)$min.' ';
|
|
}
|
|
if (!is_null($max)) {
|
|
$sql .= ' AND st.stars < '.(int)$max.' ';
|
|
}
|
|
$sql .= 'ORDER BY st.position '.$sort_order.' ';
|
|
$sql .= 'LIMIT '.((int)$offset * (int)$limit).','.(int)$limit;
|
|
// if (!Tools::getIsset('ajax') && !Tools::getIsset('from-xhr')) {
|
|
// Tools::dieObject($sql, false);
|
|
// }
|
|
$rates = Db::getInstance()->ExecuteS($sql);
|
|
// if (!Tools::getIsset('ajax') && !Tools::getIsset('from-xhr')) {
|
|
// Tools::dieObject($rates, false);
|
|
// }
|
|
return $rates;
|
|
}
|
|
|
|
/**
|
|
* Get the total sum of all star values
|
|
*
|
|
* @param null $id_lang
|
|
* @return false|null|string
|
|
*/
|
|
public static function getSumStarsValues($id_lang = null)
|
|
{
|
|
$sql = 'SELECT SUM(stars) AS totalcomentarios '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1';
|
|
|
|
if (Configuration::get('PS_LGCOMMENTS_DISPLAY_LANGUAGE') == 1) {
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$sql .= ' AND id_lang = '.(int)$id_lang;
|
|
}
|
|
|
|
$sum = Db::getInstance()->getValue($sql);
|
|
|
|
return $sum;
|
|
}
|
|
|
|
/**
|
|
* @param $min
|
|
* @param $max
|
|
* @param null $id_lang
|
|
* @return false|null|string
|
|
*/
|
|
public static function getNumReviewsByRatings($min, $max, $id_lang = null)
|
|
{
|
|
$sql = 'SELECT COUNT(id_storecomment) AS total '.
|
|
'FROM '._DB_PREFIX_.'lgcomments_storecomments '.
|
|
'WHERE active = 1 '.
|
|
' AND stars >= '.(int)$min.' '.
|
|
' AND stars < '.(int)$max.'';
|
|
|
|
if (Configuration::get('PS_LGCOMMENTS_DISPLAY_LANGUAGE') == 1) {
|
|
if (is_null($id_lang)) {
|
|
$id_lang = (int)Context::getContext()->language->id;
|
|
}
|
|
$sql .= ' AND id_lang = '.(int)$id_lang;
|
|
}
|
|
$count = Db::getInstance()->getValue($sql);
|
|
return $count;
|
|
}
|
|
|
|
public static function getReviews(
|
|
$id_lang = null,
|
|
$p = null,
|
|
$n = null,
|
|
$get_total = false
|
|
) {
|
|
if ($p < 1) {
|
|
$p = 1;
|
|
}
|
|
/* Return only the number of products */
|
|
|
|
if ($get_total) {
|
|
return self::getNumReviewsByRatings('0', '11', (int)$id_lang);
|
|
} else {
|
|
return self::getReviewsByRatings(null, null, (int)$p - 1, (int)$n, 'ASC', (int)$id_lang);
|
|
}
|
|
}
|
|
|
|
public static function getAllStoreComments()
|
|
{
|
|
$storeComments = Db::getInstance()->ExecuteS(
|
|
'SELECT * ' .
|
|
'FROM ' . _DB_PREFIX_ . 'lgcomments_storecomments ' .
|
|
'ORDER BY id_storecomment ASC'
|
|
);
|
|
return $storeComments;
|
|
}
|
|
|
|
public static function getTotalComments()
|
|
{
|
|
self::getNumReviewsByRatings('0', '11');
|
|
}
|
|
|
|
public static function allowStoreComments()
|
|
{
|
|
return Configuration::get('PS_LGCOMMENTS_OPINION_FORM') == (1 || 2);
|
|
}
|
|
|
|
public static function getLastPosition()
|
|
{
|
|
$sql = 'SELECT MAX(`position`) FROM `'._DB_PREFIX_.'lgcomments_storecomments`';
|
|
return (int)Db::getInstance()->getValue($sql) + 1;
|
|
}
|
|
}
|