2022-08-20 20:30:04 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Repositories;
|
|
|
|
use openvk\Web\Models\Entities\{BugtrackerProduct};
|
|
|
|
use Nette\Database\Table\ActiveRow;
|
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
|
|
|
|
class BugtrackerProducts
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $products;
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
|
|
$this->products = $this->context->table("bt_products");
|
|
|
|
}
|
|
|
|
|
|
|
|
private function toProduct(?ActiveRow $ar)
|
|
|
|
{
|
|
|
|
return is_null($ar) ? NULL : new BugtrackerProduct($ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(int $id): ?BugtrackerProduct
|
|
|
|
{
|
|
|
|
return $this->toProduct($this->products->get($id));
|
|
|
|
}
|
|
|
|
|
2022-08-22 02:11:48 +03:00
|
|
|
function getAll(int $page = 1): \Traversable
|
2022-08-20 20:30:04 +03:00
|
|
|
{
|
2022-08-22 02:11:48 +03:00
|
|
|
foreach($this->products->order("id ASC")->page($page, 5) as $product)
|
2022-08-20 20:30:04 +03:00
|
|
|
yield new BugtrackerProduct($product);
|
|
|
|
}
|
|
|
|
|
2022-08-22 02:11:48 +03:00
|
|
|
function getOpen(int $page = 1): \Traversable
|
2022-08-20 20:30:04 +03:00
|
|
|
{
|
2022-08-22 02:11:48 +03:00
|
|
|
foreach($this->products->where(["closed" => 0])->order("id ASC")->page($page, 5) as $product)
|
2022-08-20 20:30:04 +03:00
|
|
|
yield new BugtrackerProduct($product);
|
|
|
|
}
|
2022-08-22 02:11:48 +03:00
|
|
|
|
|
|
|
function getCount(): ?int
|
|
|
|
{
|
|
|
|
return sizeof($this->products->where(["closed" => 0]));
|
|
|
|
}
|
2022-08-20 20:30:04 +03:00
|
|
|
}
|