From d3d54059c38766083e39d6414c4591e75b2ad399 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 27 Dec 2022 17:16:43 +0530 Subject: [PATCH] Show updated helpful count when marking a review helpful --- modules/qlohotelreview/classes/QhrHotelReview.php | 9 +++++++++ modules/qlohotelreview/controllers/front/default.php | 2 ++ modules/qlohotelreview/views/js/front/review-list.js | 3 ++- .../helpers/view/_partials/review.tpl | 6 +++++- .../views/templates/hook/_partials/review.tpl | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/qlohotelreview/classes/QhrHotelReview.php b/modules/qlohotelreview/classes/QhrHotelReview.php index 92602bdac..39bc9a262 100644 --- a/modules/qlohotelreview/classes/QhrHotelReview.php +++ b/modules/qlohotelreview/classes/QhrHotelReview.php @@ -244,6 +244,15 @@ class QhrHotelReview extends ObjectModel ); } + public function getTotalUseful() + { + return (int) Db::getInstance()->getValue( + 'SELECT COUNT(*) + FROM `'._DB_PREFIX_.'qhr_review_usefulness` ru + WHERE ru.`id_hotel_review` = '.(int) $this->id_hotel_review + ); + } + public function getTotalReports() { $sql = new DbQuery(); diff --git a/modules/qlohotelreview/controllers/front/default.php b/modules/qlohotelreview/controllers/front/default.php index e1cfecb53..fe6e6f2eb 100644 --- a/modules/qlohotelreview/controllers/front/default.php +++ b/modules/qlohotelreview/controllers/front/default.php @@ -139,6 +139,8 @@ class QloHotelReviewDefaultModuleFrontController extends ModuleFrontController if (QhrHotelReview::markHelpful($idHotelReview, $this->context->cookie->id_customer)) { $response['status'] = true; + $objHotelReview = new QhrHotelReview($idHotelReview); + $response['count_useful'] = $objHotelReview->getTotalUseful(); $this->ajaxDie(json_encode($response)); } } diff --git a/modules/qlohotelreview/views/js/front/review-list.js b/modules/qlohotelreview/views/js/front/review-list.js index 5b26ab468..8e67eea04 100644 --- a/modules/qlohotelreview/views/js/front/review-list.js +++ b/modules/qlohotelreview/views/js/front/review-list.js @@ -36,9 +36,10 @@ var QhrReview = { headers: { 'cache-control': 'no-cache' }, success: function(response) { if (response.status == true) { + $(btnHelpful).closest('.review').find('.helpful-count span').html(response.count_useful); $(btnHelpful).fadeOut('slow', function() { $(btnHelpful).remove(); - }) + }); } } }); diff --git a/modules/qlohotelreview/views/templates/admin/hotel_review_hotel_review/helpers/view/_partials/review.tpl b/modules/qlohotelreview/views/templates/admin/hotel_review_hotel_review/helpers/view/_partials/review.tpl index 57e88a071..114f895d3 100644 --- a/modules/qlohotelreview/views/templates/admin/hotel_review_hotel_review/helpers/view/_partials/review.tpl +++ b/modules/qlohotelreview/views/templates/admin/hotel_review_hotel_review/helpers/view/_partials/review.tpl @@ -124,7 +124,11 @@

- {$total_reports|escape:'html':'UTF-8'} + {if $total_reports|intval > 0} + {$total_reports|escape:'html':'UTF-8'} + {else} + -- + {/if}

{if $total_reports|intval > 0}

diff --git a/modules/qlohotelreview/views/templates/hook/_partials/review.tpl b/modules/qlohotelreview/views/templates/hook/_partials/review.tpl index 5362b70b5..5444ec30f 100644 --- a/modules/qlohotelreview/views/templates/hook/_partials/review.tpl +++ b/modules/qlohotelreview/views/templates/hook/_partials/review.tpl @@ -51,7 +51,7 @@ {/if} -

{l s='%1$d people found it helpful.' sprintf=[$review.total_useful] mod='qlohotelreview'}

+

{$review.total_useful|escape:'html':'UTF-8'}{l s=' people found it helpful.' mod='qlohotelreview'}

{if $logged && !$review.response_report}