mirror of
https://github.com/openvk/openvk
synced 2025-01-09 01:09:46 +03:00
Users: Show all groups in the list of managed groups
This commit is contained in:
parent
f69610c758
commit
24624bb147
1 changed files with 29 additions and 16 deletions
|
@ -471,29 +471,42 @@ class User extends RowModel
|
||||||
|
|
||||||
function getClubs(int $page = 1, bool $admin = false): \Traversable
|
function getClubs(int $page = 1, bool $admin = false): \Traversable
|
||||||
{
|
{
|
||||||
$sel = $this->getRecord()->related("subscriptions.follower")->page($page, OPENVK_DEFAULT_PER_PAGE);
|
if($admin) {
|
||||||
foreach($sel->where("model", "openvk\\Web\\Models\\Entities\\Club") as $target) {
|
$id = $this->getId();
|
||||||
$target = (new Clubs)->get($target->target);
|
$query = "SELECT `id` FROM `groups` WHERE `owner` = ? UNION SELECT `club` as `id` FROM `group_coadmins` WHERE `user` = ?";
|
||||||
if($admin && !$target->canBeModifiedBy($this)) continue;
|
$query .= " LIMIT " . OPENVK_DEFAULT_PER_PAGE . " OFFSET " . ($page - 1) * OPENVK_DEFAULT_PER_PAGE;
|
||||||
if(!$target) continue;
|
|
||||||
|
$sel = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
|
||||||
yield $target;
|
foreach($sel as $target) {
|
||||||
|
$target = (new Clubs)->get($target->id);
|
||||||
|
if(!$target) continue;
|
||||||
|
|
||||||
|
yield $target;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$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(!$target) continue;
|
||||||
|
|
||||||
|
yield $target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClubCount(bool $admin = false): int
|
function getClubCount(bool $admin = false): int
|
||||||
{
|
{
|
||||||
$result = [];
|
if($admin) {
|
||||||
$sel = $this->getRecord()->related("subscriptions.follower");
|
$id = $this->getId();
|
||||||
foreach($sel->where("model", "openvk\\Web\\Models\\Entities\\Club") as $target) {
|
$query = "SELECT COUNT(*) AS `cnt` FROM (SELECT `id` FROM `groups` WHERE `owner` = ? UNION SELECT `club` as `id` FROM `group_coadmins` WHERE `user` = ?) u0;";
|
||||||
$target = (new Clubs)->get($target->target);
|
|
||||||
if(!$target) continue;
|
|
||||||
if($admin && !$target->canBeModifiedBy($this)) continue;
|
|
||||||
|
|
||||||
$result[] = $target;
|
return (int) DatabaseConnection::i()->getConnection()->query($query, $id, $id)->fetch()->cnt;
|
||||||
|
} else {
|
||||||
|
$sel = $this->getRecord()->related("subscriptions.follower");
|
||||||
|
$sel = $sel->where("model", "openvk\\Web\\Models\\Entities\\Club");
|
||||||
|
|
||||||
|
return sizeof($sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sizeof($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPinnedClubs(): \Traversable
|
function getPinnedClubs(): \Traversable
|
||||||
|
|
Loading…
Reference in a new issue