// productcomments

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8833 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone committed 2011-09-28 08:50:40 +00:00
1 parent 0db92ddae5
commit 96ed001ff3
3 files changed
+172 -163

No files matched your search

+56 -55
View File
@@ -18,8 +18,7 @@
* versions in the future. If you wish to customize PrestaShop for your * versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author Presta * @author PrestaShop SA <contact@prestashop.com>
SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA * @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7040 $ * @version Release: $Revision: 7040 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
@@ -31,58 +30,63 @@ if (!defined('_PS_VERSION_'))
class ProductComment extends ObjectModel class ProductComment extends ObjectModel
{ {
public $id; public $id;
/** @var integer Product's id */ /** @var integer Product's id */
public $id_product; public $id_product;
/** @var integer Customer's id */ /** @var integer Customer's id */
public $id_customer; public $id_customer;
/** @var integer Guest's id */ /** @var integer Guest's id */
public $id_guest; public $id_guest;
/** @var integer Customer name */ /** @var integer Customer name */
public $customer_name; public $customer_name;
/** @var string Title */ /** @var string Title */
public $title; public $title;
/** @var string Content */ /** @var string Content */
public $content; public $content;
/** @var integer Grade */ /** @var integer Grade */
public $grade; public $grade;
/** @var boolean Validate */ /** @var boolean Validate */
public $validate = 0; public $validate = 0;
public $deleted = 0; public $deleted = 0;
/** @var string Object creation date */ /** @var string Object creation date */
public $date_add; public $date_add;
protected $fieldsRequired = array('id_product', 'id_customer', 'content'); protected $fieldsRequired = array('id_product', 'id_customer', 'content');
protected $fieldsSize = array('content' => 65535); protected $fieldsSize = array('content' => 65535);
protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'id_customer' => 'isUnsignedId', 'content' => 'isMessage', protected $fieldsValidate = array(
'grade' => 'isFloat', 'validate' => 'isBool'); 'id_product' => 'isUnsignedId',
'id_customer' => 'isUnsignedId',
'content' => 'isMessage',
'grade' => 'isFloat',
'validate' => 'isBool'
);
protected $table = 'product_comment'; protected $table = 'product_comment';
protected $identifier = 'id_product_comment'; protected $identifier = 'id_product_comment';
public function getFields() public function getFields()
{ {
$this->validateFields(false); $this->validateFields(false);
$fields['id_product'] = (int)($this->id_product); $fields['id_product'] = (int)$this->id_product;
$fields['id_customer'] = (int)($this->id_customer); $fields['id_customer'] = (int)$this->id_customer;
$fields['id_guest'] = (int)($this->id_guest); $fields['id_guest'] = (int)$this->id_guest;
$fields['customer_name'] = pSQL($this->customer_name); $fields['customer_name'] = pSQL($this->customer_name);
$fields['title'] = pSQL($this->title); $fields['title'] = pSQL($this->title);
$fields['content'] = pSQL($this->content); $fields['content'] = pSQL($this->content);
$fields['grade'] = (float)($this->grade); $fields['grade'] = (float)$this->grade;
$fields['validate'] = (int)($this->validate); $fields['validate'] = (int)$this->validate;
$fields['deleted'] = (int)($this->deleted); $fields['deleted'] = (int)$this->deleted;
$fields['date_add'] = pSQL($this->date_add); $fields['date_add'] = pSQL($this->date_add);
return ($fields); return ($fields);
} }
@@ -97,11 +101,11 @@ class ProductComment extends ObjectModel
if (!Validate::isUnsignedId($id_product)) if (!Validate::isUnsignedId($id_product))
die(Tools::displayError()); die(Tools::displayError());
$validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE');
$p = (int)($p); $p = (int)$p;
$n = (int)($n); $n = (int)$n;
if ($p <= 1) if ($p <= 1)
$p = 1; $p = 1;
if ($n != null AND $n <= 0) if ($n != null && $n <= 0)
$n = 5; $n = 5;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -128,7 +132,8 @@ class ProductComment extends ObjectModel
$results = Db::getInstance()->ExecuteS(' $results = Db::getInstance()->ExecuteS('
SELECT * SELECT *
FROM `'._DB_PREFIX_.'product_comment` pc FROM `'._DB_PREFIX_.'product_comment` pc
WHERE pc.`id_product` = '.(int)($id_product).' AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)($id_customer) : 'pc.`id_guest` = '.(int)($id_guest)).' WHERE pc.`id_product` = '.(int)$id_product.'
AND '.(!$id_guest ? 'pc.`id_customer` = '.(int)$id_customer : 'pc.`id_guest` = '.(int)$id_guest).'
ORDER BY pc.`date_add` DESC ' ORDER BY pc.`date_add` DESC '
.($last ? 'LIMIT 1' : '') .($last ? 'LIMIT 1' : '')
); );
@@ -158,8 +163,8 @@ class ProductComment extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'product_comment_grade` pcg ON (pcg.`id_product_comment` = pc.`id_product_comment`) LEFT JOIN `'._DB_PREFIX_.'product_comment_grade` pcg ON (pcg.`id_product_comment` = pc.`id_product_comment`)
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion` pcc ON (pcc.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`) LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion` pcc ON (pcc.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`)
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pccl.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`) LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pccl.`id_product_comment_criterion` = pcg.`id_product_comment_criterion`)
WHERE pc.`id_product` = '.(int)($id_product).' WHERE pc.`id_product` = '.(int)$id_product.'
AND pccl.`id_lang` = '.(int)($id_lang). AND pccl.`id_lang` = '.(int)$id_lang.
($validate == '1' ? ' AND pc.`validate` = 1' : ''))); ($validate == '1' ? ' AND pc.`validate` = 1' : '')));
} }
@@ -168,14 +173,9 @@ class ProductComment extends ObjectModel
$validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT SUM(pc.`grade`) / SELECT (SUM(pc.`grade`) / COUNT(pc.`grade`)) AS grade
(SELECT COUNT(pc.`grade`)
FROM `'._DB_PREFIX_.'product_comment` pc
WHERE pc.`id_product` = '.(int)($id_product).'
AND pc.`deleted` = 0'.
($validate == '1' ? ' AND pc.`validate` = 1' : '').') AS grade
FROM `'._DB_PREFIX_.'product_comment` pc FROM `'._DB_PREFIX_.'product_comment` pc
WHERE pc.`id_product` = '.(int)($id_product).' WHERE pc.`id_product` = '.(int)$id_product.'
AND pc.`deleted` = 0'. AND pc.`deleted` = 0'.
($validate == '1' ? ' AND pc.`validate` = 1' : '')); ($validate == '1' ? ' AND pc.`validate` = 1' : ''));
} }
@@ -183,14 +183,15 @@ class ProductComment extends ObjectModel
public static function getAveragesByProduct($id_product, $id_lang) public static function getAveragesByProduct($id_product, $id_lang)
{ {
/* Get all grades */ /* Get all grades */
$grades = ProductComment::getGradeByProduct((int)($id_product), (int)($id_lang)); $grades = ProductComment::getGradeByProduct((int)$id_product, (int)$id_lang);
$total = ProductComment::getGradedCommentNumber((int)($id_product)); $total = ProductComment::getGradedCommentNumber((int)$id_product);
if (!sizeof($grades) OR (!$total)) if (!count($grades) || (!$total))
return array(); return array();
/* Addition grades for each criterion */ /* Addition grades for each criterion */
$criterionsGradeTotal = array(); $criterionsGradeTotal = array();
for ($i = 0; $i < count($grades); ++$i) $count_grades = count($grades);
for ($i = 0; $i < $count_grades; ++$i)
if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false) if (array_key_exists($grades[$i]['id_product_comment_criterion'], $criterionsGradeTotal) === false)
$criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = (int)($grades[$i]['grade']); $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = (int)($grades[$i]['grade']);
else else
@@ -198,7 +199,7 @@ class ProductComment extends ObjectModel
/* Finally compute the averages */ /* Finally compute the averages */
$averages = array(); $averages = array();
foreach ($criterionsGradeTotal AS $key => $criterionGradeTotal) foreach ($criterionsGradeTotal as $key => $criterionGradeTotal)
$averages[(int)($key)] = (int)($total) ? ((int)($criterionGradeTotal) / (int)($total)) : 0; $averages[(int)($key)] = (int)($total) ? ((int)($criterionGradeTotal) / (int)($total)) : 0;
return $averages; return $averages;
} }
@@ -212,7 +213,7 @@ class ProductComment extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_product)) if (!Validate::isUnsignedId($id_product))
die(Tools::displayError()); die(Tools::displayError());
$validate = (int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')); $validate = (int)Configuration::get('PRODUCT_COMMENTS_MODERATE');
if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(`id_product_comment`) AS "nbr" SELECT COUNT(`id_product_comment`) AS "nbr"
FROM `'._DB_PREFIX_.'product_comment` pc FROM `'._DB_PREFIX_.'product_comment` pc
@@ -230,7 +231,7 @@ class ProductComment extends ObjectModel
{ {
if (!Validate::isUnsignedId($id_product)) if (!Validate::isUnsignedId($id_product))
die(Tools::displayError()); die(Tools::displayError());
$validate = (int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')); $validate = (int)Configuration::get('PRODUCT_COMMENTS_MODERATE');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(pc.`id_product`) AS nbr SELECT COUNT(pc.`id_product`) AS nbr
@@ -252,7 +253,7 @@ class ProductComment extends ObjectModel
FROM `'._DB_PREFIX_.'product_comment` pc FROM `'._DB_PREFIX_.'product_comment` pc
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`) LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = pc.`id_customer`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Context::getContext()->shop->sqlLang('pl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = pc.`id_product` AND pl.`id_lang` = '.(int)Context::getContext()->language->id.Context::getContext()->shop->sqlLang('pl').')
WHERE pc.`validate` = '.(int)($validate).' WHERE pc.`validate` = '.(int)$validate.'
ORDER BY pc.`date_add` DESC')); ORDER BY pc.`date_add` DESC'));
} }
@@ -282,8 +283,8 @@ class ProductComment extends ObjectModel
die(Tools::displayError()); die(Tools::displayError());
return (Db::getInstance()->Execute(' return (Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'product_comment` SET UPDATE `'._DB_PREFIX_.'product_comment` SET
`validate` = '.(int)($validate).' `validate` = '.(int)$validate.'
WHERE `id_product_comment` = '.(int)($this->id))); WHERE `id_product_comment` = '.(int)$this->id));
} }
/** /**
@@ -297,7 +298,7 @@ class ProductComment extends ObjectModel
die(Tools::displayError()); die(Tools::displayError());
return (Db::getInstance()->Execute(' return (Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_grade` DELETE FROM `'._DB_PREFIX_.'product_comment_grade`
WHERE `id_product_comment` = '.(int)($id_product_comment))); WHERE `id_product_comment` = '.(int)$id_product_comment));
} }
/** /**
@@ -311,7 +312,7 @@ class ProductComment extends ObjectModel
die(Tools::displayError()); die(Tools::displayError());
return (Db::getInstance()->Execute(' return (Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_report` DELETE FROM `'._DB_PREFIX_.'product_comment_report`
WHERE `id_product_comment` = '.(int)($id_product_comment))); WHERE `id_product_comment` = '.(int)$id_product_comment));
} }
/** /**
@@ -326,7 +327,7 @@ class ProductComment extends ObjectModel
return (Db::getInstance()->Execute(' return (Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'product_comment_usefulness` DELETE FROM `'._DB_PREFIX_.'product_comment_usefulness`
WHERE `id_product_comment` = '.(int)($id_product_comment))); WHERE `id_product_comment` = '.(int)$id_product_comment));
} }
/** /**
@@ -351,8 +352,8 @@ class ProductComment extends ObjectModel
return (bool)Db::getInstance()->getValue(' return (bool)Db::getInstance()->getValue('
SELECT COUNT(*) SELECT COUNT(*)
FROM `'._DB_PREFIX_.'product_comment_report` FROM `'._DB_PREFIX_.'product_comment_report`
WHERE `id_customer` = '.(int)($id_customer).' WHERE `id_customer` = '.(int)$id_customer.'
AND `id_product_comment` = '.(int)($id_product_comment)); AND `id_product_comment` = '.(int)$id_product_comment);
} }
/** /**
@@ -377,8 +378,8 @@ class ProductComment extends ObjectModel
return (bool)Db::getInstance()->getValue(' return (bool)Db::getInstance()->getValue('
SELECT COUNT(*) SELECT COUNT(*)
FROM `'._DB_PREFIX_.'product_comment_usefulness` FROM `'._DB_PREFIX_.'product_comment_usefulness`
WHERE `id_customer` = '.(int)($id_customer).' WHERE `id_customer` = '.(int)$id_customer.'
AND `id_product_comment` = '.(int)($id_product_comment)); AND `id_product_comment` = '.(int)$id_product_comment);
} }
/** /**
@@ -33,20 +33,24 @@ include_once(dirname(__FILE__).'/productcomments.php');
$productCom = new productcomments(); $productCom = new productcomments();
if (Tools::getValue('action') AND Tools::getValue('id_product_comment') AND Context::getContext()->cookie->id_customer) if (Tools::getValue('action') && Tools::getValue('id_product_comment') && Context::getContext()->cookie->id_customer)
{ {
if (Tools::getValue('action') == 'report') if (Tools::getValue('action') == 'report')
{ {
if (!ProductComment::isAlreadyReport(Tools::getValue('id_product_comment'), Context::getContext()->cookie->id_customer) AND ProductComment::reportComment((int)Tools::getValue('id_product_comment'), (int)Context::getContext()->cookie->id_customer)) if (!ProductComment::isAlreadyReport(Tools::getValue('id_product_comment'), Context::getContext()->cookie->id_customer) &&
ProductComment::reportComment((int)Tools::getValue('id_product_comment'), (int)Context::getContext()->cookie->id_customer))
die('0'); die('0');
} }
elseif (Tools::getValue('action') == 'usefulness' AND Tools::getValue('value') AND Tools::getValue('value')) else if (Tools::getValue('action') == 'usefulness' && Tools::getValue('value') && Tools::getValue('value'))
{ {
if (!ProductComment::isAlreadyUsefulness(Tools::getValue('id_product_comment'), Context::getContext()->cookie->id_customer) AND ProductComment::setCommentUsefulness((int)Tools::getValue('id_product_comment'), (bool)((int)Tools::getValue('value')), Context::getContext()->cookie->id_customer)) if (!ProductComment::isAlreadyUsefulness(Tools::getValue('id_product_comment'), Context::getContext()->cookie->id_customer) &&
ProductComment::setCommentUsefulness((int)Tools::getValue('id_product_comment'),
(bool)Tools::getValue('value'),
Context::getContext()->cookie->id_customer))
die('0'); die('0');
} }
} }
elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productCom->secure_key) else if (Tools::getValue('action') && Tools::getValue('secure_key') == $productCom->secure_key)
{ {
$review = Tools::jsonDecode(Tools::getValue('review')); $review = Tools::jsonDecode(Tools::getValue('review'));
$id_product = 0; $id_product = 0;
@@ -56,39 +60,39 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
$grades = array(); $grades = array();
foreach ($review as $entry) foreach ($review as $entry)
{ {
if ($entry->key == "id_product") if ($entry->key == 'id_product')
$id_product = $entry->value; $id_product = $entry->value;
elseif ($entry->key == "title") else if ($entry->key == 'title')
$title = $entry->value; $title = $entry->value;
elseif ($entry->key == "content") else if ($entry->key == 'content')
$content = $entry->value; $content = $entry->value;
elseif ($entry->key == "customer_name") else if ($entry->key == 'customer_name')
$name = $entry->value; $name = $entry->value;
elseif (preg_match("/grade/", $entry->key)) else if (strstr($entry->key, 'grade'))
{ {
$id = array(preg_split("/_/", $entry->key)); $id = array(explode('_', $entry->key));
$grades[] = array('id' => $id['0']['0'], 'grade' => $entry->value); $grades[] = array('id' => $id['0']['0'], 'grade' => $entry->value);
} }
} }
if ($title == "" OR $content == "" OR !$id_product OR count($grades) == 0) if ($title == '' || $content == '' || !$id_product || count($grades) == 0)
die('0'); die('0');
$allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'); $allow_guests = (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS');
if (Context::getContext()->customer->id OR (!Context::getContext()->customer->id AND $allow_guests)) if (Context::getContext()->customer->id || (!Context::getContext()->customer->id && $allow_guests))
{ {
$id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false; $id_guest = (!$id_customer = (int)Context::getContext()->cookie->id_customer) ? (int)Context::getContext()->cookie->id_guest : false;
$customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest); $customerComment = ProductComment::getByCustomer((int)($id_product), Context::getContext()->cookie->id_customer, true, (int)$id_guest);
if (!$customerComment OR ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time())) if (!$customerComment || ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) < time()))
{ {
$errors = array(); $errors = array();
$customer_name = false; $customer_name = false;
if ($id_guest AND (!$customer_name = Context::getContext()->customer->firstname . " " . Context::getContext()->customer->lastname)) if ($id_guest && (!$customer_name = Context::getContext()->customer->firstname.' '.Context::getContext()->customer->lastname))
$errors[] = $productCom->l('Please fill your name'); $errors[] = $productCom->l('Please fill your name');
if (!sizeof($errors) AND $content) if (!count($errors) && $content)
{ {
$comment = new ProductComment(); $comment = new ProductComment();
$comment->content = strip_tags($content); $comment->content = strip_tags($content);
@@ -102,28 +106,25 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC
$comment->grade = 0; $comment->grade = 0;
$comment->validate = 0; $comment->validate = 0;
if (!$comment->content)
$errors[] = $productCom->l('Invalid comment text posted.'); $tgrade = 0;
else $comment->save();
foreach ($grades as $grade)
{ {
$tgrade = 0; $tgrade += $grade['grade'];
$comment->save(); $productCommentCriterion = new ProductCommentCriterion((int)Tools::getValue('id_product_comment_criterion_'.$grade['id']));
foreach ($grades as $grade) if ($productCommentCriterion->id)
{ $productCommentCriterion->addGrade($comment->id, $grade['grade']);
$tgrade += $grade['grade'];
$productCommentCriterion = new ProductCommentCriterion((int)Tools::getValue('id_product_comment_criterion_'.$grade['id']));
if ($productCommentCriterion->id)
$productCommentCriterion->addGrade($comment->id, $grade['grade']);
}
if ((count($grades) - 1) >= 0)
$comment->grade = (int)($tgrade / ((int)count($grades)));
if (!$comment->save())
$errors[] = $productCom->l('An error occurred while saving your comment.');
else
Context::getContext()->smarty->assign('confirmation', $productCom->l('Comment posted.').((int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')) ? ' '.$productCom->l('Awaiting moderator validation.') : ''));
} }
if ((count($grades) - 1) >= 0)
$comment->grade = (int)($tgrade / ((int)count($grades)));
if (!$comment->save())
$errors[] = $productCom->l('An error occurred while saving your comment.');
else
Context::getContext()->smarty->assign('confirmation', $productCom->l('Comment posted.').((int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')) ? ' '.$productCom->l('Awaiting moderator validation.') : ''));
} }
else else
$errors[] = $productCom->l('Comment text is required.'); $errors[] = $productCom->l('Comment text is required.');
+79 -72
View File
@@ -57,32 +57,38 @@ class ProductComments extends Module
{ {
if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
return false; return false;
elseif (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) else if (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE))
return false; return false;
$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
$sql = preg_split("/;\s*[\r\n]+/", trim($sql)); $sql = preg_split("/;\s*[\r\n]+/", trim($sql));
foreach ($sql AS $query) foreach ($sql as $query)
if (!Db::getInstance()->Execute(trim($query))) if (!Db::getInstance()->Execute(trim($query)))
return false; return false;
if (parent::install() == false if (parent::install() == false ||
OR !$this->registerHook('productTab') !$this->registerHook('productTab') ||
OR !$this->registerHook('extraProductComparison') OR !$this->registerHook('productTabContent') !$this->registerHook('extraProductComparison') ||
OR !$this->registerHook('header') OR !$this->registerHook('productOutOfStock') !$this->registerHook('productTabContent') ||
OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30) !$this->registerHook('header') ||
OR !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0) !$this->registerHook('productOutOfStock') ||
OR !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1)) !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30) ||
!Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0) ||
!Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1))
return false; return false;
return true; return true;
} }
public function uninstall() public function uninstall()
{ {
if (!parent::uninstall() OR !$this->deleteTables() if (!parent::uninstall() || !$this->deleteTables() ||
OR !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE') !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE') ||
OR !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') OR !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME') !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') ||
OR !$this->unregisterHook('extraProductComparison') OR !$this->unregisterHook('productOutOfStock') OR !$this->unregisterHook('productTabContent') !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME') ||
OR !$this->unregisterHook('header') OR !$this->unregisterHook('productTab')) !$this->unregisterHook('extraProductComparison') ||
!$this->unregisterHook('productOutOfStock') ||
!$this->unregisterHook('productTabContent') ||
!$this->unregisterHook('header') ||
!$this->unregisterHook('productTab'))
return false; return false;
return true; return true;
} }
@@ -110,7 +116,7 @@ class ProductComments extends Module
Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', (int)Tools::getValue('product_comments_minimal_time')); Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', (int)Tools::getValue('product_comments_minimal_time'));
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>'; $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
} }
if ($id_criterion = (int)Tools::getValue('deleteCriterion')) if ($id_criterion = (int)Tools::getValue('deleteCriterion'))
{ {
$productCommentCriterion = new ProductCommentCriterion((int)$id_criterion); $productCommentCriterion = new ProductCommentCriterion((int)$id_criterion);
if ($productCommentCriterion->id) if ($productCommentCriterion->id)
@@ -139,7 +145,7 @@ class ProductComments extends Module
private function _setBaseUrl() private function _setBaseUrl()
{ {
$this->_baseUrl = 'index.php?'; $this->_baseUrl = 'index.php?';
foreach ($_GET AS $k => $value) foreach ($_GET as $k => $value)
if (!in_array($k, array('deleteCriterion', 'editCriterion'))) if (!in_array($k, array('deleteCriterion', 'editCriterion')))
$this->_baseUrl .= $k.'='.$value.'&'; $this->_baseUrl .= $k.'='.$value.'&';
$this->_baseUrl = rtrim($this->_baseUrl, '&'); $this->_baseUrl = rtrim($this->_baseUrl, '&');
@@ -148,18 +154,17 @@ class ProductComments extends Module
private function _checkModerateComment() private function _checkModerateComment()
{ {
$action = Tools::getValue('action'); $action = Tools::getValue('action');
if (empty($action) === false && if (empty($action) === false && (int)Configuration::get('PRODUCT_COMMENTS_MODERATE'))
(int)(Configuration::get('PRODUCT_COMMENTS_MODERATE')))
{ {
$product_comments = Tools::getValue('id_product_comment'); $product_comments = Tools::getValue('id_product_comment');
if (sizeof($product_comments)) if (count($product_comments))
{ {
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
switch ($action) switch ($action)
{ {
case 'accept': case 'accept':
foreach ($product_comments AS $id_product_comment) foreach ($product_comments as $id_product_comment)
{ {
if (!$id_product_comment) if (!$id_product_comment)
continue; continue;
@@ -167,8 +172,9 @@ class ProductComments extends Module
$comment->validate(); $comment->validate();
} }
break; break;
case 'delete': case 'delete':
foreach ($product_comments AS $id_product_comment) foreach ($product_comments as $id_product_comment)
{ {
if (!$id_product_comment) if (!$id_product_comment)
continue; continue;
@@ -177,6 +183,7 @@ class ProductComments extends Module
ProductComment::deleteGrades((int)$id_product_comment); ProductComment::deleteGrades((int)$id_product_comment);
} }
break; break;
default: default:
; ;
} }
@@ -191,13 +198,13 @@ class ProductComments extends Module
{ {
$product_comments = Tools::getValue('id_product_comment'); $product_comments = Tools::getValue('id_product_comment');
if (sizeof($product_comments)) if (count($product_comments))
{ {
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
switch ($action) switch ($action)
{ {
case 'accept': case 'accept':
foreach ($product_comments AS $id_product_comment) foreach ($product_comments as $id_product_comment)
{ {
if (!$id_product_comment) if (!$id_product_comment)
continue; continue;
@@ -207,7 +214,7 @@ class ProductComments extends Module
} }
break; break;
case 'delete': case 'delete':
foreach ($product_comments AS $id_product_comment) foreach ($product_comments as $id_product_comment)
{ {
if (!$id_product_comment) if (!$id_product_comment)
continue; continue;
@@ -235,7 +242,7 @@ class ProductComments extends Module
$languages = Language::getLanguages(); $languages = Language::getLanguages();
$id_criterion = (int)Tools::getValue('id_product_comment_criterion'); $id_criterion = (int)Tools::getValue('id_product_comment_criterion');
$productCommentCriterion = new ProductCommentCriterion((int)$id_criterion); $productCommentCriterion = new ProductCommentCriterion((int)$id_criterion);
foreach ($languages AS $lang) foreach ($languages as $lang)
$productCommentCriterion->name[(int)$lang['id_lang']] = Tools::getValue('criterion_'.(int)$lang['id_lang']); $productCommentCriterion->name[(int)$lang['id_lang']] = Tools::getValue('criterion_'.(int)$lang['id_lang']);
// Check default language criterion name // Check default language criterion name
@@ -252,7 +259,7 @@ class ProductComments extends Module
if ($productCommentCriterion->save()) if ($productCommentCriterion->save())
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.(Tools::getValue('editCriterion') ? $this->l('Criterion updated') : $this->l('Criterion added')).'</div>'; $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.(Tools::getValue('editCriterion') ? $this->l('Criterion updated') : $this->l('Criterion added')).'</div>';
} }
elseif (!empty($action_criterion) AND empty($name)) else if (!empty($action_criterion) && empty($name))
{ {
$id_product_comment_criterion = Tools::getValue('id_product_comment_criterion'); $id_product_comment_criterion = Tools::getValue('id_product_comment_criterion');
require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
@@ -286,16 +293,16 @@ class ProductComments extends Module
{ {
$productCommentCriterion->deleteCategories(); $productCommentCriterion->deleteCategories();
if ($categories = Tools::getValue('id_product')) if ($categories = Tools::getValue('id_product'))
if (sizeof($categories)) if (count($categories))
foreach ($categories AS $id_category) foreach ($categories as $id_category)
$productCommentCriterion->addCategory((int)$id_category); $productCommentCriterion->addCategory((int)$id_category);
} }
elseif ($productCommentCriterion->id_product_comment_criterion_type == 3) else if ($productCommentCriterion->id_product_comment_criterion_type == 3)
{ {
$productCommentCriterion->deleteProducts(); $productCommentCriterion->deleteProducts();
if ($products = Tools::getValue('id_product')) if ($products = Tools::getValue('id_product'))
if (sizeof($products)) if (count($products))
foreach ($products AS $product) foreach ($products as $product)
$productCommentCriterion->addProduct((int)$product); $productCommentCriterion->addProduct((int)$product);
} }
} }
@@ -354,7 +361,7 @@ class ProductComments extends Module
{ {
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
$comments = ProductComment::getByValidate(); $comments = ProductComment::getByValidate();
if (sizeof($comments)) if (count($comments))
{ {
$this->_html .= ' $this->_html .= '
<form action="'.$this->_baseUrl.'" method="post" name="comment_form"> <form action="'.$this->_baseUrl.'" method="post" name="comment_form">
@@ -371,7 +378,7 @@ class ProductComments extends Module
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($comments AS $comment) foreach ($comments as $comment)
$this->_html .= '<tr> $this->_html .= '<tr>
<td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="id_product_comment[]" /></td> <td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="id_product_comment[]" /></td>
<td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td> <td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td>
@@ -403,7 +410,7 @@ class ProductComments extends Module
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
$comments = ProductComment::getReportedComments(); $comments = ProductComment::getReportedComments();
if (sizeof($comments)) if (count($comments))
{ {
$this->_html .= ' $this->_html .= '
<form action="'.$this->_baseUrl.'" method="post" name="comment_form"> <form action="'.$this->_baseUrl.'" method="post" name="comment_form">
@@ -420,7 +427,7 @@ class ProductComments extends Module
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($comments AS $comment) foreach ($comments as $comment)
$this->_html .= '<tr> $this->_html .= '<tr>
<td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="id_product_comment[]" /></td> <td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="id_product_comment[]" /></td>
<td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td> <td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td>
@@ -461,7 +468,7 @@ class ProductComments extends Module
<label>'.$this->l('Name').'</label> <label>'.$this->l('Name').'</label>
<div class="margin-form"> <div class="margin-form">
<input type="hidden" name="id_product_comment_criterion" value="'.(int)$criterion->id.'" />'; <input type="hidden" name="id_product_comment_criterion" value="'.(int)$criterion->id.'" />';
foreach ($langs AS $lang) foreach ($langs as $lang)
$this->_html .= ' $this->_html .= '
<div id="criterion_'.(int)$lang['id_lang'].'" style="display: '.($lang['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;"> <div id="criterion_'.(int)$lang['id_lang'].'" style="display: '.($lang['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input value="'.$criterion->name[(int)$lang['id_lang']].'" type="text" class="text" name="criterion_'.(int)$lang['id_lang'].'" /> <input value="'.$criterion->name[(int)$lang['id_lang']].'" type="text" class="text" name="criterion_'.(int)$lang['id_lang'].'" />
@@ -473,8 +480,8 @@ class ProductComments extends Module
<label for="criterion_type">'.$this->l('Apply to').'</label> <label for="criterion_type">'.$this->l('Apply to').'</label>
<div class="margin-form"> <div class="margin-form">
<select name="criterion_type">'; <select name="criterion_type">';
foreach ($this->_productCommentsCriterionTypes AS $k => $type) foreach ($this->_productCommentsCriterionTypes as $k => $type)
$this->_html.= '<option value="'.(int)$k.'" '.($k == $criterion->id_product_comment_criterion_type ? 'selected="selected"' : '').'>'.$type.'</option>'; $this->_html .= '<option value="'.(int)$k.'" '.($k == $criterion->id_product_comment_criterion_type ? 'selected="selected"' : '').'>'.$type.'</option>';
$this->_html .= '</select> $this->_html .= '</select>
</div> </div>
<label>'.$this->l('Active').'</label> <label>'.$this->l('Active').'</label>
@@ -490,9 +497,9 @@ class ProductComments extends Module
</form>'; </form>';
require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
$criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id); $criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id);
if (sizeof($criterions)) if (count($criterions))
{ {
$this->_html.= '<br /> $this->_html .= '<br />
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
@@ -504,7 +511,7 @@ class ProductComments extends Module
</thead> </thead>
<tbody>'; <tbody>';
foreach ($criterions AS $criterion) foreach ($criterions as $criterion)
{ {
$this->_html .= '<tr> $this->_html .= '<tr>
<td>'.$criterion['name'].'</td> <td>'.$criterion['name'].'</td>
@@ -533,18 +540,18 @@ class ProductComments extends Module
$categories = Category::getSimpleCategories(Context::getContext()->language->id); $categories = Category::getSimpleCategories(Context::getContext()->language->id);
$criterion_categories = $criterion->getCategories(); $criterion_categories = $criterion->getCategories();
} }
elseif ($criterion->id_product_comment_criterion_type == 3) else if ($criterion->id_product_comment_criterion_type == 3)
{ {
$criterion_products = $criterion->getProducts(); $criterion_products = $criterion->getProducts();
$products = Product::getSimpleProducts(Context::getContext()->language->id); $products = Product::getSimpleProducts(Context::getContext()->language->id);
} }
} }
foreach ($criterions AS $key => $foo) foreach ($criterions as $key => $foo)
if ($foo['id_product_comment_criterion_type'] == 1) if ($foo['id_product_comment_criterion_type'] == 1)
unset($criterions[$key]); unset($criterions[$key]);
if (sizeof($criterions)) if (count($criterions))
{ {
$this->_html .= ' $this->_html .= '
<fieldset class="width2"> <fieldset class="width2">
@@ -556,13 +563,13 @@ class ProductComments extends Module
"> ">
<select name="id_product_comment_criterion" id="id_product_comment_criterion" onchange="window.location=\''.$this->_baseUrl.'&updateCriterion=\'+$(\'#id_product_comment_criterion option:selected\').val()"> <select name="id_product_comment_criterion" id="id_product_comment_criterion" onchange="window.location=\''.$this->_baseUrl.'&updateCriterion=\'+$(\'#id_product_comment_criterion option:selected\').val()">
<option value="--">-- '.$this->l('Choose a criterion').' --</option>'; <option value="--">-- '.$this->l('Choose a criterion').' --</option>';
foreach ($criterions AS $foo) foreach ($criterions as $foo)
$this->_html .= '<option value="'.(int)($foo['id_product_comment_criterion']).'" '.($foo['id_product_comment_criterion'] == $id_criterion ? 'selected="selected"' : '').'>'.$foo['name'].'</option>'; $this->_html .= '<option value="'.(int)($foo['id_product_comment_criterion']).'" '.($foo['id_product_comment_criterion'] == $id_criterion ? 'selected="selected"' : '').'>'.$foo['name'].'</option>';
$this->_html .= '</select> $this->_html .= '</select>
</div> </div>
</form>'; </form>';
if ($id_criterion AND $criterion->id_product_comment_criterion_type != 1) if ($id_criterion && $criterion->id_product_comment_criterion_type != 1)
{ {
$this->_html .='<label for="id_product_comment_criterion">'.($criterion->id_product_comment_criterion_type == 3 ? $this->l('Products') : $this->l('Categories')).'</label> $this->_html .='<label for="id_product_comment_criterion">'.($criterion->id_product_comment_criterion_type == 3 ? $this->l('Products') : $this->l('Categories')).'</label>
<form action="'.$this->_baseUrl.'" method="post" name="comment_form"> <form action="'.$this->_baseUrl.'" method="post" name="comment_form">
@@ -579,11 +586,11 @@ class ProductComments extends Module
<tbody>'; <tbody>';
if ($criterion->id_product_comment_criterion_type == 3) if ($criterion->id_product_comment_criterion_type == 3)
foreach ($products AS $product) foreach ($products as $product)
$this->_html .='<tr><td><input class="noborder" type="checkbox" value="'.(int)$product['id_product'].'" name="id_product[]" '.(in_array($product['id_product'], $criterion_products) ? 'checked="checked"' : '').' /></td> $this->_html .='<tr><td><input class="noborder" type="checkbox" value="'.(int)$product['id_product'].'" name="id_product[]" '.(in_array($product['id_product'], $criterion_products) ? 'checked="checked"' : '').' /></td>
<td>'.(int)$product['id_product'].'</td><td>'.$product['name'].'</td></tr>'; <td>'.(int)$product['id_product'].'</td><td>'.$product['name'].'</td></tr>';
elseif ($criterion->id_product_comment_criterion_type == 2) else if ($criterion->id_product_comment_criterion_type == 2)
foreach ($categories AS $category) foreach ($categories as $category)
$this->_html .='<tr><td><input class="noborder" type="checkbox" value="'.(int)$category['id_category'].'" name="id_product[]" '.(in_array($category['id_category'], $criterion_categories) ? 'checked="checked"' : '').' /></td> $this->_html .='<tr><td><input class="noborder" type="checkbox" value="'.(int)$category['id_category'].'" name="id_product[]" '.(in_array($category['id_category'], $criterion_categories) ? 'checked="checked"' : '').' /></td>
<td>'.(int)$category['id_category'].'</td><td>'.$category['name'].'</td></tr>'; <td>'.(int)$category['id_category'].'</td><td>'.$category['name'].'</td></tr>';
$this->_html .='</tbody> $this->_html .='</tbody>
@@ -607,7 +614,7 @@ class ProductComments extends Module
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
$comments = ProductComment::getAll(); $comments = ProductComment::getAll();
if (sizeof($comments)) if (count($comments))
{ {
$this->_html .= ' $this->_html .= '
<form action="'.$this->_baseUrl.'" method="post" name="delete_comment_form"> <form action="'.$this->_baseUrl.'" method="post" name="delete_comment_form">
@@ -623,7 +630,7 @@ class ProductComments extends Module
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach ($comments AS $comment) foreach ($comments as $comment)
$this->_html .= '<tr> $this->_html .= '<tr>
<td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="delete_id_product_comment[]" /></td> <td><input class="noborder" type="checkbox" value="'.$comment['id_product_comment'].'" name="delete_id_product_comment[]" /></td>
<td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td> <td>'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.</td>
@@ -652,12 +659,12 @@ class ProductComments extends Module
{ {
$product_comments = Tools::getValue('delete_id_product_comment'); $product_comments = Tools::getValue('delete_id_product_comment');
if (sizeof($product_comments)) if (count($product_comments))
{ {
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
if ($action == 'delete') if ($action == 'delete')
{ {
foreach ($product_comments AS $id_product_comment) foreach ($product_comments as $id_product_comment)
{ {
if (!$id_product_comment) if (!$id_product_comment)
continue; continue;
@@ -671,15 +678,15 @@ class ProductComments extends Module
} }
public function hookProductTab($params) public function hookProductTab($params)
{ {
require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductComment.php');
require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php');
Context::getContext()->smarty->assign(array( Context::getContext()->smarty->assign(array(
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'comments' => ProductComment::getByProduct((int)($_GET['id_product'])), 'comments' => ProductComment::getByProduct((int)(Tools::getValue('id_product'))),
'criterions' => ProductCommentCriterion::getByProduct((int)($_GET['id_product']), Context::getContext()->language->id), 'criterions' => ProductCommentCriterion::getByProduct((int)(Tools::getValue('id_product')), Context::getContext()->language->id),
'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product']))))); 'nbComments' => (int)(ProductComment::getCommentNumber((int)(Tools::getValue('id_product'))))));
return ($this->display(__FILE__, '/tab.tpl')); return ($this->display(__FILE__, '/tab.tpl'));
} }
@@ -694,7 +701,7 @@ class ProductComments extends Module
$average = ProductComment::getAverageGrade((int)Tools::getValue('id_product')); $average = ProductComment::getAverageGrade((int)Tools::getValue('id_product'));
$image = Product::getCover((int)($_GET['id_product'])); $image = Product::getCover((int)Tools::getValue('id_product'));
Context::getContext()->smarty->assign(array( Context::getContext()->smarty->assign(array(
'id_product_comment_form' => (int)Tools::getValue('id_product'), 'id_product_comment_form' => (int)Tools::getValue('id_product'),
@@ -706,8 +713,8 @@ class ProductComments extends Module
'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id), 'criterions' => ProductCommentCriterion::getByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id),
'action_url' => '', 'action_url' => '',
'averageTotal' => (int)$average['grade'], 'averageTotal' => (int)$average['grade'],
'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product']))) 'nbComments' => (int)(ProductComment::getCommentNumber((int)Tools::getValue('id_product')))
)); ));
return ($this->display(__FILE__, '/productcomments-extra.tpl')); return ($this->display(__FILE__, '/productcomments-extra.tpl'));
@@ -725,7 +732,7 @@ class ProductComments extends Module
$averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id); $averages = ProductComment::getAveragesByProduct((int)Tools::getValue('id_product'), Context::getContext()->language->id);
$averageTotal = 0; $averageTotal = 0;
foreach ($averages AS $average) foreach ($averages as $average)
$averageTotal += (float)($average); $averageTotal += (float)($average);
$averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0; $averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0;
@@ -738,19 +745,19 @@ class ProductComments extends Module
'product_comment_path' => $this->_path, 'product_comment_path' => $this->_path,
'averageTotal' => $averageTotal, 'averageTotal' => $averageTotal,
'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'),
'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()),
'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME'))); 'delay' => Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')));
$this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product'))); $this->context->controller->pagination((int)ProductComment::getCommentNumber((int)Tools::getValue('id_product')));
$image = Product::getCover((int)($_GET['id_product'])); $image = Product::getCover((int)Tools::getValue('id_product'));
Context::getContext()->smarty->assign(array( Context::getContext()->smarty->assign(array(
'id_product_comment_form' => (int)Tools::getValue('id_product'), 'id_product_comment_form' => (int)Tools::getValue('id_product'),
'secure_key' => $this->secure_key, 'secure_key' => $this->secure_key,
'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'], 'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product']))) 'nbComments' => (int)ProductComment::getCommentNumber((int)Tools::getValue('id_product'))
)); ));
@@ -774,16 +781,16 @@ class ProductComments extends Module
$list_product_average = array(); $list_product_average = array();
$list_product_comment = array(); $list_product_comment = array();
foreach ($params['list_ids_product'] AS $id_product) foreach ($params['list_ids_product'] as $id_product)
{ {
$grades = ProductComment::getAveragesByProduct($id_product, Context::getContext()->language->id); $grades = ProductComment::getAveragesByProduct($id_product, Context::getContext()->language->id);
$criterions = ProductCommentCriterion::getByProduct($id_product, Context::getContext()->language->id); $criterions = ProductCommentCriterion::getByProduct($id_product, Context::getContext()->language->id);
$grade_total = 0; $grade_total = 0;
if (sizeof($grades) > 0) if (count($grades) > 0)
{ {
foreach ($criterions AS $criterion) foreach ($criterions as $criterion)
{ {
if(isset($grades[$criterion['id_product_comment_criterion']])) if (isset($grades[$criterion['id_product_comment_criterion']]))
{ {
$list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']]; $list_product_grades[$criterion['id_product_comment_criterion']][$id_product] = $grades[$criterion['id_product_comment_criterion']];
$grade_total += (float)($grades[$criterion['id_product_comment_criterion']]); $grade_total += (float)($grades[$criterion['id_product_comment_criterion']]);
@@ -795,17 +802,17 @@ class ProductComments extends Module
$list_grades[$criterion['id_product_comment_criterion']] = $criterion['name']; $list_grades[$criterion['id_product_comment_criterion']] = $criterion['name'];
} }
$list_product_average[$id_product] = $grade_total / sizeof($criterion); $list_product_average[$id_product] = $grade_total / count($criterion);
$list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3); $list_product_comment[$id_product] = ProductComment::getByProduct($id_product, 0, 3);
} }
} }
if (sizeof($list_grades) < 1) if (count($list_grades) < 1)
return false; return false;
Context::getContext()->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'], Context::getContext()->smarty->assign(array('grades' => $list_grades, 'product_grades' => $list_product_grades, 'list_ids_product' => $params['list_ids_product'],
'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment)); 'list_product_average' => $list_product_average, 'product_comments' => $list_product_comment));
return $this->display(__FILE__,'/products-comparison.tpl'); return $this->display(__FILE__, '/products-comparison.tpl');
} }
} }