[*] MO : productComments - It's now possible to delete comments, beside moderation
This commit is contained in:
1 parent
5c64f12662
commit
081b8e7aa5
5 files changed
+110
-2
No files matched your search
@@ -256,6 +256,21 @@ class ProductComment extends ObjectModel
|
|||||||
ORDER BY pc.`date_add` DESC'));
|
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
|
* Validate a comment
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ function getCommentForm()
|
|||||||
return (document.comment_form);
|
return (document.comment_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCommentDeleteForm()
|
||||||
|
{
|
||||||
|
if (document.forms)
|
||||||
|
return (document.forms['delete_comment_form']);
|
||||||
|
else
|
||||||
|
return (document.delete_comment_form);
|
||||||
|
}
|
||||||
|
|
||||||
function acceptComment(id)
|
function acceptComment(id)
|
||||||
{
|
{
|
||||||
var form = getCommentForm();
|
var form = getCommentForm();
|
||||||
@@ -51,6 +59,19 @@ function deleteComment(id)
|
|||||||
form.submit();
|
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()
|
function getCriterionForm()
|
||||||
{
|
{
|
||||||
if (document.forms)
|
if (document.forms)
|
||||||
|
|||||||
@@ -62,7 +62,6 @@
|
|||||||
o.value = $(this).val();
|
o.value = $(this).val();
|
||||||
datas.push(o);
|
datas.push(o);
|
||||||
});
|
});
|
||||||
console.log(datas);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
||||||
post: "POST",
|
post: "POST",
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ class ProductComments extends Module
|
|||||||
$this->_checkReportedComment();
|
$this->_checkReportedComment();
|
||||||
$this->_checkCriterion();
|
$this->_checkCriterion();
|
||||||
$this->_updateApplicationCriterion();
|
$this->_updateApplicationCriterion();
|
||||||
|
$this->_checkDeleteComment();
|
||||||
|
|
||||||
return $this->_html.$this->_displayForm();
|
return $this->_html.$this->_displayForm();
|
||||||
}
|
}
|
||||||
@@ -309,6 +310,8 @@ class ProductComments extends Module
|
|||||||
$this->_displayFormReported();
|
$this->_displayFormReported();
|
||||||
$this->_displayFormConfigurationCriterion();
|
$this->_displayFormConfigurationCriterion();
|
||||||
$this->_displayFormApplicationCriterion();
|
$this->_displayFormApplicationCriterion();
|
||||||
|
$this->_displayFormDelete();
|
||||||
|
|
||||||
return $this->_html;
|
return $this->_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,6 +599,77 @@ class ProductComments extends Module
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function _displayFormDelete()
|
||||||
|
{
|
||||||
|
$this->_html .= '
|
||||||
|
<fieldset class="width2">
|
||||||
|
<legend><img src="'.$this->_path.'img/comments_delete.png" alt="" title="" />'.$this->l('Manage Comments').'</legend>';
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||||
|
$comments = ProductComment::getAll();
|
||||||
|
if (sizeof($comments))
|
||||||
|
{
|
||||||
|
$this->_html .= '
|
||||||
|
<form action="'.$this->_baseUrl.'" method="post" name="delete_comment_form">
|
||||||
|
<input type="hidden" name="delete_id_product_comment[]" id="delete_id_product_comment" />
|
||||||
|
<input type="hidden" name="delete_action" id="delete_action" />
|
||||||
|
<br /><table class="table" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input class="noborder" type="checkbox" name="delete_id_product_comment[]" onclick="checkDelBoxes(this.form, \'delete_id_product_comment[]\', this.checked)" /></th>
|
||||||
|
<th style="width:150px;">'.$this->l('Author').'</th>
|
||||||
|
<th style="width:550px;">'.$this->l('Comment').'</th>
|
||||||
|
<th style="width:30px;">'.$this->l('Actions').'</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>';
|
||||||
|
foreach ($comments AS $comment)
|
||||||
|
$this->_html .= '<tr>
|
||||||
|
<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['content'], ENT_COMPAT, 'UTF-8').'</td>
|
||||||
|
<td><a href="javascript:;" onclick="delComment(\''.(int)($comment['id_product_comment']).'\',\''.$this->l('Are you sure?').'\');"><img src="'.$this->_path.'img/delete.png" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a></td>
|
||||||
|
</tr>';
|
||||||
|
$this->_html .= '
|
||||||
|
<tr>
|
||||||
|
<td colspan="3" style="font-weight:bold;text-align:right">'.$this->l('Selection:').'</td>
|
||||||
|
<td><a href="javascript:;" onclick="delComment(0);"><img src="'.$this->_path.'img/delete.png" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->_html .= $this->l('No comments to manage at this time.');
|
||||||
|
|
||||||
|
$this->_html .= '</fieldset><br />';
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
public function hookProductTab($params)
|
||||||
{
|
{
|
||||||
require_once(dirname(__FILE__).'/ProductComment.php');
|
require_once(dirname(__FILE__).'/ProductComment.php');
|
||||||
|
|||||||
@@ -103,7 +103,6 @@
|
|||||||
o.value = $(this).val();
|
o.value = $(this).val();
|
||||||
datas.push(o);
|
datas.push(o);
|
||||||
});
|
});
|
||||||
console.log(datas);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
{/literal}url: "{$module_dir}productcomments-ajax.php",{literal}
|
||||||
post: "POST",
|
post: "POST",
|
||||||
|
|||||||
Reference in new issue
Block a user