openvk/Web/Models/Repositories/Managers.php

40 lines
982 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2020-06-07 19:04:43 +03:00
namespace openvk\Web\Models\Repositories;
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
{
use \Nette\SmartObject;
2020-06-07 19:04:43 +03:00
private $context;
private $managers;
public function __construct()
2020-06-07 19:04:43 +03:00
{
$this->context = DatabaseConnection::i()->getContext();
$this->managers = $this->context->table("group_coadmins");
2020-06-07 19:04:43 +03:00
}
2020-06-07 19:04:43 +03:00
private function toManager(?ActiveRow $ar): ?Manager
{
return is_null($ar) ? null : new Manager($ar);
2020-06-07 19:04:43 +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());
}
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());
}
}