2022-11-02 13:45:49 +03:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->context = DB::i()->getContext();
|
2022-11-02 15:48:35 +03:00
|
|
|
$this->groups = $this->context->table("ChandlerGroups");
|
|
|
|
$this->members = $this->context->table("ChandlerACLRelations");
|
|
|
|
$this->perms = $this->context->table("ChandlerACLGroupsPermissions");
|
2022-11-02 13:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function get(string $UUID): ?ActiveRow
|
|
|
|
{
|
|
|
|
return $this->groups->where("id", $UUID)->fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getList(): \Traversable
|
|
|
|
{
|
|
|
|
foreach($this->groups as $group) yield $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMembersById(string $UUID): \Traversable
|
|
|
|
{
|
|
|
|
foreach($this->members->where("group", $UUID) as $member)
|
|
|
|
yield (new Users)->getByChandlerUser(
|
2022-11-02 15:48:35 +03:00
|
|
|
new ChandlerUser($this->context->table("ChandlerUsers")->where("id", $member->user)->fetch())
|
2022-11-02 13:45:49 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUsersMemberships(string $UUID): \Traversable
|
|
|
|
{
|
|
|
|
foreach($this->members->where("user", $UUID) as $member) yield $member;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPermissionsById(string $UUID): \Traversable
|
|
|
|
{
|
|
|
|
foreach($this->perms->where("group", $UUID) as $perm) yield $perm;
|
|
|
|
}
|
|
|
|
}
|