Improvements related to group admins

Changes:
1. Add the ability to display only administrators on the page with a list of subscribers
2. Add the ability to hide the fact that the subscriber is an administrator
3. Fix display of large text in the block with the list of administrators
4. Fix display of the number of administrators
This commit is contained in:
Maxim Leshchenko 2021-11-07 22:06:09 +02:00
parent 610b2bda6d
commit 848683b1d6
9 changed files with 111 additions and 29 deletions

View file

@ -95,6 +95,11 @@ class Club extends RowModel
return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment; return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment;
} }
function isOwnerHidden(): bool
{
return (bool) $this->getRecord()->owner_hidden;
}
function getDescription(): ?string function getDescription(): ?string
{ {
return $this->getRecord()->about; return $this->getRecord()->about;
@ -269,9 +274,13 @@ class Club extends RowModel
} }
} }
function getManagers(int $page = 1): \Traversable function getManagers(int $page = 1, bool $ignoreHidden = false): \Traversable
{ {
if($ignoreHidden) {
$rels = $this->getRecord()->related("group_coadmins.club")->where("hidden", false)->page($page, 6);
} else {
$rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6); $rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6);
}
foreach($rels as $rel) { foreach($rels as $rel) {
$rel = (new Managers)->get($rel->id); $rel = (new Managers)->get($rel->id);
@ -281,15 +290,25 @@ class Club extends RowModel
} }
} }
function getManager(User $user): ?Manager function getManager(User $user, bool $ignoreHidden = false): ?Manager
{ {
return (new Managers)->getByUserAndClub($user->getId(), $this->getId()); $manager = (new Managers)->getByUserAndClub($user->getId(), $this->getId());
if ($ignoreHidden && $manager !== null && $manager->isHidden()) {
$manager = null;
} }
function getManagersCount(): int return $manager;
}
function getManagersCount(bool $ignoreHidden = false): int
{ {
if ($ignoreHidden) {
return sizeof($this->getRecord()->related("group_coadmins.club")->where("hidden", false)) + (int) !$this->isOwnerHidden();
} else {
return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; return sizeof($this->getRecord()->related("group_coadmins.club")) + 1;
} }
}
function addManager(User $user, ?string $comment = NULL): void function addManager(User $user, ?string $comment = NULL): void
{ {

View file

@ -42,5 +42,10 @@ class Manager extends RowModel
return is_null($this->getRecord()->comment) ? "" : $this->getRecord()->comment; return is_null($this->getRecord()->comment) ? "" : $this->getRecord()->comment;
} }
function isHidden(): bool
{
return (bool) $this->getRecord()->hidden;
}
use Traits\TSubscribable; use Traits\TSubscribable;
} }

View file

