Groups: Add the ability to write comments on behalf of the group

This commit is contained in:
Maxim Leshchenko 2021-12-04 21:46:26 +02:00
parent 7591c1082b
commit 021971289d
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
7 changed files with 33 additions and 2 deletions

View file

@ -1,5 +1,7 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace openvk\Web\Models\Entities; namespace openvk\Web\Models\Entities;
use openvk\Web\Models\Repositories\Clubs;
use openvk\Web\Models\RowModel;
class Comment extends Post class Comment extends Post
{ {
@ -24,4 +26,19 @@ class Comment extends Post
return $entity; return $entity;
} }
/**
* May return fake owner (group), if flags are [1, (*)]
*
* @param bool $honourFlags - check flags
*/
function getOwner(bool $honourFlags = true, bool $real = false): RowModel
{
if($honourFlags && $this->isPostedOnBehalfOfGroup()) {
if($this->getTarget() instanceof Post)
return (new Clubs)->get(abs($this->getTarget()->getTargetWall()));
}
return parent::getOwner($honourFlags, $real);
}
} }

View file

@ -38,6 +38,10 @@ final class CommentPresenter extends OpenVKPresenter
$entity = $repo->get($eId); $entity = $repo->get($eId);
if(!$entity) $this->notFound(); if(!$entity) $this->notFound();
$flags = 0;
if($this->postParam("as_group") === "on")
$flags |= 0b10000000;
$photo = NULL; $photo = NULL;
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) { if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
try { try {
@ -75,6 +79,7 @@ final class CommentPresenter extends OpenVKPresenter
$comment->setTarget($entity->getId()); $comment->setTarget($entity->getId());
$comment->setContent($this->postParam("text")); $comment->setContent($this->postParam("text"));
$comment->setCreated(time()); $comment->setCreated(time());
$comment->setFlags($flags);
$comment->save(); $comment->save();
if(!is_null($photo)) if(!is_null($photo))

View file

@ -1,7 +1,8 @@
{var author = $comment->getOwner()} {var author = $comment->getOwner()}
{var $Club = openvk\Web\Models\Entities\Club::class}
<a name="cid={$comment->getId()}"></a> <a name="cid={$comment->getId()}"></a>
<table border="0" style="font-size: 11px;" class="post comment" id="_comment{$comment->getId()}" data-comment-id="{$comment->getId()}" data-owner-id="{$author->getId()}"> <table border="0" style="font-size: 11px;" class="post comment" id="_comment{$comment->getId()}" data-comment-id="{$comment->getId()}" data-owner-id="{$author->getId()}" data-from-group="{$comment->getOwner() instanceof $Club}">
<tbody> <tbody>
<tr> <tr>
<td width="30" valign="top"> <td width="30" valign="top">

View file

@ -2,7 +2,8 @@
<div n:ifset="$thisUser"> <div n:ifset="$thisUser">
{var commentsURL = "/al_comments.pl/create/$model/" . $parent->getId()} {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}
</div> </div>
{if sizeof($comments) > 0} {if sizeof($comments) > 0}

View file

@ -42,6 +42,11 @@
<input type="checkbox" name="nsfw" /> {_"contains_nsfw"} <input type="checkbox" name="nsfw" /> {_"contains_nsfw"}
</label> </label>
</div> </div>
<div n:if="!($postOpts ?? true) && !is_null($thisUser) && !is_null($club ?? NULL) && $club->canBeModifiedBy($thisUser)" class="post-opts">
<label>
<input type="checkbox" name="as_group" /> {_"comment_as_group"}
</label>
</div>
<input type="file" class="postFileSel" id="postFilePic" name="_pic_attachment" accept="image/*" style="display:none;" /> <input type="file" class="postFileSel" id="postFilePic" name="_pic_attachment" accept="image/*" style="display:none;" />
<input type="file" class="postFileSel" id="postFileVid" name="_vid_attachment" accept="video/*" style="display:none;" /> <input type="file" class="postFileSel" id="postFileVid" name="_vid_attachment" accept="video/*" style="display:none;" />
<input type="hidden" name="type" value="1" /> <input type="hidden" name="type" value="1" />

View file

@ -129,6 +129,7 @@
"attachment" = "Attachment"; "attachment" = "Attachment";
"post_as_group" = "Post as group"; "post_as_group" = "Post as group";
"comment_as_group" = "Comment as group";
"add_signature" = "Add signature"; "add_signature" = "Add signature";
/* ^ can be translated as "author's signature". ^ */ /* ^ can be translated as "author's signature". ^ */
"contains_nsfw" = "Contains NSFW content"; "contains_nsfw" = "Contains NSFW content";

View file

@ -132,6 +132,7 @@
"attachment" = "Вложение"; "attachment" = "Вложение";
"post_as_group" = "От имени сообщества"; "post_as_group" = "От имени сообщества";
"comment_as_group" = "От имени сообщества";
"add_signature" = "Подпись автора"; "add_signature" = "Подпись автора";
"contains_nsfw" = "Содержит NSFW-контент"; "contains_nsfw" = "Содержит NSFW-контент";
"nsfw_warning" = "Данный пост может содержать 18+ контент"; "nsfw_warning" = "Данный пост может содержать 18+ контент";