mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +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
|
||||
{
|
||||
if($admin) {
|
||||
$id = $this->getId();
|
||||
$query = "SELECT `id` FROM `groups` WHERE `owner` = ? UNION SELECT `club` as `id` FROM `group_coadmins` WHERE `user` = ?";
|
||||
$query .= " LIMIT " . OPENVK_DEFAULT_PER_PAGE . " OFFSET " . ($page - 1) * OPENVK_DEFAULT_PER_PAGE;
|
||||
|
||||
$sel = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
|
||||
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($admin && !$target->canBeModifiedBy($this)) continue;
|
||||
if(!$target) continue;
|
||||
|
||||
yield $target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getClubCount(bool $admin = false): int
|
||||
{
|
||||
$result = [];
|
||||
if($admin) {
|
||||
$id = $this->getId();
|
||||
$query = "SELECT COUNT(*) AS `cnt` FROM (SELECT `id` FROM `groups` WHERE `owner` = ? UNION SELECT `club` as `id` FROM `group_coadmins` WHERE `user` = ?) u0;";
|
||||
|
||||
return (int) DatabaseConnection::i()->getConnection()->query($query, $id, $id)->fetch()->cnt;
|
||||
} else {
|
||||
$sel = $this->getRecord()->related("subscriptions.follower");
|
||||
foreach($sel->where("model", "openvk\\Web\\Models\\Entities\\Club") as $target) {
|
||||
$target = (new Clubs)->get($target->target);
|
||||
if(!$target) continue;
|
||||
if($admin && !$target->canBeModifiedBy($this)) continue;
|
||||
$sel = $sel->where("model", "openvk\\Web\\Models\\Entities\\Club");
|
||||
|
||||
$result[] = $target;
|
||||
return sizeof($sel);
|
||||
}
|
||||
|
||||
return sizeof($result);
|
||||
}
|
||||
|
||||
function getPinnedClubs(): \Traversable
|
||||
|
|
Loading…
Reference in a new issue