diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 65353fc7..1da1850e 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -94,7 +94,17 @@ 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 + { + return (bool) $this->getRecord()->owner_club_pinned; + } + function getDescription(): ?string { return $this->getRecord()->about; @@ -269,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); @@ -281,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 e58eef6e..0876e01e 100644 --- a/Web/Models/Entities/Manager.php +++ b/Web/Models/Entities/Manager.php @@ -41,6 +41,16 @@ 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; + } 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/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 56c9aa5a..23b10fc4 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/UserPresenter.php b/Web/Presenters/UserPresenter.php index 937a04d4..12abe32c 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()} {_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 9972776e..02a2e153 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -124,7 +124,8 @@ -
+ {* Это наверное костыль, ну да ладно *} +
{$author->getCanonicalName()}
@@ -139,10 +140,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")} + {$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}
+ + + + + + +
{_actions}: + + {if $clubPinned} + {_remove_from_left_menu} + {else} + {_add_to_left_menu} + {/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/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/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;