Newer
Older
<?php
namespace JsonApi\Routes\Tree;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;
class ChildrenOfTreeNode extends JsonApiController
{

Thomas Hackl
committed
protected $allowUnrecognizedParams = true;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
protected $allowedFilteringParameters = ['visible'];
protected $allowedIncludePaths = [
'children',
'courses',
'institute',
'parent',
];
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameters)
*/
public function __invoke(Request $request, Response $response, $args)
{
list($classname, $id) = explode('_', $args['id']);
$node = $classname::getNode($id);
if (!$node) {
throw new RecordNotFoundException();
}
$filters = $this->getContextFilters();
$data = $node->getChildNodes((bool) $filters['visible']);
return $this->getContentResponse($data);
}
private function getContextFilters()
{
$defaults = [
'visible' => false
];
$filtering = $this->getQueryParameters()->getFilteringParameters() ?: [];
return array_merge($defaults, $filtering);
}
}