From 081b8e7aa5a92644caf75795eb340b100292e900 Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 29 Aug 2011 16:21:57 +0000 Subject: [PATCH] [*] MO : productComments - It's now possible to delete comments, beside moderation --- modules/productcomments/ProductComment.php | 15 ++++ modules/productcomments/js/moderate.js | 21 ++++++ .../productcomments/productcomments-extra.tpl | 1 - modules/productcomments/productcomments.php | 74 +++++++++++++++++++ modules/productcomments/productcomments.tpl | 1 - 5 files changed, 110 insertions(+), 2 deletions(-) diff --git a/modules/productcomments/ProductComment.php b/modules/productcomments/ProductComment.php index 1e08f3dee..7b6007ab4 100644 --- a/modules/productcomments/ProductComment.php +++ b/modules/productcomments/ProductComment.php @@ -256,6 +256,21 @@ class ProductComment extends ObjectModel ORDER BY pc.`date_add` DESC')); } + /** + * Get all comments + * + * @return array Comments + */ + public static function getAll() + { + return (Db::getInstance()->ExecuteS(' + SELECT pc.`id_product_comment`, pc.`id_product`, IF(c.id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`), pc.customer_name) customer_name, pc.`content`, pc.`grade`, pc.`date_add`, pl.`name` + 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').') + ORDER BY pc.`date_add` DESC')); + } + /** * Validate a comment * diff --git a/modules/productcomments/js/moderate.js b/modules/productcomments/js/moderate.js index 620d3e3fa..93700f938 100644 --- a/modules/productcomments/js/moderate.js +++ b/modules/productcomments/js/moderate.js @@ -32,6 +32,14 @@ function getCommentForm() return (document.comment_form); } +function getCommentDeleteForm() +{ + if (document.forms) + return (document.forms['delete_comment_form']); + else + return (document.delete_comment_form); +} + function acceptComment(id) { var form = getCommentForm(); @@ -51,6 +59,19 @@ function deleteComment(id) form.submit(); } +function delComment(id, confirmation) +{ + var answer = confirm(confirmation); + if (answer) + { + var form = getCommentDeleteForm(); + if (id) + form.elements['delete_id_product_comment'].value = id; + form.elements['delete_action'].value = 'delete'; + form.submit(); + } +} + function getCriterionForm() { if (document.forms) diff --git a/modules/productcomments/productcomments-extra.tpl b/modules/productcomments/productcomments-extra.tpl index ffd5ed460..2805bd600 100644 --- a/modules/productcomments/productcomments-extra.tpl +++ b/modules/productcomments/productcomments-extra.tpl @@ -62,7 +62,6 @@ o.value = $(this).val(); datas.push(o); }); - console.log(datas); $.ajax({ {/literal}url: "{$module_dir}productcomments-ajax.php",{literal} post: "POST", diff --git a/modules/productcomments/productcomments.php b/modules/productcomments/productcomments.php index acfda5b47..69f55bf4e 100644 --- a/modules/productcomments/productcomments.php +++ b/modules/productcomments/productcomments.php @@ -131,6 +131,7 @@ class ProductComments extends Module $this->_checkReportedComment(); $this->_checkCriterion(); $this->_updateApplicationCriterion(); + $this->_checkDeleteComment(); return $this->_html.$this->_displayForm(); } @@ -309,6 +310,8 @@ class ProductComments extends Module $this->_displayFormReported(); $this->_displayFormConfigurationCriterion(); $this->_displayFormApplicationCriterion(); + $this->_displayFormDelete(); + return $this->_html; } @@ -596,6 +599,77 @@ class ProductComments extends Module } } + private function _displayFormDelete() + { + $this->_html .= ' +
+ '.$this->l('Manage Comments').''; + + require_once(dirname(__FILE__).'/ProductComment.php'); + $comments = ProductComment::getAll(); + if (sizeof($comments)) + { + $this->_html .= ' +
+ + +
+ + + + + + + + + '; + foreach ($comments AS $comment) + $this->_html .= ' + + + + + '; + $this->_html .= ' + + + + + +
'.$this->l('Author').''.$this->l('Comment').''.$this->l('Actions').'
'.htmlspecialchars($comment['customer_name'], ENT_COMPAT, 'UTF-8').'.'.htmlspecialchars($comment['content'], ENT_COMPAT, 'UTF-8').''.$this->l('Delete').'
'.$this->l('Selection:').''.$this->l('Delete').'
+
'; + } + else + $this->_html .= $this->l('No comments to manage at this time.'); + + $this->_html .= '

'; + } + + private function _checkDeleteComment() + { + $action = Tools::getValue('delete_action'); + if (empty($action) === false) + { + $product_comments = Tools::getValue('delete_id_product_comment'); + + if (sizeof($product_comments)) + { + require_once(dirname(__FILE__).'/ProductComment.php'); + if ($action == 'delete') + { + foreach ($product_comments AS $id_product_comment) + { + if (!$id_product_comment) + continue; + $comment = new ProductComment((int)$id_product_comment); + $comment->delete(); + ProductComment::deleteGrades((int)$id_product_comment); + } + } + } + } + } + public function hookProductTab($params) { require_once(dirname(__FILE__).'/ProductComment.php'); diff --git a/modules/productcomments/productcomments.tpl b/modules/productcomments/productcomments.tpl index 02b72f5f7..8b9818451 100644 --- a/modules/productcomments/productcomments.tpl +++ b/modules/productcomments/productcomments.tpl @@ -103,7 +103,6 @@ o.value = $(this).val(); datas.push(o); }); - console.log(datas); $.ajax({ {/literal}url: "{$module_dir}productcomments-ajax.php",{literal} post: "POST",