Comment approve : filtering missing

This commit is contained in:
Fred Tempez 2020-07-16 12:06:51 +02:00
parent 4a599c513c
commit dca8fb57ab
3 changed files with 74 additions and 3 deletions

View File

@ -23,6 +23,7 @@ class blog extends common {
public static $actions = [ public static $actions = [
'add' => self::GROUP_MODERATOR, 'add' => self::GROUP_MODERATOR,
'comment' => self::GROUP_MODERATOR, 'comment' => self::GROUP_MODERATOR,
'commentApprove' => self::GROUP_MODERATOR,
'commentDelete' => self::GROUP_MODERATOR, 'commentDelete' => self::GROUP_MODERATOR,
'commentDeleteAll' => self::GROUP_MODERATOR, 'commentDeleteAll' => self::GROUP_MODERATOR,
'config' => self::GROUP_MODERATOR, 'config' => self::GROUP_MODERATOR,
@ -166,10 +167,20 @@ class blog extends common {
for($i = $pagination['first']; $i < $pagination['last']; $i++) { for($i = $pagination['first']; $i < $pagination['last']; $i++) {
// Met en forme le tableau // Met en forme le tableau
$comment = $comments[$commentIds[$i]]; $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[] = [ self::$comments[] = [
utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])), utf8_encode(strftime('%d %B %Y - %H:%M', $comment['createdOn'])),
$comment['content'], $comment['content'],
$comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'], $comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'],
$buttonApproval,
template::button('blogCommentDelete' . $commentIds[$i], [ template::button('blogCommentDelete' . $commentIds[$i], [
'class' => 'blogCommentDelete buttonRed', 'class' => 'blogCommentDelete buttonRed',
'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , '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 * Configuration
*/ */
@ -271,8 +320,8 @@ class blog extends common {
self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])], self::$states[$this->getData(['module', $this->getUrl(0), $articleIds[$i], 'state'])],
// Bouton pour afficher les commentaires de l'article // Bouton pour afficher les commentaires de l'article
template::button('blogConfigComment' . $articleIds[$i], [ template::button('blogConfigComment' . $articleIds[$i], [
'class' => $toApprove == 0 ? 'buttonGrey' : 'buttonBlue' , 'class' => ($toApprove || $approved ) > 0 ? 'buttonBlue' : 'buttonGrey' ,
'href' => $toApprove > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '', 'href' => ($toApprove || $approved ) > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '',
'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved 'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved
//'value' => count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment'])) //'value' => count($this->getData(['module', $this->getUrl(0), $articleIds[$i],'comment']))
]), ]),

View File

@ -22,6 +22,28 @@ $(".blogCommentDelete").on("click", function() {
}); });
}); });
/**
* Confirmation d'approbation
*/
$(".blogCommentApprove").on("click", function() {
var _this = $(this);
var nom = "<?php echo $this->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 = "<?php echo $this->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 * Confirmation de suppression en masse
*/ */

View File

@ -14,7 +14,7 @@
</div> </div>
</div> </div>
<?php echo template::table([3, 6, 2, 1], $module::$comments, ['Date', 'Contenu', 'Auteur', '']); ?> <?php echo template::table([3, 5, 2, 1, 1], $module::$comments, ['Date', 'Contenu', 'Auteur', '', '']); ?>
<?php echo $module::$pages.'<br/>'; ?> <?php echo $module::$pages.'<br/>'; ?>
<?php else: ?> <?php else: ?>
</div> </div>