From 848683b1d6cc4da7732eb81bef152a70d6ff5b3c Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Sun, 7 Nov 2021 22:06:09 +0200 Subject: [PATCH] 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 --- Web/Models/Entities/Club.php | 31 +++++++++++--- Web/Models/Entities/Manager.php | 5 +++ Web/Presenters/GroupPresenter.php | 43 ++++++++++++++++++-- Web/Presenters/templates/Group/Edit.xml | 5 ++- Web/Presenters/templates/Group/Followers.xml | 42 +++++++++++++------ Web/Presenters/templates/Group/View.xml | 9 ++-- Web/static/css/style.css | 1 + install/sqls/00007-hidden-admins.sql | 2 + locales | 2 +- 9 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 install/sqls/00007-hidden-admins.sql diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 65353fc7..e8c84fb4 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -94,6 +94,11 @@ class Club extends RowModel { return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment; } + + function isOwnerHidden(): bool + { + return (bool) $this->getRecord()->owner_hidden; + } function getDescription(): ?string { @@ -269,9 +274,13 @@ class Club extends RowModel } } - function getManagers(int $page = 1): \Traversable + function getManagers(int $page = 1, bool $ignoreHidden = false): \Traversable { - $rels = $this->getRecord()->related("group_coadmins.club")->page($page, 6); + 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); + } foreach($rels as $rel) { $rel = (new Managers)->get($rel->id); @@ -281,14 +290,24 @@ 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; + } + + return $manager; } - function getManagersCount(): int + function getManagersCount(bool $ignoreHidden = false): int { - return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; + 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; + } } function addManager(User $user, ?string $comment = NULL): void diff --git a/Web/Models/Entities/Manager.php b/Web/Models/Entities/Manager.php index e58eef6e..b1c10924 100644 --- a/Web/Models/Entities/Manager.php +++ b/Web/Models/Entities/Manager.php @@ -41,6 +41,11 @@ class Manager extends RowModel { return is_null($this->getRecord()->comment) ? "" : $this->getRecord()->comment; } + + function isHidden(): bool + { + return (bool) $this->getRecord()->hidden; + } use Traits\TSubscribable; } diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 16ac32ea..4b862a7b 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -83,9 +83,23 @@ final class GroupPresenter extends OpenVKPresenter { $this->assertUserLoggedIn(); - $this->template->club = $this->clubs->get($id); - $this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1)); - $this->template->count = $this->template->club->getFollowersCount(); + $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->managers = null; + $this->template->count = $this->template->club->getFollowersCount(); + } + $this->template->paginatorConf = (object) [ "count" => $this->template->count, "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"); $comment = $this->postParam("comment"); $removeComment = $this->postParam("removeComment") === "1"; + $hidden = $this->queryParam("hidden") === "1" ? true : ($this->queryParam("hidden") === "0" ? false : null); //$index = $this->queryParam("index"); if(!$user) $this->badRequest(); @@ -111,7 +126,27 @@ final class GroupPresenter extends OpenVKPresenter if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) $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()) { $club->setOwner_Comment(null); $club->save(); diff --git a/Web/Presenters/templates/Group/Edit.xml b/Web/Presenters/templates/Group/Edit.xml index aaaeefee..23778181 100644 --- a/Web/Presenters/templates/Group/Edit.xml +++ b/Web/Presenters/templates/Group/Edit.xml @@ -74,8 +74,9 @@ {_group_administrators_list}: - getAdministratorsListDisplay() == 0}checked{/if}/> {_group_display_only_creator}
- getAdministratorsListDisplay() == 1}checked{/if}/> {_group_display_all_administrators}
+ {var isAllAdminsHidden = $club->getManagersCount(true) == 0} + getAdministratorsListDisplay() == 0}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_only_creator}
+ getAdministratorsListDisplay() == 1}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_all_administrators}
getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}
diff --git a/Web/Presenters/templates/Group/Followers.xml b/Web/Presenters/templates/Group/Followers.xml index 56f041ff..1b34c5e3 100644 --- a/Web/Presenters/templates/Group/Followers.xml +++ b/Web/Presenters/templates/Group/Followers.xml @@ -1,5 +1,6 @@ {extends "../@listView.xml"} -{var iterator = $followers} +{var $Manager = openvk\Web\Models\Entities\Manager::class} +{var iterator = $onlyShowManagers ? $managers : $followers} {var count = $paginatorConf->count} {var page = $paginatorConf->page} {var perPage = 6} @@ -9,6 +10,8 @@ {block header} {$club->getCanonicalName()} » {_followers} + {_all_followers} + {_only_administrators} {/block} {block actions} @@ -38,49 +41,50 @@ {/block} {block link|strip|stripHtml} - /id{$x->getId()} + /id{$x instanceof $Manager ? $x->getUserId() : $x->getId()} {/block} {block preview} - {$x->getCanonicalName()} + {$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()} {/block} {block name} - {$x->getCanonicalName()} + {$x instanceof $Manager ? $x->getUser()->getCanonicalName() : $x->getCanonicalName()} {/block} {block description} + {var user = $x instanceof $Manager ? $x->getUser() : $x} + {var manager = $x instanceof $Manager ? $x : $club->getManager($user, !$club->canBeModifiedBy($thisUser))} - + - + - {var manager = $club->getManager($x)} - + - + diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index af761183..81885d2e 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -131,10 +131,13 @@
- {tr("administrators", $club->getManagersCount() + 1)} + {tr("administrators", $club->getManagersCount(true))} +
+ {_"all_title"} +
{_"gender"}: {$x->isFemale() ? "женский" : "мужской"}{$user->isFemale() ? "женский" : "мужской"}
{_"registration_date"}: {$x->getRegistrationTime()}{$user->getRegistrationTime()}
{_role}: - {$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")} + {$manager || $club->getOwner()->getId() == $user->getId() && !$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser) ? tr("administrator") : tr("follower")}
{_comment}: - {if $club->getOwner()->getId() === $x->getId()} + {if $club->getOwner()->getId() === $user->getId()} {$club->getOwnerComment()} {else} {$manager->getComment()} {/if}
{_actions}: - + {if $manager} {_devote} {else} @@ -93,9 +97,21 @@ {_set_comment} {/if} - + {_set_comment} + {if $manager} + | + + {if $manager->isHidden()}{_hidden_yes}{else}{_hidden_no}{/if} + + {/if} + {if $club->getOwner()->getId() == $user->getId()} + | + + {if $club->isOwnerHidden()}{_hidden_yes}{else}{_hidden_no}{/if} + + {/if}