Users: Show all groups in the list of managed groups

This commit is contained in:
Maxim Leshchenko 2021-12-03 20:08:50 +02:00
parent f69610c758
commit 24624bb147
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE

View file

@ -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