2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-08-11 16:50:19 +03:00
|
|
|
namespace openvk\Web\Models\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2023-08-11 16:50:19 +03:00
|
|
|
use Chandler\Database\DatabaseConnection as DB;
|
|
|
|
use Nette\Database\Table\{ActiveRow, Selection};
|
|
|
|
use openvk\Web\Models\Entities\Ban;
|
|
|
|
|
|
|
|
class Bans
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $bans;
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function __construct()
|
2023-08-11 16:50:19 +03:00
|
|
|
{
|
|
|
|
$this->context = DB::i()->getContext();
|
|
|
|
$this->bans = $this->context->table("bans");
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function toBan(?ActiveRow $ar): ?Ban
|
2023-08-11 16:50:19 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return is_null($ar) ? null : new Ban($ar);
|
2023-08-11 16:50:19 +03:00
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function get(int $id): ?Ban
|
2023-08-11 16:50:19 +03:00
|
|
|
{
|
|
|
|
return $this->toBan($this->bans->get($id));
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getByUser(int $user_id): \Traversable
|
2023-08-11 16:50:19 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
foreach ($this->bans->where("user", $user_id) as $ban) {
|
2023-08-11 16:50:19 +03:00
|
|
|
yield new Ban($ban);
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2023-08-11 16:50:19 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|