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 ChandlerUsers
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $users;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->context = DB::i()->getContext();
|
2022-11-02 15:48:35 +03:00
|
|
|
$this->users = $this->context->table("ChandlerUsers");
|
2022-11-02 13:45:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function toUser(?ActiveRow $ar): ?ChandlerUser
|
|
|
|
{
|
|
|
|
return is_null($ar) ? NULL : (new User($ar))->getChandlerUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(int $id): ?ChandlerUser
|
|
|
|
{
|
|
|
|
return (new Users)->get($id)->getChandlerUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getById(string $UUID): ?ChandlerUser
|
|
|
|
{
|
|
|
|
return new ChandlerUser($this->users->where("id", $UUID)->fetch());
|
|
|
|
}
|
|
|
|
|
|
|
|
function getList(int $page = 1): \Traversable
|
|
|
|
{
|
|
|
|
foreach($this->users as $user)
|
|
|
|
yield new ChandlerUser($user);
|
|
|
|
}
|
|
|
|
}
|