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