@ -84,8 +84,22 @@ final class GroupPresenter extends OpenVKPresenter
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$this->template->club = $this->clubs->get($id); $this->template->club = $this->clubs->get($id);
$this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1";
if($this->template->onlyShowManagers) {
$this->template->followers = null;
$this->template->managers = $this->template->club->getManagers((int) ($this->queryParam("p") ?? 1), !$this->template->club->canBeModifiedBy($this->user->identity));
if($this->template->club->canBeModifiedBy($this->user->identity) || !$this->template->club->isOwnerHidden()) {
$this->template->managers = array_merge(array($this->template->club->getOwner()), iterator_to_array($this->template->managers));
}
$this->template->count = $this->template->club->getManagersCount();
} else {
$this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1)); $this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1));
$this->template->managers = null;
$this->template->count = $this->template->club->getFollowersCount(); $this->template->count = $this->template->club->getFollowersCount();
}
$this->template->paginatorConf = (object) [ $this->template->paginatorConf = (object) [
"count" => $this->template->count, "count" => $this->template->count,
"page" => $this->queryParam("p") ?? 1, "page" => $this->queryParam("p") ?? 1,
@ -99,6 +113,7 @@ final class GroupPresenter extends OpenVKPresenter
$user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user"); $user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user");
$comment = $this->postParam("comment"); $comment = $this->postParam("comment");
$removeComment = $this->postParam("removeComment") === "1"; $removeComment = $this->postParam("removeComment") === "1";
$hidden = $this->queryParam("hidden") === "1" ? true : ($this->queryParam("hidden") === "0" ? false : null);
//$index = $this->queryParam("index"); //$index = $this->queryParam("index");
if(!$user) if(!$user)
$this->badRequest(); $this->badRequest();
@ -111,7 +126,27 @@ final class GroupPresenter extends OpenVKPresenter
if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId())
$this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс.");
if($removeComment) { if($hidden !== null) {
if($club->getOwner()->getId() == $user->getId()) {
$club->setOwner_Hidden($hidden);
$club->save();
} else {
$manager = (new Managers)->getByUserAndClub($user->getId(), $club->getId());
$manager->setHidden($hidden);
$manager->save();
}
if($club->getManagersCount(true) == 0) {
$club->setAdministrators_List_Display(2);
$club->save();
}
if($hidden) {
$this->flashFail("succ", "Операция успешна", "Теперь " . $user->getCanonicalName() . " будет показываться как обычный подписчик всем кроме других администраторов");
} else {
$this->flashFail("succ", "Операция успешна", "Теперь все будут знать про то что " . $user->getCanonicalName() . " - администратор");
}
} elseif($removeComment) {
if($club->getOwner()->getId() == $user->getId()) { if($club->getOwner()->getId() == $user->getId()) {
$club->setOwner_Comment(null); $club->setOwner_Comment(null);
$club->save(); $club->save();

View file

@ -74,8 +74,9 @@
<span class="nobold">{_group_administrators_list}: </span> <span class="nobold">{_group_administrators_list}: </span>
</td> </td>
<td> <td>
<input type="radio" name="administrators_list_display" value="0" {if $club->getAdministratorsListDisplay() == 0}checked{/if}/> {_group_display_only_creator}<br> {var isAllAdminsHidden = $club->getManagersCount(true) == 0}
<input type="radio" name="administrators_list_display" value="1" {if $club->getAdministratorsListDisplay() == 1}checked{/if}/> {_group_display_all_administrators}<br> <input type="radio" name="administrators_list_display" value="0" {if $club->getAdministratorsListDisplay() == 0}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_only_creator}<br>
<input type="radio" name="administrators_list_display" value="1" {if $club->getAdministratorsListDisplay() == 1}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_all_administrators}<br>
<input type="radio" name="administrators_list_display" value="2" {if $club->getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}<br> <input type="radio" name="administrators_list_display" value="2" {if $club->getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}<br>
</td> </td>
</tr> </tr>

View file

@ -1,5 +1,6 @@
{extends "../@listView.xml"} {extends "../@listView.xml"}
{var iterator = $followers} {var $Manager = openvk\Web\Models\Entities\Manager::class}
{var iterator = $onlyShowManagers ? $managers : $followers}
{var count = $paginatorConf->count} {var count = $paginatorConf->count}
{var page = $paginatorConf->page} {var page = $paginatorConf->page}
{var perPage = 6} {var perPage = 6}
@ -9,6 +10,8 @@
{block header} {block header}
<a href="{$club->getURL()}">{$club->getCanonicalName()}</a> <a href="{$club->getURL()}">{$club->getCanonicalName()}</a>
» {_followers} » {_followers}
<a n:if="!$onlyShowManagers" href="/club{$club->getId()}/followers?onlyAdmins=1" style="float: right;">{_all_followers}</a>
<a n:if="$onlyShowManagers" href="/club{$club->getId()}/followers" style="float: right;">{_only_administrators}</a>
{/block} {/block}
{block actions} {block actions}
@ -38,49 +41,50 @@
{/block} {/block}
{block link|strip|stripHtml} {block link|strip|stripHtml}
/id{$x->getId()} /id{$x instanceof $Manager ? $x->getUserId() : $x->getId()}
{/block} {/block}
{block preview} {block preview}
<img src="{$x->getAvatarURL()}" alt="{$x->getCanonicalName()}" width=75 /> <img src="{$x instanceof $Manager ? $x->getUser()->getAvatarURL() : $x->getAvatarURL()}" alt="{$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()}" width=75 />
{/block} {/block}
{block name} {block name}
{$x->getCanonicalName()} {$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()}
{/block} {/block}
{block description} {block description}
{var user = $x instanceof $Manager ? $x->getUser() : $x}
{var manager = $x instanceof $Manager ? $x : $club->getManager($user, !$club->canBeModifiedBy($thisUser))}
<table> <table>
<tbody> <tbody>
<tr> <tr>
<td width="120" valign="top"><span class="nobold">{_"gender"}: </span></td> <td width="120" valign="top"><span class="nobold">{_"gender"}: </span></td>
<td>{$x->isFemale() ? "женский" : "мужской"}</td> <td>{$user->isFemale() ? "женский" : "мужской"}</td>
</tr> </tr>
<tr> <tr>
<td width="120" valign="top"><span class="nobold">{_"registration_date"}: </span></td> <td width="120" valign="top"><span class="nobold">{_"registration_date"}: </span></td>
<td>{$x->getRegistrationTime()}</td> <td>{$user->getRegistrationTime()}</td>
</tr> </tr>
<tr> <tr>
<td width="120" valign="top"><span class="nobold">{_role}: </span></td> <td width="120" valign="top"><span class="nobold">{_role}: </span></td>
<td> <td>
{$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")} {$manager || $club->getOwner()->getId() == $user->getId() && !$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser) ? tr("administrator") : tr("follower")}
</td> </td>
</tr> </tr>
{var manager = $club->getManager($x)} <tr n:if="$manager && !empty($manager->getComment()) || $club->getOwner()->getId() === $user->getId() && !empty($club->getOwnerComment()) && (!$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser))">
<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 width="120" valign="top"><span class="nobold">{_comment}: </span></td>
<td> <td>
{if $club->getOwner()->getId() === $x->getId()} {if $club->getOwner()->getId() === $user->getId()}
{$club->getOwnerComment()} {$club->getOwnerComment()}
{else} {else}
{$manager->getComment()} {$manager->getComment()}
{/if} {/if}
</td> </td>
</tr> </tr>
<tr n:if="$club->canBeModifiedBy($thisUser ?? NULL) && $club->getOwner()->getId() !== $x->getId() || $club->getOwner()->getId() == $x->getId()"> <tr n:if="$club->canBeModifiedBy($thisUser ?? NULL)">
<td width="120" valign="top"><span class="nobold">{_actions}: </span></td> <td width="120" valign="top"><span class="nobold">{_actions}: </span></td>
<td> <td>
<a href="/club{$club->getId()}/setAdmin.jsp?user={$x->getId()}&hash={rawurlencode($csrfToken)}" n:if="$club->getOwner()->getId() !== $x->getId()"> <a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hash={rawurlencode($csrfToken)}" n:if="$club->getOwner()->getId() !== $user->getId()">
{if $manager} {if $manager}
{_devote} {_devote}
{else} {else}
@ -93,9 +97,21 @@
{_set_comment} {_set_comment}
</a> </a>
{/if} {/if}
<a n:if="$club->getOwner()->getId() === $x->getId()" href="javascript:setClubAdminComment('{$club->getId()}', '{$club->getOwner()->getId()}', '{rawurlencode($csrfToken)}')"> <a n:if="$club->getOwner()->getId() === $user->getId()" href="javascript:setClubAdminComment('{$club->getId()}', '{$club->getOwner()->getId()}', '{rawurlencode($csrfToken)}')">
{_set_comment} {_set_comment}
</a> </a>
{if $manager}
|
<a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hidden={(int) !$manager->isHidden()}&hash={rawurlencode($csrfToken)}">
{if $manager->isHidden()}{_hidden_yes}{else}{_hidden_no}{/if}
</a>
{/if}
{if $club->getOwner()->getId() == $user->getId()}
|
<a href="/club{$club->getId()}/setAdmin.jsp?user={$user->getId()}&hidden={(int) !$club->isOwnerHidden()}&hash={rawurlencode($csrfToken)}">
{if $club->isOwnerHidden()}{_hidden_yes}{else}{_hidden_no}{/if}
</a>
{/if}
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -131,10 +131,13 @@
</div> </div>
<div> <div>
<div class="content_subtitle"> <div class="content_subtitle">
{tr("administrators", $club->getManagersCount() + 1)} {tr("administrators", $club->getManagersCount(true))}
<div style="float: right;">
<a href="/club{$club->getId()}/followers?onlyAdmins=1">{_"all_title"}</a>
</div>
</div> </div>
<div class="avatar-list"> <div class="avatar-list">
<div class="avatar-list-item"> <div class="avatar-list-item" n:if="!$club->isOwnerHidden()">
{var author = $club->getOwner()} {var author = $club->getOwner()}
<div class="avatar"> <div class="avatar">
<a href="{$author->getURL()}"> <a href="{$author->getURL()}">
@ -146,7 +149,7 @@
<div class="subtitle" n:if="!empty($club->getOwnerComment())">{$club->getOwnerComment()}</div> <div class="subtitle" n:if="!empty($club->getOwnerComment())">{$club->getOwnerComment()}</div>
</div> </div>
</div> </div>
<div class="avatar-list-item" n:foreach="$club->getManagers(1) as $manager"> <div class="avatar-list-item" n:foreach="$club->getManagers(1, true) as $manager">
{var user = $manager->getUser()} {var user = $manager->getUser()}
<div class="avatar"> <div class="avatar">
<a href="{$user->getURL()}"> <a href="{$user->getURL()}">

View file

@ -1480,6 +1480,7 @@ body.scrolled .toTop:hover {
.avatar-list-item .info { .avatar-list-item .info {
float: left; float: left;
padding-left: 8px; padding-left: 8px;
width: 134px;
} }
.avatar-list-item .info-without-subtitle-centered { .avatar-list-item .info-without-subtitle-centered {

View file

@ -0,0 +1,2 @@
ALTER TABLE group_coadmins ADD COLUMN hidden BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE groups ADD COLUMN owner_hidden BOOLEAN NOT NULL DEFAULT FALSE AFTER owner_comment;

@ -1 +1 @@
Subproject commit ce4ede6f8c6cb42f2421969fab23da933c81b52b Subproject commit b1c49d9b3aa7aa0a7421aa853c60af0007196f84