mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Allow adding comments to group admins
This commit allows you to add a comment to group administrators, which will be displayed in the list of administrators
This commit is contained in:
parent
dc10276621
commit
989cd8952b
8 changed files with 98 additions and 33 deletions
|
@ -90,6 +90,11 @@ class Club extends RowModel
|
|||
return (new Users)->get($this->getRecord()->owner);
|
||||
}
|
||||
|
||||
function getOwnerComment(): string
|
||||
{
|
||||
return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment;
|
||||
}
|
||||
|
||||
function getDescription(): ?string
|
||||
{
|
||||
return $this->getRecord()->about;
|
||||
|
@ -268,18 +273,6 @@ class Club extends RowModel
|
|||
{
|
||||
$rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6);
|
||||
|
||||
foreach($rels as $rel) {
|
||||
$rel = (new Users)->get($rel->user);
|
||||
if(!$rel) continue;
|
||||
|
||||
yield $rel;
|
||||
}
|
||||
}
|
||||
|
||||
function getManagersWithComment(int $page = 1): \Traversable
|
||||
{
|
||||
$rels = $this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")->page($page, 10);
|
||||
|
||||
foreach($rels as $rel) {
|
||||
$rel = (new Managers)->get($rel->id);
|
||||
if(!$rel) continue;
|
||||
|
@ -288,16 +281,16 @@ class Club extends RowModel
|
|||
}
|
||||
}
|
||||
|
||||
function getManager(User $user): ?Manager
|
||||
{
|
||||
return (new Managers)->getByUserAndClub($user->getId(), $this->getId());
|
||||
}
|
||||
|
||||
function getManagersCount(): int
|
||||
{
|
||||
return sizeof($this->getRecord()->related("group_coadmins.club")) + 1;
|
||||
}
|
||||
|
||||
function getManagersCountWithComment(): int
|
||||
{
|
||||
return sizeof($this->getRecord()->related("group_coadmins.club")->where("comment IS NOT NULL")) + 1;
|
||||
}
|
||||
|
||||
function addManager(User $user, ?string $comment = NULL): void
|
||||
{
|
||||
DB::i()->getContext()->table("group_coadmins")->insert([
|
||||
|
|
|
@ -17,7 +17,7 @@ class Manager extends RowModel
|
|||
return $this->getRecord()->id;
|
||||
}
|
||||
|
||||
function getUserId(): string
|
||||
function getUserId(): int
|
||||
{
|
||||
return $this->getRecord()->user;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class Manager extends RowModel
|
|||
return (new Users)->get($this->getRecord()->user);
|
||||
}
|
||||
|
||||
function getClubId(): string
|
||||
function getClubId(): int
|
||||
{
|
||||
return $this->getRecord()->club;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ final class GroupPresenter extends OpenVKPresenter
|
|||
{
|
||||
$user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user");
|
||||
$comment = $this->postParam("comment");
|
||||
$removeComment = $this->postParam("removeComment") === "1";
|
||||
//$index = $this->queryParam("index");
|
||||
if(!$user)
|
||||
$this->badRequest();
|
||||
|
@ -110,16 +111,34 @@ final class GroupPresenter extends OpenVKPresenter
|
|||
if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId())
|
||||
$this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс.");
|
||||
|
||||
/* if(!empty($index)){
|
||||
$manager = (new Managers)->get($index);
|
||||
$manager->setComment($comment);
|
||||
if($removeComment) {
|
||||
if($club->getOwner()->getId() == $user->getId()) {
|
||||
$club->setOwner_Comment(null);
|
||||
$club->save();
|
||||
} else {
|
||||
$manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId());
|
||||
$manager->setComment(null);
|
||||
$manager->save();
|
||||
}
|
||||
|
||||
$this->flashFail("succ", "Операция успешна", "Комментарий к администратору удален");
|
||||
} elseif($comment) {
|
||||
if(strlen($comment) > 36) {
|
||||
$commentLength = (string) strlen($comment);
|
||||
$this->flashFail("err", "Ошибка", "Комментарий слишком длинный ($commentLength символов вместо 36 символов)");
|
||||
return;
|
||||
}
|
||||
|
||||
if($club->getOwner()->getId() == $user->getId()) {
|
||||
$club->setOwner_Comment($comment);
|
||||
$club->save();
|
||||
} else {
|
||||
$manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId());
|
||||
$manager->setComment($comment);
|
||||
$manager->save();
|
||||
}
|
||||
|
||||
$this->flashFail("succ", "Операция успешна", "Комментарий к администратору изменён");
|
||||
}else{ */
|
||||
if($comment) {
|
||||
$manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId());
|
||||
$manager->setComment($comment);
|
||||
$manager->save();
|
||||
$this->flashFail("succ", "Операция успешна", ".");
|
||||
}else{
|
||||
if($club->canBeModifiedBy($user)) {
|
||||
$club->removeManager($user);
|
||||
|
|
|
@ -46,16 +46,36 @@
|
|||
{$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")}
|
||||
</td>
|
||||
</tr>
|
||||
<tr n:if="$club->canBeModifiedBy($thisUser ?? NULL) && $club->getOwner()->getId() !== $x->getId()">
|
||||
{var manager = $club->getManager($x)}
|
||||
<tr n:if="$manager && !empty($manager->getComment()) || $club->getOwner()->getId() === $x->getId() && !empty($club->getOwnerComment())">
|
||||
<td width="120" valign="top"><span class="nobold">{_comment}: </span></td>
|
||||
<td>
|
||||
{if $club->getOwner()->getId() === $x->getId()}
|
||||
{$club->getOwnerComment()}
|
||||
{else}
|
||||
{$manager->getComment()}
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
<tr n:if="$club->canBeModifiedBy($thisUser ?? NULL) && $club->getOwner()->getId() !== $x->getId() || $club->getOwner()->getId() == $x->getId()">
|
||||
<td width="120" valign="top"><span class="nobold">{_actions}: </span></td>
|
||||
<td>
|
||||
<a href="/club{$club->getId()}/setAdmin.jsp?user={$x->getId()}&hash={rawurlencode($csrfToken)}">
|
||||
{if $club->canBeModifiedBy($x)}
|
||||
<a href="/club{$club->getId()}/setAdmin.jsp?user={$x->getId()}&hash={rawurlencode($csrfToken)}" n:if="$club->getOwner()->getId() !== $x->getId()">
|
||||
{if $manager}
|
||||
{_devote}
|
||||
{else}
|
||||
{_promote_to_admin}
|
||||
{/if}
|
||||
</a>
|
||||
{if $manager}
|
||||
|
|
||||
<a href="javascript:setClubAdminComment('{$club->getId()}', '{$manager->getUserId()}', '{rawurlencode($csrfToken)}')">
|
||||
{_set_comment}
|
||||
</a>
|
||||
{/if}
|
||||
<a n:if="$club->getOwner()->getId() === $x->getId()" href="javascript:setClubAdminComment('{$club->getId()}', '{$club->getOwner()->getId()}', '{rawurlencode($csrfToken)}')">
|
||||
{_set_comment}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -114,6 +114,10 @@
|
|||
<ul>
|
||||
<li>
|
||||
<a href="{$author->getURL()}"><b>{$author->getCanonicalName()}</b></a>
|
||||
{if !empty($club->getOwnerComment())}
|
||||
<br>
|
||||
<b>{$club->getOwnerComment()}</b>
|
||||
{/if}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -127,9 +131,17 @@
|
|||
<ul>
|
||||
<li>
|
||||
<a href="{$author->getURL()}"><b>{$author->getCanonicalName()}</b></a>
|
||||
{if !empty($club->getOwnerComment())}
|
||||
<br>
|
||||
<b>{$club->getOwnerComment()}</b>
|
||||
{/if}
|
||||
</li>
|
||||
<li n:foreach="$club->getManagers(1) as $manager">
|
||||
<a href="{$manager->getURL()}"><b>{$manager->getCanonicalName()}</b></a>
|
||||
<a href="{$manager->getUser()->getURL()}"><b>{$manager->getUser()->getCanonicalName()}</b></a>
|
||||
{if !empty($manager->getComment())}
|
||||
<br>
|
||||
<b>{$manager->getComment()}</b>
|
||||
{/if}
|
||||
</li>
|
||||
{var managersCount = $club->getManagersCount()}
|
||||
<li n:if="$managersCount > 7">
|
||||
|
|
|
@ -105,3 +105,23 @@ function repostPost(id, hash) {
|
|||
Function.noop
|
||||
]);
|
||||
}
|
||||
|
||||
function setClubAdminComment(clubId, adminId, hash) {
|
||||
MessageBox("Изменить комментарий к администратору", `
|
||||
<form action="/club${clubId}/setAdmin.jsp" method="post" id="uClubAdminCommentForm_${clubId}_${adminId}">
|
||||
<input type="hidden" name="user" value="${adminId}">
|
||||
<input type="hidden" name="hash" value="${hash}">
|
||||
<input type="hidden" name="removeComment" id="uClubAdminCommentRemoveCommentInput_${clubId}_${adminId}" value="0">
|
||||
<textarea name="comment" id="uClubAdminCommentTextArea_${clubId}_${adminId}"></textarea><br><br>
|
||||
</form>
|
||||
`, ["Изменить", "Отменить"], [
|
||||
() => {
|
||||
if (document.querySelector(`#uClubAdminCommentTextArea_${clubId}_${adminId}`).value === "") {
|
||||
document.querySelector(`#uClubAdminCommentRemoveCommentInput_${clubId}_${adminId}`).value = "1";
|
||||
}
|
||||
|
||||
document.querySelector(`#uClubAdminCommentForm_${clubId}_${adminId}`).submit();
|
||||
},
|
||||
Function.noop
|
||||
]);
|
||||
}
|
||||
|
|
1
install/sqls/00006-group-owner-comment.sql
Normal file
1
install/sqls/00006-group-owner-comment.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE groups ADD COLUMN owner_comment VARCHAR(36) AFTER owner;
|
2
locales
2
locales
|
@ -1 +1 @@
|
|||
Subproject commit c3127e1af00fa19e88acdf1c8ce0ebe74a61d6d4
|
||||
Subproject commit dc078637401a673476ef294e5fdf020948dcaba8
|
Loading…
Reference in a new issue