1
|
|
|
<?php |
2
|
|
|
namespace keeko\core\domain\base; |
3
|
|
|
|
4
|
|
|
use keeko\core\model\RegionArea; |
5
|
|
|
use keeko\core\model\RegionAreaQuery; |
6
|
|
|
use keeko\framework\service\ServiceContainer; |
7
|
|
|
use keeko\framework\domain\payload\Found; |
8
|
|
|
use keeko\framework\domain\payload\NotFound; |
9
|
|
|
use Tobscure\JsonApi\Parameters; |
10
|
|
|
use keeko\framework\utils\NameUtils; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
*/ |
14
|
|
|
trait RegionAreaDomainTrait { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param Parameters $params |
18
|
|
|
*/ |
19
|
|
|
public function paginate(Parameters $params) { |
20
|
|
|
$sysPrefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences(); |
21
|
|
|
$defaultSize = $sysPrefs->getPaginationSize(); |
22
|
|
|
$page = $params->getPage('number'); |
|
|
|
|
23
|
|
|
$size = $params->getPage('size', $defaultSize); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$query = RegionAreaQuery::create(); |
26
|
|
|
|
27
|
|
|
// sorting |
28
|
|
|
$sort = $params->getSort(RegionArea::getSerializer()->getSortFields()); |
29
|
|
|
foreach ($sort as $field => $order) { |
30
|
|
|
$method = 'orderBy' . NameUtils::toStudlyCase($field); |
31
|
|
|
$query->$method($order); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
// filtering |
35
|
|
|
$filter = $params->getFilter(); |
36
|
|
|
if (!empty($filter)) { |
37
|
|
|
$this->applyFilter($query, $filter); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// paginate |
41
|
|
|
$regionArea = $query->paginate($page, $size); |
42
|
|
|
|
43
|
|
|
// run response |
44
|
|
|
return new Found(['model' => $regionArea]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param mixed $id |
49
|
|
|
*/ |
50
|
|
|
public function read($id) { |
51
|
|
|
// read |
52
|
|
|
$regionArea = RegionAreaQuery::create()->findOneById($id); |
53
|
|
|
|
54
|
|
|
// check existence |
55
|
|
|
if ($regionArea === null) { |
56
|
|
|
$payload = new NotFound(['message' => 'RegionArea not found.']); |
57
|
|
|
} else { |
58
|
|
|
$payload = new Found(['model' => $regionArea]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// run response |
62
|
|
|
return $payload; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Implement this functionality at keeko\core\domain\RegionAreaDomain |
67
|
|
|
* |
68
|
|
|
* @param RegionAreaQuery $query |
69
|
|
|
*/ |
70
|
|
|
abstract protected function applyFilter(RegionAreaQuery $query); |
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the service container |
74
|
|
|
* |
75
|
|
|
* @return ServiceContainer |
76
|
|
|
*/ |
77
|
|
|
abstract protected function getServiceContainer(); |
78
|
|
|
} |
79
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.