openvk/Web/Models/Repositories/Reports.php

51 lines
1.3 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use openvk\Web\Models\Entities\Report;
use Nette\Database\Table\ActiveRow;
use Chandler\Database\DatabaseConnection;
class Reports
{
private $context;
private $reports;
function __construct()
{
$this->context = DatabaseConnection::i()->getContext();
$this->reports = $this->context->table("reports");
}
private function toReport(?ActiveRow $ar): ?Report
{
return is_null($ar) ? NULL : new Report($ar);
}
function getReports(int $state = 0, int $page = 1): \Traversable
{
foreach($this->reports->where(["deleted" => 0])->page($page, 15) as $t)
2021-09-25 16:59:18 +03:00
yield new Report($t);
}
function getReportsCount(int $state = 0): int
{
2021-09-25 16:59:18 +03:00
return sizeof($this->reports->where(["deleted" => 0, "type" => $state]));
}
2021-09-25 16:59:18 +03:00
function get(int $id): ?Report
{
2021-09-25 16:59:18 +03:00
return $this->toReport($this->reports->get($id));
}
2021-09-21 01:02:53 +03:00
2021-09-25 16:59:18 +03:00
function getByContentId(int $id): ?Report
2021-09-21 01:02:53 +03:00
{
$post = $this->reports->where(["deleted" => 0, "content_id" => $id])->fetch();
if($post)
return new Report($post);
else
return null;
}
use \Nette\SmartObject;
}