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}:
{_"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} |