From e3358fcfa5876cb81c36a5106cadbc06da688d0f Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Wed, 10 Nov 2021 10:45:06 +0200 Subject: [PATCH 1/4] Pinning groups to the left menu This commit allows you to pin groups to the left menu (max 10 groups, only those in which you are the administrator) from the My Groups page. Fixes #186 --- Web/Models/Entities/Club.php | 5 ++++ Web/Models/Entities/Manager.php | 5 ++++ Web/Models/Entities/User.php | 32 +++++++++++++++++++++++ Web/Presenters/UserPresenter.php | 33 ++++++++++++++++++++++++ Web/Presenters/templates/@layout.xml | 6 +++++ Web/Presenters/templates/User/Groups.xml | 19 ++++++++++++++ Web/routes.yml | 2 ++ install/sqls/00009-pinned-clubs.sql | 2 ++ locales | 2 +- 9 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 install/sqls/00009-pinned-clubs.sql diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 65353fc7..0a4843e9 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -95,6 +95,11 @@ class Club extends RowModel return is_null($this->getRecord()->owner_comment) ? "" : $this->getRecord()->owner_comment; } + function isOwnerClubPinned(): bool + { + return (bool) $this->getRecord()->owner_club_pinned; + } + function getDescription(): ?string { return $this->getRecord()->about; diff --git a/Web/Models/Entities/Manager.php b/Web/Models/Entities/Manager.php index e58eef6e..272e9d82 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 isClubPinned(): bool + { + return (bool) $this->getRecord()->club_pinned; + } use Traits\TSubscribable; } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 68585168..16c4692f 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -473,6 +473,38 @@ class User extends RowModel return sizeof($sel); } + function getPinnedClubs(): \Traversable + { + foreach($this->getRecord()->related("groups.owner")->where("owner_club_pinned", true) as $target) { + $target = (new Clubs)->get($target->id); + if(!$target) continue; + + yield $target; + } + + foreach($this->getRecord()->related("group_coadmins.user")->where("club_pinned", true) as $target) { + $target = (new Clubs)->get($target->club); + if(!$target) continue; + + yield $target; + } + } + + function getPinnedClubCount(): int + { + return sizeof($this->getRecord()->related("groups.owner")->where("owner_club_pinned", true)) + sizeof($this->getRecord()->related("group_coadmins.user")->where("club_pinned", true)); + } + + function isClubPinned(Club $club): bool + { + if($club->getOwner()->getId() === $this->getId()) + return $club->isOwnerClubPinned(); + + $manager = $club->getManager($this); + if(!is_null($manager)) + return $manager->isClubPinned(); + } + function getMeetings(int $page = 1): \Traversable { $sel = $this->getRecord()->related("event_turnouts.user")->page($page, OPENVK_DEFAULT_PER_PAGE); diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 1bf2ddbd..e4d1e7ab 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -4,6 +4,7 @@ use openvk\Web\Util\Sms; use openvk\Web\Themes\Themepacks; use openvk\Web\Models\Entities\Photo; use openvk\Web\Models\Repositories\Users; +use openvk\Web\Models\Repositories\Clubs; use openvk\Web\Models\Repositories\Albums; use openvk\Web\Models\Repositories\Videos; use openvk\Web\Models\Repositories\Notes; @@ -80,6 +81,38 @@ final class UserPresenter extends OpenVKPresenter $this->template->page = $this->queryParam("p") ?? 1; } } + + function renderPinClub(): void + { + $this->assertUserLoggedIn(); + + $club = (new Clubs)->get((int) $this->queryParam("club")); + if(!$club) + $this->notFound(); + + if(!$club->canBeModifiedBy($this->user->identity ?? NULL)) + $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); + + $isClubPinned = $this->user->identity->isClubPinned($club); + if(!$isClubPinned && $this->user->identity->getPinnedClubCount() > 10) + $this->flashFail("err", "Ошибка", "Находится в левом меню могут максимум 10 групп"); + + if($club->getOwner()->getId() === $this->user->identity->getId()) { + $club->setOwner_Club_Pinned(!$isClubPinned); + $club->save(); + } else { + $manager = $club->getManager($this->user->identity); + if(!is_null($manager)) { + $manager->setClub_Pinned(!$isClubPinned); + $manager->save(); + } + } + + if($isClubPinned) + $this->flashFail("succ", "Операция успешна", "Группа " . $club->getName() . " была успешно удалена из левого меню"); + else + $this->flashFail("succ", "Операция успешна", "Группа " . $club->getName() . " была успешно добавлена в левое меню"); + } function renderEdit(): void { diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 2907f524..bc71b1aa 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -169,6 +169,12 @@ href="{$menuItem['url']}" target="_blank" class="link">{$menuItem["name"]} +
+ {$club->getName()} getDescription()} + {if $x->canBeModifiedBy($thisUser ?? NULL)} + {var clubPinned = $thisUser->isClubPinned($x)} + + + + + + + +
{_actions}: + + {if $clubPinned} + {_remove_from_sidebar} + {else} + {_add_to_sidebar} + {/if} + +
+ {/if} {/block} diff --git a/Web/routes.yml b/Web/routes.yml index 014cb358..5bd51261 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -151,6 +151,8 @@ routes: handler: "Group->modifyAdmin" - url: "/groups{num}" handler: "User->groups" + - url: "/groups_pin" + handler: "User->pinClub" - url: "/groups_create" handler: "Group->create" - url: "/audios{num}" diff --git a/install/sqls/00009-pinned-clubs.sql b/install/sqls/00009-pinned-clubs.sql new file mode 100644 index 00000000..f5c57149 --- /dev/null +++ b/install/sqls/00009-pinned-clubs.sql @@ -0,0 +1,2 @@ +ALTER TABLE `groups` ADD COLUMN `owner_club_pinned` BOOLEAN NOT NULL DEFAULT FALSE AFTER `owner_hidden`; +ALTER TABLE `group_coadmins` ADD COLUMN `club_pinned` BOOLEAN DEFAULT FALSE NOT NULL; diff --git a/locales b/locales index ce4ede6f..a4003623 160000 --- a/locales +++ b/locales @@ -1 +1 @@ -Subproject commit ce4ede6f8c6cb42f2421969fab23da933c81b52b +Subproject commit a4003623be856185679a7976423b7914455d8ab9 From 3f74e426be3c03b57b95a8ad01753dcfe02a0d5a Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko <50026114+maksalees@users.noreply.github.com> Date: Fri, 12 Nov 2021 11:32:22 +0200 Subject: [PATCH 2/4] Pinning groups to the left menu: Correct name of the strings --- Web/Presenters/templates/User/Groups.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Web/Presenters/templates/User/Groups.xml b/Web/Presenters/templates/User/Groups.xml index 8c157f7a..67e98425 100644 --- a/Web/Presenters/templates/User/Groups.xml +++ b/Web/Presenters/templates/User/Groups.xml @@ -49,9 +49,9 @@
{if $clubPinned} - {_remove_from_sidebar} + {_remove_from_left_menu} {else} - {_add_to_sidebar} + {_add_to_left_menu} {/if} From 5556c88e4402b3ec93f48307d750973928022578 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko <50026114+maksalees@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:31:23 +0200 Subject: [PATCH 3/4] Improvements related to group admins (#278) 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 | 23 ++++++++-- Web/Models/Entities/Manager.php | 5 +++ Web/Presenters/GroupPresenter.php | 46 +++++++++++++++++--- Web/Presenters/templates/Group/Edit.xml | 7 +-- Web/Presenters/templates/Group/Followers.xml | 42 ++++++++++++------ Web/Presenters/templates/Group/View.xml | 12 +++-- Web/static/css/style.css | 3 +- install/sqls/00007-hidden-admins.sql | 2 + locales | 2 +- 9 files changed, 111 insertions(+), 31 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 0a4843e9..1da1850e 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 isOwnerClubPinned(): bool { @@ -274,9 +279,11 @@ 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 = $rels->where("hidden", false); foreach($rels as $rel) { $rel = (new Managers)->get($rel->id); @@ -286,13 +293,21 @@ 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()) + return null; + + return $manager; } - function getManagersCount(): int + function getManagersCount(bool $ignoreHidden = false): int { + if($ignoreHidden) + return sizeof($this->getRecord()->related("group_coadmins.club")->where("hidden", false)) + (int) !$this->isOwnerHidden(); + return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; } diff --git a/Web/Models/Entities/Manager.php b/Web/Models/Entities/Manager.php index 272e9d82..0876e01e 100644 --- a/Web/Models/Entities/Manager.php +++ b/Web/Models/Entities/Manager.php @@ -42,6 +42,11 @@ class Manager extends RowModel return is_null($this->getRecord()->comment) ? "" : $this->getRecord()->comment; } + function isHidden(): bool + { + return (bool) $this->getRecord()->hidden; + } + function isClubPinned(): bool { return (bool) $this->getRecord()->club_pinned; diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 16ac32ea..16fd6381 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -83,15 +83,30 @@ 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->paginatorConf = (object) [ "count" => $this->template->count, "page" => $this->queryParam("p") ?? 1, "amount" => NULL, "perPage" => OPENVK_DEFAULT_PER_PAGE, ]; + + $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([$this->template->club->getOwner()], iterator_to_array($this->template->managers)); + } + + $this->template->count = $this->template->club->getManagersCount(); + return; + } + + $this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1)); + $this->template->managers = null; + $this->template->count = $this->template->club->getFollowersCount(); } function renderModifyAdmin(int $id): void @@ -99,6 +114,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 = ["0" => false, "1" => true][$this->queryParam("hidden")] ?? null; //$index = $this->queryParam("index"); if(!$user) $this->badRequest(); @@ -108,10 +124,30 @@ final class GroupPresenter extends OpenVKPresenter if(!$user || !$club) $this->notFound(); - if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) + if(!$club->canBeModifiedBy($this->user->identity ?? NULL)) $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); - if($removeComment) { + if(!is_null($hidden)) { + 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..ccc98ea9 100644 --- a/Web/Presenters/templates/Group/Edit.xml +++ b/Web/Presenters/templates/Group/Edit.xml @@ -74,9 +74,10 @@ {_group_administrators_list}: - getAdministratorsListDisplay() == 0}checked{/if}/> {_group_display_only_creator}
- getAdministratorsListDisplay() == 1}checked{/if}/> {_group_display_all_administrators}
- getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}
+ {var areAllAdminsHidden = $club->getManagersCount(true) == 0} + {_group_display_only_creator}
+ {_group_display_all_administrators}
+ {_group_dont_display_administrators_list}
diff --git a/Web/Presenters/templates/Group/Followers.xml b/Web/Presenters/templates/Group/Followers.xml index 56f041ff..ead3368a 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..443fdecf 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -116,7 +116,8 @@ -
+ {* Это наверное костыль, ну да ладно *} +
{$author->getCanonicalName()}
@@ -131,10 +132,13 @@
- {tr("administrators", $club->getManagersCount() + 1)} + {tr("administrators", $club->getManagersCount(true))} +
+ {_"all_title"} +
-
+ -
+
{var user = $manager->getUser()}
diff --git a/Web/static/css/style.css b/Web/static/css/style.css index c327596b..54ce0f5e 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -1480,9 +1480,10 @@ body.scrolled .toTop:hover { .avatar-list-item .info { float: left; padding-left: 8px; + width: 134px; } -.avatar-list-item .info-without-subtitle-centered { +.avatar-list-item .info-centered { padding-top: 8px; } diff --git a/install/sqls/00007-hidden-admins.sql b/install/sqls/00007-hidden-admins.sql new file mode 100644 index 00000000..77a0db72 --- /dev/null +++ b/install/sqls/00007-hidden-admins.sql @@ -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`; diff --git a/locales b/locales index a4003623..b1c49d9b 160000 --- a/locales +++ b/locales @@ -1 +1 @@ -Subproject commit a4003623be856185679a7976423b7914455d8ab9 +Subproject commit b1c49d9b3aa7aa0a7421aa853c60af0007196f84 From e4a90ec2bfcc47a08f19b82a141d82f124ae9459 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Fri, 12 Nov 2021 16:37:09 +0200 Subject: [PATCH 4/4] Fix locales (sorry) Signed-off-by: Maxim Leshchenko --- locales | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales b/locales index b1c49d9b..0dbc2990 160000 --- a/locales +++ b/locales @@ -1 +1 @@ -Subproject commit b1c49d9b3aa7aa0a7421aa853c60af0007196f84 +Subproject commit 0dbc29908e74bcd048ebf39aaf4f11281c907a2d
{_"gender"}: {$x->isFemale() ? "женский" : "мужской"}{$user->isFemale() ? "женский" : "мужской"}
{_"registration_date"}: {$x->getRegistrationTime()}{$user->getRegistrationTime()}
{_role}: - {$club->canBeModifiedBy($x) ? tr("administrator") : tr("follower")} + {$club->getOwner()->getId() == $user->getId() ? !$club->isOwnerHidden() || $club->canBeModifiedBy($thisUser) : !is_null($manager) ? 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}