mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
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
This commit is contained in:
parent
610b2bda6d
commit
e3358fcfa5
9 changed files with 105 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -42,5 +42,10 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -81,6 +82,38 @@ final class UserPresenter extends OpenVKPresenter
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
|
|
@ -169,6 +169,12 @@
|
|||
href="{$menuItem['url']}"
|
||||
target="_blank"
|
||||
class="link">{$menuItem["name"]}</a>
|
||||
<div n:if="$thisUser->getPinnedClubCount() > 0" style="height: 1px;background: #CCC;margin: 4px 0 2px;"></div>
|
||||
<a
|
||||
n:foreach="$thisUser->getPinnedClubs() as $club"
|
||||
href="{$club->getURL()}"
|
||||
style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
|
||||
class="link">{$club->getName()}</a>
|
||||
|
||||
<a
|
||||
n:if="OPENVK_ROOT_CONF['openvk']['preferences']['adPoster']['enable']"
|
||||
|
|
|
@ -40,4 +40,23 @@
|
|||
|
||||
{block description}
|
||||
{$x->getDescription()}
|
||||
{if $x->canBeModifiedBy($thisUser ?? NULL)}
|
||||
{var clubPinned = $thisUser->isClubPinned($x)}
|
||||
<table n:if="$clubPinned || $thisUser->getPinnedClubCount() <= 10">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="120" valign="top"><span class="nobold">{_actions}: </span></td>
|
||||
<td>
|
||||
<a href="/groups_pin?club={$x->getId()}&hash={rawurlencode($csrfToken)}">
|
||||
{if $clubPinned}
|
||||
{_remove_from_sidebar}
|
||||
{else}
|
||||
{_add_to_sidebar}
|
||||
{/if}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{/if}
|
||||
{/block}
|
||||
|
|
|
@ -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}"
|
||||
|
|
2
install/sqls/00009-pinned-clubs.sql
Normal file
2
install/sqls/00009-pinned-clubs.sql
Normal file
|
@ -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;
|
2
locales
2
locales
|
@ -1 +1 @@
|
|||
Subproject commit ce4ede6f8c6cb42f2421969fab23da933c81b52b
|
||||
Subproject commit a4003623be856185679a7976423b7914455d8ab9
|
Loading…
Reference in a new issue