From dca8fb57ab7fb5d22200869050ee7da7fd4ce4d8 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Thu, 16 Jul 2020 12:06:51 +0200 Subject: [PATCH] Comment approve : filtering missing --- module/blog/blog.php | 53 ++++++++++++++++++++++++- module/blog/view/comment/comment.js.php | 22 ++++++++++ module/blog/view/comment/comment.php | 2 +- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/module/blog/blog.php b/module/blog/blog.php index 3a72ab4b..137e691c 100755 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -23,6 +23,7 @@ class blog extends common { public static $actions = [ 'add' => self::GROUP_MODERATOR, 'comment' => self::GROUP_MODERATOR, + 'commentApprove' => self::GROUP_MODERATOR, 'commentDelete' => self::GROUP_MODERATOR, 'commentDeleteAll' => self::GROUP_MODERATOR, 'config' => self::GROUP_MODERATOR, @@ -166,10 +167,20 @@ class blog extends common { for($i = $pagination['first']; $i < $pagination['last']; $i++) { // Met en forme le tableau $comment = $comments[$commentIds[$i]]; + // Bouton d'approbation + $buttonApproval = ''; + if ( $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'commentApprove']) === true) { + $buttonApproval = template::button('blogcommentApprove' . $commentIds[$i], [ + 'class' => $comment['approval'] === true ? 'blogCommentApprove' : 'blogCommentApprove buttonRed' , + 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentApprove/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , + 'value' => $comment['approval'] === true ? 'A' : 'R' + ]); + } self::$comments[] = [ utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])), $comment['content'], $comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'], + $buttonApproval, template::button('blogCommentDelete' . $commentIds[$i], [ 'class' => 'blogCommentDelete buttonRed', 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , @@ -239,6 +250,44 @@ class blog extends common { } } + /** + * Approbation oou désapprobation de commentaire + */ + public function commentApprove() { + // Le commentaire n'existe pas + if($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(4) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => 'Action non autorisée' + ]); + } + // Inversion du statut + else { + $this->setData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), [ + 'author' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'author']), + 'content' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'content']), + 'createdOn' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'createdOn']), + 'userId' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'userId']), + 'approval' => !$this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) + ]]); + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2), + 'notification' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) === true ? 'Commentaire approuvé' : 'Commentaire rejeté', + 'state' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) + ]); + } + } + /** * Configuration */ @@ -271,8 +320,8 @@ class blog extends common { self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])], // Bouton pour afficher les commentaires de l'article template::button('blogConfigComment' . $articleIds[$i], [ - 'class' => $toApprove == 0 ? 'buttonGrey' : 'buttonBlue' , - 'href' => $toApprove > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '', + 'class' => ($toApprove || $approved ) > 0 ? 'buttonBlue' : 'buttonGrey' , + 'href' => ($toApprove || $approved ) > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '', 'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved //'value' => count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment'])) ]), diff --git a/module/blog/view/comment/comment.js.php b/module/blog/view/comment/comment.js.php index 87fa6da2..4d83befb 100755 --- a/module/blog/view/comment/comment.js.php +++ b/module/blog/view/comment/comment.js.php @@ -22,6 +22,28 @@ $(".blogCommentDelete").on("click", function() { }); }); +/** + * Confirmation d'approbation + */ +$(".blogCommentApprove").on("click", function() { + var _this = $(this); + var nom = "getData(['module', $this->getUrl(0), $this->getUrl(2), 'title' ]); ?>"; + return core.confirm("Approuver le commentaire de l'article " + nom + " ?", function() { + $(location).attr("href", _this.attr("href")); + }); +}); + +/** + * Confirmation de rejet + */ +$(".blogCommentReject").on("click", function() { + var _this = $(this); + var nom = "getData(['module', $this->getUrl(0), $this->getUrl(2), 'title' ]); ?>"; + return core.confirm("Rejeter le commentaire de l'article " + nom + " ?", function() { + $(location).attr("href", _this.attr("href")); + }); +}); + /** * Confirmation de suppression en masse */ diff --git a/module/blog/view/comment/comment.php b/module/blog/view/comment/comment.php index 3d1d4fa5..08d5e9ee 100755 --- a/module/blog/view/comment/comment.php +++ b/module/blog/view/comment/comment.php @@ -14,7 +14,7 @@ - + '; ?>