48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
namespace Contabilidad\Common\Controller;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use ProVM\Common\Factory\Model as Factory;
|
|
use ProVM\Common\Define\Controller\Json;
|
|
use Contabilidad\Queue;
|
|
|
|
class Queues {
|
|
use Json;
|
|
|
|
public function __invoke(Request $request, Response $response, Factory $factory): Response {
|
|
$queues = $factory->find(Queue::class)->many();
|
|
$output = [
|
|
'queues' => array_map(function($item) {return $item->toArray();}, $queues)
|
|
];
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function pending(Request $request, Response $response, Factory $factory): Response {
|
|
$pending = $factory->find(Queue::class)->where([['processed', 0]])->many();
|
|
$output = [
|
|
'pending' => array_map(function($item) {return $item->toArray();}, $pending)
|
|
];
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function processed(Request $request, Response $response, Factory $factory): Response {
|
|
$input = json_decode($request->getBody()->getContents());
|
|
$output = [
|
|
'input' => $input,
|
|
'queues' => []
|
|
];
|
|
if (!is_array($input->processed)) {
|
|
$input->processed = [$input->processed];
|
|
}
|
|
foreach ($input->processed as $id) {
|
|
$queue = $factory->find(Queue::class)->one($id);
|
|
$queue->setProcessed(true);
|
|
$status = $queue->save();
|
|
$output['queues'] []= [
|
|
'queue' => $queue->toArray(),
|
|
'processed' => $status
|
|
];
|
|
}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
}
|