1 | <?php |
||
20 | class DataController extends AbstractActionController |
||
21 | { |
||
22 | /** |
||
23 | * Возвращает данные для таблиц |
||
24 | * @return ViewModel |
||
25 | * @throws Exception\InvalidConditionNameException |
||
26 | * @throws Exception\InvalidConditionValueException |
||
27 | * @throws Exception\InvalidGridNameException |
||
28 | */ |
||
29 | public function getAction() |
||
30 | { |
||
31 | /** @var \ZF\ContentNegotiation\Request $request */ |
||
32 | $request = $this->getRequest(); |
||
|
|||
33 | $gridName = $request->getQuery('grid'); |
||
34 | $limit = (int)$request->getQuery('limit', 25); |
||
35 | $offset = (int)$request->getQuery('offset', 0); |
||
36 | $orderField = $request->getQuery('sidx', null); |
||
37 | $orderType = $request->getQuery('sorder', null); |
||
38 | $collapsedRows = is_array($request->getPost('collapsedRows')) ? $request->getPost('collapsedRows') : []; |
||
39 | /** |
||
40 | * $conditions => [ |
||
41 | * [ |
||
42 | * 'key' => $name, |
||
43 | * 'value' => $value |
||
44 | * ] |
||
45 | * ]; |
||
46 | */ |
||
47 | $conditions = $request->getQuery('conditions', []); |
||
48 | if (!$gridName) { |
||
49 | throw new Exception\InvalidGridNameException('Не задано имя таблицы для получения данных'); |
||
50 | } |
||
51 | /** @var GridInterface $grid */ |
||
52 | $grid = $this->getServiceLocator()->get('GridManager')->get('grids.' . $gridName); |
||
53 | |||
54 | $adapter = $grid->getAdapter(); |
||
55 | if ($adapter instanceof DoctrineDBAL) { |
||
56 | $adapter->setLimit($limit); |
||
57 | $adapter->setOffset($offset); |
||
58 | if ($orderField && $orderType) { |
||
59 | $adapter->setOrder([ |
||
60 | [ |
||
61 | 'field' => $orderField, |
||
62 | 'order' => $orderType |
||
63 | ] |
||
64 | ]); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $conditionsObj = new Conditions(); |
||
69 | foreach ($conditions as $cond) { |
||
70 | if (is_array($cond)) { |
||
71 | $condition = $this->getCondition($cond); |
||
72 | $conditionsObj[] = $condition; |
||
73 | } |
||
74 | } |
||
75 | $grid->setConditions($conditionsObj); |
||
76 | $result = new ViewModel(['grid' => $grid, 'collapsedRows' => $collapsedRows]); |
||
77 | $result->setTerminal(true); |
||
78 | return $result; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param array $conditionData |
||
83 | * @return SimpleCondition |
||
84 | * @throws Exception\InvalidConditionNameException |
||
85 | * @throws Exception\InvalidConditionValueException |
||
86 | */ |
||
87 | protected function getCondition(array $conditionData) |
||
100 | } |
||
101 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.