From 021971289d4370a101bdc817138221398fb2143a Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Sat, 4 Dec 2021 21:46:26 +0200 Subject: [PATCH] Groups: Add the ability to write comments on behalf of the group --- Web/Models/Entities/Comment.php | 17 +++++++++++++++++ Web/Presenters/CommentPresenter.php | 5 +++++ Web/Presenters/templates/components/comment.xml | 3 ++- .../templates/components/comments.xml | 3 ++- .../templates/components/textArea.xml | 5 +++++ locales/en.strings | 1 + locales/ru.strings | 1 + 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php index ebbfccc3..1afd0126 100644 --- a/Web/Models/Entities/Comment.php +++ b/Web/Models/Entities/Comment.php @@ -1,5 +1,7 @@ isPostedOnBehalfOfGroup()) { + if($this->getTarget() instanceof Post) + return (new Clubs)->get(abs($this->getTarget()->getTargetWall())); + } + + return parent::getOwner($honourFlags, $real); + } } diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index eef84b6d..083f0750 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -38,6 +38,10 @@ final class CommentPresenter extends OpenVKPresenter $entity = $repo->get($eId); if(!$entity) $this->notFound(); + $flags = 0; + if($this->postParam("as_group") === "on") + $flags |= 0b10000000; + $photo = NULL; if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) { try { @@ -75,6 +79,7 @@ final class CommentPresenter extends OpenVKPresenter $comment->setTarget($entity->getId()); $comment->setContent($this->postParam("text")); $comment->setCreated(time()); + $comment->setFlags($flags); $comment->save(); if(!is_null($photo)) diff --git a/Web/Presenters/templates/components/comment.xml b/Web/Presenters/templates/components/comment.xml index fb67c566..cfea3148 100644 --- a/Web/Presenters/templates/components/comment.xml +++ b/Web/Presenters/templates/components/comment.xml @@ -1,7 +1,8 @@ {var author = $comment->getOwner()} +{var $Club = openvk\Web\Models\Entities\Club::class} - +
diff --git a/Web/Presenters/templates/components/comments.xml b/Web/Presenters/templates/components/comments.xml index eae83fad..cfc103c7 100644 --- a/Web/Presenters/templates/components/comments.xml +++ b/Web/Presenters/templates/components/comments.xml @@ -2,7 +2,8 @@
{var commentsURL = "/al_comments.pl/create/$model/" . $parent->getId()} - {include "textArea.xml", route => $commentsURL, postOpts => false, graffiti => (bool) ovkGetQuirk("comments.allow-graffiti")} + {var club = $parent instanceof \openvk\Web\Models\Entities\Post && $parent->getTargetWall() < 0 ? (new openvk\Web\Models\Repositories\Clubs)->get(abs($parent->getTargetWall())) : NULL} + {include "textArea.xml", route => $commentsURL, postOpts => false, graffiti => (bool) ovkGetQuirk("comments.allow-graffiti"), club => $club}
{if sizeof($comments) > 0} diff --git a/Web/Presenters/templates/components/textArea.xml b/Web/Presenters/templates/components/textArea.xml index 6192f6f5..9dce51ac 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -42,6 +42,11 @@ {_"contains_nsfw"} +
+ +
diff --git a/locales/en.strings b/locales/en.strings index e4b617df..4619f1c1 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -129,6 +129,7 @@ "attachment" = "Attachment"; "post_as_group" = "Post as group"; +"comment_as_group" = "Comment as group"; "add_signature" = "Add signature"; /* ^ can be translated as "author's signature". ^ */ "contains_nsfw" = "Contains NSFW content"; diff --git a/locales/ru.strings b/locales/ru.strings index 07746993..0109646b 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -132,6 +132,7 @@ "attachment" = "Вложение"; "post_as_group" = "От имени сообщества"; +"comment_as_group" = "От имени сообщества"; "add_signature" = "Подпись автора"; "contains_nsfw" = "Содержит NSFW-контент"; "nsfw_warning" = "Данный пост может содержать 18+ контент";