This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Controllers/HistoryController.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2014-09-26 20:41:28 +02:00
<?php
namespace Szurubooru\Controllers;
final class HistoryController extends AbstractController
{
private $historyService;
private $privilegeService;
private $snapshotSearchParser;
private $inputReader;
private $snapshotViewProxy;
public function __construct(
\Szurubooru\Services\HistoryService $historyService,
\Szurubooru\Services\PrivilegeService $privilegeService,
\Szurubooru\SearchServices\Parsers\SnapshotSearchParser $snapshotSearchParser,
\Szurubooru\Helpers\InputReader $inputReader,
\Szurubooru\Controllers\ViewProxies\SnapshotViewProxy $snapshotViewProxy)
{
$this->historyService = $historyService;
$this->privilegeService = $privilegeService;
$this->snapshotSearchParser = $snapshotSearchParser;
$this->inputReader = $inputReader;
$this->snapshotViewProxy = $snapshotViewProxy;
}
public function registerRoutes(\Szurubooru\Router $router)
{
$router->get('/api/history', [$this, 'getFiltered']);
}
public function getFiltered()
{
$this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY);
$filter = $this->snapshotSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize(50);
$result = $this->historyService->getFiltered($filter);
$entities = $this->snapshotViewProxy->fromArray($result->getEntities());
return [
'data' => $entities,
'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()];
}
}