2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
namespace openvk\Web\Models\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
use openvk\Web\Models\Entities\Club;
|
|
|
|
use openvk\Web\Models\Entities\Manager;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use Nette\Database\Table\ActiveRow;
|
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
|
|
|
|
class Managers
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
use \Nette\SmartObject;
|
2020-06-07 19:04:43 +03:00
|
|
|
private $context;
|
|
|
|
private $managers;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function __construct()
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
2025-01-31 18:20:13 +03:00
|
|
|
$this->managers = $this->context->table("group_coadmins");
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
private function toManager(?ActiveRow $ar): ?Manager
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return is_null($ar) ? null : new Manager($ar);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function get(int $id): ?Manager
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->toManager($this->managers->where("id", $id)->fetch());
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getByUserAndClub(int $user, int $club): ?Manager
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->toManager($this->managers->where("user", $user)->where("club", $club)->fetch());
|
|
|
|
}
|
|
|
|
}
|