User: Added a tab in "My Groups" page for usual and managed groups

This commit is contained in:
veselcraft 2021-11-20 13:47:59 +03:00
parent 9780b5ad52
commit e5238ecc41
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
5 changed files with 32 additions and 6 deletions

View file

@ -454,23 +454,31 @@ class User extends RowModel
return sizeof(DatabaseConnection::i()->getContext()->table("messages")->where(["recipient_id" => $this->getId(), "unread" => 1]));
}
function getClubs(int $page = 1): \Traversable
function getClubs(int $page = 1, bool $admin = false): \Traversable
{
$sel = $this->getRecord()->related("subscriptions.follower")->page($page, OPENVK_DEFAULT_PER_PAGE);
foreach($sel->where("model", "openvk\\Web\\Models\\Entities\\Club") as $target) {
$target = (new Clubs)->get($target->target);
if($admin && !$target->canBeModifiedBy($this)) continue;
if(!$target) continue;
yield $target;
}
}
function getClubCount(): int
function getClubCount(bool $admin = false): int
{
$result = [];
$sel = $this->getRecord()->related("subscriptions.follower");
$sel = $sel->where("model", "openvk\\Web\\Models\\Entities\\Club");
foreach($sel->where("model", "openvk\\Web\\Models\\Entities\\Club") as $target) {
$target = (new Clubs)->get($target->target);
if($admin && !$target->canBeModifiedBy($this)) continue;
if(!$target) continue;
$result[] = $target;
}
return sizeof($sel);
return sizeof($result);
}
function getPinnedClubs(): \Traversable

View file

@ -79,6 +79,7 @@ final class UserPresenter extends OpenVKPresenter
} else {
$this->template->user = $user;
$this->template->page = $this->queryParam("p") ?? 1;
$this->template->admin = $this->queryParam("act") == "managed";
}
}

View file

@ -1,6 +1,6 @@
{extends "../@listView.xml"}
{var iterator = $user->getClubs($page)}
{var count = $user->getClubCount()}
{var iterator = $user->getClubs($page, $admin)}
{var count = $user->getClubCount($admin)}
{block title}{_"groups"}{/block}
@ -26,6 +26,21 @@
{* BEGIN ELEMENTS DESCRIPTION *}
{block tabs}
{if !is_null($thisUser) && $user->getId() === $thisUser->getId()}
<div {if !$admin}id="activetabs"{/if} class="tab">
<a {if !$admin}id="act_tab_a"{/if} href="/groups{$user->getId()}">
{_groups}
</a>
</div>
<div {if $admin}id="activetabs"{/if} class="tab">
<a {if $admin}id="act_tab_a"{/if} href="/groups{$user->getId()}?act=managed">
{_managed}
</a>
</div>
{/if}
{/block}
{block link|strip|stripHtml}
{$x->getURL()}
{/block}

View file

@ -186,6 +186,7 @@
"all_followers" = "All followers";
"only_administrators" = "Only administrators";
"website" = "Website";
"managed" = "Managed";
"administrators_one" = "$1 administrator";
"administrators_other" = "$1 administrators";

View file

@ -194,6 +194,7 @@
"all_followers" = "Все подписчики";
"only_administrators" = "Только администраторы";
"website" = "Сайт";
"managed" = "Управляемые";
"administrators_one" = "$1 администратор";
"administrators_few" = "$1 администратора";