From df3d2fca0cb8ba917440dc18b94abc6b770a55a4 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Mon, 8 Nov 2021 13:38:49 +0200 Subject: [PATCH] Code improvements --- Web/Models/Entities/Club.php | 7 +++---- Web/Presenters/GroupPresenter.php | 27 +++++++++++++------------ Web/Presenters/templates/Group/Edit.xml | 8 ++++---- Web/Presenters/templates/Group/View.xml | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index e8c84fb4..8442967d 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -303,11 +303,10 @@ class Club extends RowModel function getManagersCount(bool $ignoreHidden = false): int { - if ($ignoreHidden) { + 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 diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 4b862a7b..dfddf4ec 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -83,6 +83,13 @@ final class GroupPresenter extends OpenVKPresenter { $this->assertUserLoggedIn(); + $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) { @@ -90,22 +97,16 @@ final class GroupPresenter extends OpenVKPresenter $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->managers = array_merge([$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(); + return; } - $this->template->paginatorConf = (object) [ - "count" => $this->template->count, - "page" => $this->queryParam("p") ?? 1, - "amount" => NULL, - "perPage" => OPENVK_DEFAULT_PER_PAGE, - ]; + $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 @@ -113,7 +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 = $this->queryParam("hidden") === "1" ? true : ($this->queryParam("hidden") === "0" ? false : null); + $hidden = ["0" => false, "1" => true][$this->queryParam("hidden")] ?? null; //$index = $this->queryParam("index"); if(!$user) $this->badRequest(); @@ -126,7 +127,7 @@ final class GroupPresenter extends OpenVKPresenter if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); - if($hidden !== null) { + if(!is_null($hidden)) { if($club->getOwner()->getId() == $user->getId()) { $club->setOwner_Hidden($hidden); $club->save(); diff --git a/Web/Presenters/templates/Group/Edit.xml b/Web/Presenters/templates/Group/Edit.xml index 23778181..ccc98ea9 100644 --- a/Web/Presenters/templates/Group/Edit.xml +++ b/Web/Presenters/templates/Group/Edit.xml @@ -74,10 +74,10 @@ {_group_administrators_list}: - {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}
+ {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/View.xml b/Web/Presenters/templates/Group/View.xml index 07816e79..443fdecf 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -117,7 +117,7 @@ {* Это наверное костыль, ну да ладно *} -
+
{$author->getCanonicalName()}
@@ -133,7 +133,7 @@
{tr("administrators", $club->getManagersCount(true))} -