From 96ed001ff3f2816add22b1096b6f8d38b5f41eb5 Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 28 Sep 2011 08:50:40 +0000 Subject: [PATCH] // productcomments git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8833 b9a71923-0436-4b27-9f14-aed3839534dd --- modules/productcomments/ProductComment.php | 111 ++++++------- .../productcomments/productcomments-ajax.php | 73 ++++----- modules/productcomments/productcomments.php | 153 +++++++++--------- 3 files changed, 173 insertions(+), 164 deletions(-) diff --git a/modules/productcomments/ProductComment.php b/modules/productcomments/ProductComment.php index 7b6007ab4..9a060084e 100644 --- a/modules/productcomments/ProductComment.php +++ b/modules/productcomments/ProductComment.php @@ -18,8 +18,7 @@ * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * -* @author Presta - SA +* @author PrestaShop SA * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7040 $ * @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 { - public $id; + public $id; /** @var integer Product's id */ - public $id_product; + public $id_product; /** @var integer Customer's id */ - public $id_customer; + public $id_customer; /** @var integer Guest's id */ - public $id_guest; + public $id_guest; /** @var integer Customer name */ - public $customer_name; + public $customer_name; /** @var string Title */ - public $title; + public $title; /** @var string Content */ - public $content; + public $content; /** @var integer Grade */ - public $grade; + public $grade; /** @var boolean Validate */ - public $validate = 0; + public $validate = 0; - public $deleted = 0; + public $deleted = 0; /** @var string Object creation date */ - public $date_add; + public $date_add; - protected $fieldsRequired = array('id_product', 'id_customer', 'content'); - protected $fieldsSize = array('content' => 65535); - protected $fieldsValidate = array('id_product' => 'isUnsignedId', 'id_customer' => 'isUnsignedId', 'content' => 'isMessage', - 'grade' => 'isFloat', 'validate' => 'isBool'); + protected $fieldsRequired = array('id_product', 'id_customer', 'content'); + protected $fieldsSize = array('content' => 65535); + protected $fieldsValidate = array( + 'id_product' => 'isUnsignedId', + 'id_customer' => 'isUnsignedId', + 'content' => 'isMessage', + 'grade' => 'isFloat', + 'validate' => 'isBool' + ); - protected $table = 'product_comment'; - protected $identifier = 'id_product_comment'; + protected $table = 'product_comment'; + protected $identifier = 'id_product_comment'; public function getFields() { $this->validateFields(false); - $fields['id_product'] = (int)($this->id_product); - $fields['id_customer'] = (int)($this->id_customer); - $fields['id_guest'] = (int)($this->id_guest); + $fields['id_product'] = (int)$this->id_product; + $fields['id_customer'] = (int)$this->id_customer; + $fields['id_guest'] = (int)$this->id_guest; $fields['customer_name'] = pSQL($this->customer_name); $fields['title'] = pSQL($this->title); $fields['content'] = pSQL($this->content); - $fields['grade'] = (float)($this->grade); - $fields['validate'] = (int)($this->validate); - $fields['deleted'] = (int)($this->deleted); + $fields['grade'] = (float)$this->grade; + $fields['validate'] = (int)$this->validate; + $fields['deleted'] = (int)$this->deleted; $fields['date_add'] = pSQL($this->date_add); return ($fields); } @@ -97,11 +101,11 @@ class ProductComment extends ObjectModel if (!Validate::isUnsignedId($id_product)) die(Tools::displayError()); $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); - $p = (int)($p); - $n = (int)($n); + $p = (int)$p; + $n = (int)$n; if ($p <= 1) $p = 1; - if ($n != null AND $n <= 0) + if ($n != null && $n <= 0) $n = 5; return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' @@ -128,7 +132,8 @@ class ProductComment extends ObjectModel $results = Db::getInstance()->ExecuteS(' SELECT * 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 ' .($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_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`) - WHERE pc.`id_product` = '.(int)($id_product).' - AND pccl.`id_lang` = '.(int)($id_lang). + WHERE pc.`id_product` = '.(int)$id_product.' + AND pccl.`id_lang` = '.(int)$id_lang. ($validate == '1' ? ' AND pc.`validate` = 1' : ''))); } @@ -168,14 +173,9 @@ class ProductComment extends ObjectModel $validate = Configuration::get('PRODUCT_COMMENTS_MODERATE'); return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT SUM(pc.`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 + SELECT (SUM(pc.`grade`) / COUNT(pc.`grade`)) AS grade FROM `'._DB_PREFIX_.'product_comment` pc - WHERE pc.`id_product` = '.(int)($id_product).' + WHERE pc.`id_product` = '.(int)$id_product.' AND pc.`deleted` = 0'. ($validate == '1' ? ' AND pc.`validate` = 1' : '')); } @@ -183,14 +183,15 @@ class ProductComment extends ObjectModel public static function getAveragesByProduct($id_product, $id_lang) { /* Get all grades */ - $grades = ProductComment::getGradeByProduct((int)($id_product), (int)($id_lang)); - $total = ProductComment::getGradedCommentNumber((int)($id_product)); - if (!sizeof($grades) OR (!$total)) + $grades = ProductComment::getGradeByProduct((int)$id_product, (int)$id_lang); + $total = ProductComment::getGradedCommentNumber((int)$id_product); + if (!count($grades) || (!$total)) return array(); /* Addition grades for each criterion */ $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) $criterionsGradeTotal[$grades[$i]['id_product_comment_criterion']] = (int)($grades[$i]['grade']); else @@ -198,7 +199,7 @@ class ProductComment extends ObjectModel /* Finally compute the averages */ $averages = array(); - foreach ($criterionsGradeTotal AS $key => $criterionGradeTotal) + foreach ($criterionsGradeTotal as $key => $criterionGradeTotal) $averages[(int)($key)] = (int)($total) ? ((int)($criterionGradeTotal) / (int)($total)) : 0; return $averages; } @@ -212,7 +213,7 @@ class ProductComment extends ObjectModel { if (!Validate::isUnsignedId($id_product)) 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(' SELECT COUNT(`id_product_comment`) AS "nbr" FROM `'._DB_PREFIX_.'product_comment` pc @@ -230,7 +231,7 @@ class ProductComment extends ObjectModel { if (!Validate::isUnsignedId($id_product)) 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(' SELECT COUNT(pc.`id_product`) AS nbr @@ -252,7 +253,7 @@ class ProductComment extends ObjectModel FROM `'._DB_PREFIX_.'product_comment` pc 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').') - WHERE pc.`validate` = '.(int)($validate).' + WHERE pc.`validate` = '.(int)$validate.' ORDER BY pc.`date_add` DESC')); } @@ -282,8 +283,8 @@ class ProductComment extends ObjectModel die(Tools::displayError()); return (Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product_comment` SET - `validate` = '.(int)($validate).' - WHERE `id_product_comment` = '.(int)($this->id))); + `validate` = '.(int)$validate.' + WHERE `id_product_comment` = '.(int)$this->id)); } /** @@ -297,7 +298,7 @@ class ProductComment extends ObjectModel die(Tools::displayError()); return (Db::getInstance()->Execute(' 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()); return (Db::getInstance()->Execute(' 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(' 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(' SELECT COUNT(*) FROM `'._DB_PREFIX_.'product_comment_report` - WHERE `id_customer` = '.(int)($id_customer).' - AND `id_product_comment` = '.(int)($id_product_comment)); + WHERE `id_customer` = '.(int)$id_customer.' + AND `id_product_comment` = '.(int)$id_product_comment); } /** @@ -377,8 +378,8 @@ class ProductComment extends ObjectModel return (bool)Db::getInstance()->getValue(' SELECT COUNT(*) FROM `'._DB_PREFIX_.'product_comment_usefulness` - WHERE `id_customer` = '.(int)($id_customer).' - AND `id_product_comment` = '.(int)($id_product_comment)); + WHERE `id_customer` = '.(int)$id_customer.' + AND `id_product_comment` = '.(int)$id_product_comment); } /** diff --git a/modules/productcomments/productcomments-ajax.php b/modules/productcomments/productcomments-ajax.php index 1281ac04b..1c1877996 100644 --- a/modules/productcomments/productcomments-ajax.php +++ b/modules/productcomments/productcomments-ajax.php @@ -33,20 +33,24 @@ include_once(dirname(__FILE__).'/productcomments.php'); $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 (!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'); } - 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'); } } -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')); $id_product = 0; @@ -56,39 +60,39 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC $grades = array(); foreach ($review as $entry) { - if ($entry->key == "id_product") + if ($entry->key == 'id_product') $id_product = $entry->value; - elseif ($entry->key == "title") + else if ($entry->key == 'title') $title = $entry->value; - elseif ($entry->key == "content") + else if ($entry->key == 'content') $content = $entry->value; - elseif ($entry->key == "customer_name") + else if ($entry->key == 'customer_name') $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); } } - if ($title == "" OR $content == "" OR !$id_product OR count($grades) == 0) + if ($title == '' || $content == '' || !$id_product || count($grades) == 0) die('0'); $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; $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(); $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'); - if (!sizeof($errors) AND $content) + if (!count($errors) && $content) { $comment = new ProductComment(); $comment->content = strip_tags($content); @@ -102,28 +106,25 @@ elseif (Tools::getValue('action') AND Tools::getValue('secure_key') == $productC $comment->grade = 0; $comment->validate = 0; - if (!$comment->content) - $errors[] = $productCom->l('Invalid comment text posted.'); - else + + $tgrade = 0; + $comment->save(); + foreach ($grades as $grade) { - $tgrade = 0; - $comment->save(); - foreach ($grades as $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.') : '')); + $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.') : '')); + } else $errors[] = $productCom->l('Comment text is required.'); diff --git a/modules/productcomments/productcomments.php b/modules/productcomments/productcomments.php index 0afd40da0..6cc8ddde3 100644 --- a/modules/productcomments/productcomments.php +++ b/modules/productcomments/productcomments.php @@ -57,32 +57,38 @@ class ProductComments extends Module { if (!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) 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; $sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql); $sql = preg_split("/;\s*[\r\n]+/", trim($sql)); - foreach ($sql AS $query) + foreach ($sql as $query) if (!Db::getInstance()->Execute(trim($query))) return false; - if (parent::install() == false - OR !$this->registerHook('productTab') - OR !$this->registerHook('extraProductComparison') OR !$this->registerHook('productTabContent') - OR !$this->registerHook('header') OR !$this->registerHook('productOutOfStock') - OR !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30) - OR !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0) - OR !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1)) + if (parent::install() == false || + !$this->registerHook('productTab') || + !$this->registerHook('extraProductComparison') || + !$this->registerHook('productTabContent') || + !$this->registerHook('header') || + !$this->registerHook('productOutOfStock') || + !Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', 30) || + !Configuration::updateValue('PRODUCT_COMMENTS_ALLOW_GUESTS', 0) || + !Configuration::updateValue('PRODUCT_COMMENTS_MODERATE', 1)) return false; return true; } public function uninstall() { - if (!parent::uninstall() OR !$this->deleteTables() - OR !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE') - OR !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') OR !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME') - OR !$this->unregisterHook('extraProductComparison') OR !$this->unregisterHook('productOutOfStock') OR !$this->unregisterHook('productTabContent') - OR !$this->unregisterHook('header') OR !$this->unregisterHook('productTab')) + if (!parent::uninstall() || !$this->deleteTables() || + !Configuration::deleteByName('PRODUCT_COMMENTS_MODERATE') || + !Configuration::deleteByName('PRODUCT_COMMENTS_ALLOW_GUESTS') || + !Configuration::deleteByName('PRODUCT_COMMENTS_MINIMAL_TIME') || + !$this->unregisterHook('extraProductComparison') || + !$this->unregisterHook('productOutOfStock') || + !$this->unregisterHook('productTabContent') || + !$this->unregisterHook('header') || + !$this->unregisterHook('productTab')) return false; return true; } @@ -110,7 +116,7 @@ class ProductComments extends Module Configuration::updateValue('PRODUCT_COMMENTS_MINIMAL_TIME', (int)Tools::getValue('product_comments_minimal_time')); $this->_html .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } - if ($id_criterion = (int)Tools::getValue('deleteCriterion')) + if ($id_criterion = (int)Tools::getValue('deleteCriterion')) { $productCommentCriterion = new ProductCommentCriterion((int)$id_criterion); if ($productCommentCriterion->id) @@ -139,7 +145,7 @@ class ProductComments extends Module private function _setBaseUrl() { $this->_baseUrl = 'index.php?'; - foreach ($_GET AS $k => $value) + foreach ($_GET as $k => $value) if (!in_array($k, array('deleteCriterion', 'editCriterion'))) $this->_baseUrl .= $k.'='.$value.'&'; $this->_baseUrl = rtrim($this->_baseUrl, '&'); @@ -148,18 +154,17 @@ class ProductComments extends Module private function _checkModerateComment() { $action = Tools::getValue('action'); - if (empty($action) === false && - (int)(Configuration::get('PRODUCT_COMMENTS_MODERATE'))) + if (empty($action) === false && (int)Configuration::get('PRODUCT_COMMENTS_MODERATE')) { $product_comments = Tools::getValue('id_product_comment'); - if (sizeof($product_comments)) + if (count($product_comments)) { require_once(dirname(__FILE__).'/ProductComment.php'); switch ($action) { case 'accept': - foreach ($product_comments AS $id_product_comment) + foreach ($product_comments as $id_product_comment) { if (!$id_product_comment) continue; @@ -167,8 +172,9 @@ class ProductComments extends Module $comment->validate(); } break; + case 'delete': - foreach ($product_comments AS $id_product_comment) + foreach ($product_comments as $id_product_comment) { if (!$id_product_comment) continue; @@ -177,6 +183,7 @@ class ProductComments extends Module ProductComment::deleteGrades((int)$id_product_comment); } break; + default: ; } @@ -191,13 +198,13 @@ class ProductComments extends Module { $product_comments = Tools::getValue('id_product_comment'); - if (sizeof($product_comments)) + if (count($product_comments)) { require_once(dirname(__FILE__).'/ProductComment.php'); switch ($action) { case 'accept': - foreach ($product_comments AS $id_product_comment) + foreach ($product_comments as $id_product_comment) { if (!$id_product_comment) continue; @@ -207,7 +214,7 @@ class ProductComments extends Module } break; case 'delete': - foreach ($product_comments AS $id_product_comment) + foreach ($product_comments as $id_product_comment) { if (!$id_product_comment) continue; @@ -235,7 +242,7 @@ class ProductComments extends Module $languages = Language::getLanguages(); $id_criterion = (int)Tools::getValue('id_product_comment_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']); // Check default language criterion name @@ -252,7 +259,7 @@ class ProductComments extends Module if ($productCommentCriterion->save()) $this->_html .= '
'.$this->l('Confirmation').''.(Tools::getValue('editCriterion') ? $this->l('Criterion updated') : $this->l('Criterion added')).'
'; } - elseif (!empty($action_criterion) AND empty($name)) + else if (!empty($action_criterion) && empty($name)) { $id_product_comment_criterion = Tools::getValue('id_product_comment_criterion'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); @@ -286,16 +293,16 @@ class ProductComments extends Module { $productCommentCriterion->deleteCategories(); if ($categories = Tools::getValue('id_product')) - if (sizeof($categories)) - foreach ($categories AS $id_category) + if (count($categories)) + foreach ($categories as $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(); if ($products = Tools::getValue('id_product')) - if (sizeof($products)) - foreach ($products AS $product) + if (count($products)) + foreach ($products as $product) $productCommentCriterion->addProduct((int)$product); } } @@ -354,7 +361,7 @@ class ProductComments extends Module { require_once(dirname(__FILE__).'/ProductComment.php'); $comments = ProductComment::getByValidate(); - if (sizeof($comments)) + if (count($comments)) { $this->_html .= '
@@ -371,7 +378,7 @@ class ProductComments extends Module '; - foreach ($comments AS $comment) + foreach ($comments as $comment) $this->_html .= ' '.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'. @@ -403,7 +410,7 @@ class ProductComments extends Module require_once(dirname(__FILE__).'/ProductComment.php'); $comments = ProductComment::getReportedComments(); - if (sizeof($comments)) + if (count($comments)) { $this->_html .= ' @@ -420,7 +427,7 @@ class ProductComments extends Module '; - foreach ($comments AS $comment) + foreach ($comments as $comment) $this->_html .= ' '.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'. @@ -461,7 +468,7 @@ class ProductComments extends Module
'; - foreach ($langs AS $lang) + foreach ($langs as $lang) $this->_html .= '
@@ -473,8 +480,8 @@ class ProductComments extends Module
@@ -490,9 +497,9 @@ class ProductComments extends Module '; require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); $criterions = ProductCommentCriterion::getCriterions(Context::getContext()->language->id); - if (sizeof($criterions)) + if (count($criterions)) { - $this->_html.= '
+ $this->_html .= '
@@ -504,7 +511,7 @@ class ProductComments extends Module '; - foreach ($criterions AS $criterion) + foreach ($criterions as $criterion) { $this->_html .= ' @@ -533,18 +540,18 @@ class ProductComments extends Module $categories = Category::getSimpleCategories(Context::getContext()->language->id); $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(); $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) unset($criterions[$key]); - if (sizeof($criterions)) + if (count($criterions)) { $this->_html .= '
@@ -556,13 +563,13 @@ class ProductComments extends Module "> '; - if ($id_criterion AND $criterion->id_product_comment_criterion_type != 1) + if ($id_criterion && $criterion->id_product_comment_criterion_type != 1) { $this->_html .='
@@ -579,11 +586,11 @@ class ProductComments extends Module
'; if ($criterion->id_product_comment_criterion_type == 3) - foreach ($products AS $product) + foreach ($products as $product) $this->_html .=''; - elseif ($criterion->id_product_comment_criterion_type == 2) - foreach ($categories AS $category) + else if ($criterion->id_product_comment_criterion_type == 2) + foreach ($categories as $category) $this->_html .=''; $this->_html .=' @@ -607,7 +614,7 @@ class ProductComments extends Module require_once(dirname(__FILE__).'/ProductComment.php'); $comments = ProductComment::getAll(); - if (sizeof($comments)) + if (count($comments)) { $this->_html .= ' @@ -623,7 +630,7 @@ class ProductComments extends Module '; - foreach ($comments AS $comment) + foreach ($comments as $comment) $this->_html .= ' @@ -652,12 +659,12 @@ class ProductComments extends Module { $product_comments = Tools::getValue('delete_id_product_comment'); - if (sizeof($product_comments)) + if (count($product_comments)) { require_once(dirname(__FILE__).'/ProductComment.php'); if ($action == 'delete') { - foreach ($product_comments AS $id_product_comment) + foreach ($product_comments as $id_product_comment) { if (!$id_product_comment) continue; @@ -671,15 +678,15 @@ class ProductComments extends Module } public function hookProductTab($params) - { - require_once(dirname(__FILE__).'/ProductComment.php'); + { + require_once(dirname(__FILE__).'/ProductComment.php'); require_once(dirname(__FILE__).'/ProductCommentCriterion.php'); Context::getContext()->smarty->assign(array( 'allow_guests' => (int)Configuration::get('PRODUCT_COMMENTS_ALLOW_GUESTS'), - 'comments' => ProductComment::getByProduct((int)($_GET['id_product'])), - 'criterions' => ProductCommentCriterion::getByProduct((int)($_GET['id_product']), Context::getContext()->language->id), - 'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product']))))); + 'comments' => ProductComment::getByProduct((int)(Tools::getValue('id_product'))), + 'criterions' => ProductCommentCriterion::getByProduct((int)(Tools::getValue('id_product')), Context::getContext()->language->id), + 'nbComments' => (int)(ProductComment::getCommentNumber((int)(Tools::getValue('id_product')))))); return ($this->display(__FILE__, '/tab.tpl')); } @@ -694,7 +701,7 @@ class ProductComments extends Module $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( '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), 'action_url' => '', 'averageTotal' => (int)$average['grade'], - 'too_early' => ($customerComment AND (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), - 'nbComments' => (int)(ProductComment::getCommentNumber((int)($_GET['id_product']))) + 'too_early' => ($customerComment && (strtotime($customerComment['date_add']) + Configuration::get('PRODUCT_COMMENTS_MINIMAL_TIME')) > time()), + 'nbComments' => (int)(ProductComment::getCommentNumber((int)Tools::getValue('id_product'))) )); 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); $averageTotal = 0; - foreach ($averages AS $average) + foreach ($averages as $average) $averageTotal += (float)($average); $averageTotal = count($averages) ? ($averageTotal / count($averages)) : 0; @@ -738,19 +745,19 @@ class ProductComments extends Module 'product_comment_path' => $this->_path, 'averageTotal' => $averageTotal, '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'))); $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( 'id_product_comment_form' => (int)Tools::getValue('id_product'), 'secure_key' => $this->secure_key, 'productcomment_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'], '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_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); $criterions = ProductCommentCriterion::getByProduct($id_product, Context::getContext()->language->id); $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']]; $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_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); } } - if (sizeof($list_grades) < 1) + if (count($list_grades) < 1) return false; 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)); - return $this->display(__FILE__,'/products-comparison.tpl'); + return $this->display(__FILE__, '/products-comparison.tpl'); } -} +} \ No newline at end of file
'.$criterion['name'].'
'.(int)$product['id_product'].''.$product['name'].'
'.(int)$category['id_category'].''.$category['name'].'
'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.