openvk/Web/Models/Repositories/ChandlerGroups.php
Alexander Minkin def76226b7
feat(core): add phpstan for static analysis (#1223)
* feat: add phpstan for static analysis

* ci(actions): add phpstan action

* ci(actions): do analysing inside docker container

* fix(FetchToncoinTransactions): add var declaration

* fix(ServiceAPI/Wall): add var declaration

* fix(bootstrap): remove case-insensitive false vars

* fix(VKAPI/Handlers/Board): change parameters order

* fix(VKAPIRequestHandler): set fail's return type as never

* fix(VKAPI/Handlers/Groups): add array declaration

* fix(VKAPI/Handlers/Newsfeed): add return_banned declaration

* fix(VKAPI/Handlers/Notes): move $nodez declaration up

* fix(phpstan): most of the things and stupid lines of code

* fix(lint)

* fix(phpstan): less errors

* fix(lint): again. cuz i forgot about it

* fix(stan): all errors are gone now =3

---------

Co-authored-by: veselcraft <veselcraft@icloud.com>
2025-03-09 16:03:33 +03:00

66 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use Nette\Database\Table\ActiveRow;
use Chandler\Database\DatabaseConnection as DB;
use openvk\Web\Models\Entities\User;
use Chandler\Security\User as ChandlerUser;
class ChandlerGroups
{
private $context;
private $groups;
private $members;
private $perms;
public function __construct()
{
$this->context = DB::i()->getContext();
$this->groups = $this->context->table("ChandlerGroups");
$this->members = $this->context->table("ChandlerACLRelations");
$this->perms = $this->context->table("ChandlerACLGroupsPermissions");
}
public function get(string $UUID): ?ActiveRow
{
return $this->groups->where("id", $UUID)->fetch();
}
public function getList(): \Traversable
{
foreach ($this->groups as $group) {
yield $group;
}
}
public function getMembersById(string $UUID): \Traversable
{
foreach ($this->members->where("group", $UUID) as $member) {
yield (new Users())->getByChandlerUser(
new ChandlerUser($this->context->table("ChandlerUsers")->where("id", $member->user)->fetch())
);
}
}
public function getUsersMemberships(string $UUID): \Traversable
{
foreach ($this->members->where("user", $UUID) as $member) {
yield $member;
}
}
public function getPermissionsById(string $UUID): \Traversable
{
foreach ($this->perms->where("group", $UUID) as $perm) {
yield $perm;
}
}
public function isUserAMember(string $GID, string $UID): bool
{
return ($this->context->query("SELECT * FROM `ChandlerACLRelations` WHERE `group` = ? AND `user` = ?", $GID, $UID)) !== null;
}
}