1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Related list view action file. |
4
|
|
|
* |
5
|
|
|
* @package Action |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o. |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace YF\Modules\Base\Action; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Related list view action class. |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
class RelatedListView extends \App\Controller\Action |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** {@inheritdoc} */ |
20
|
|
|
public function process(): void |
21
|
|
|
{ |
22
|
|
|
$relatedListModel = \YF\Modules\Base\Model\RelatedList::getInstance($this->moduleName, 'RelatedList'); |
23
|
|
|
$relatedListModel->setRequest($this->request); |
24
|
|
|
$rows = $columns = $fields = []; |
25
|
|
|
foreach ($this->request->getArray('columns') as $key => $value) { |
26
|
|
|
$columns[$key] = $value['name']; |
27
|
|
|
if ($value['name']) { |
28
|
|
|
$fields[] = $value['name']; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
$order = current($this->request->getArray('order', \App\Purifier::ALNUM)); |
32
|
|
|
if ($order && isset($columns[$order['column']], $columns[$order['column']])) { |
33
|
|
|
$relatedListModel->setOrder($columns[$order['column']], strtoupper($order['dir'])); |
34
|
|
|
} |
35
|
|
|
if ($this->request->has('filters') && !$this->request->isEmpty('filters')) { |
36
|
|
|
$conditions = []; |
37
|
|
|
foreach ($this->request->getArray('filters') as $fieldName => $value) { |
38
|
|
|
if ('' !== $value) { |
39
|
|
|
$conditions[] = [ |
40
|
|
|
'fieldName' => $fieldName, |
41
|
|
|
'value' => $value, |
42
|
|
|
'operator' => 'a', |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
$relatedListModel->setConditions($conditions); |
47
|
|
|
} |
48
|
|
|
$relatedListModel->setFields($fields); |
49
|
|
|
$relatedListModel->setLimit($this->request->getInteger('length')); |
50
|
|
|
$relatedListModel->setOffset($this->request->getInteger('start')); |
51
|
|
|
$relatedListModel->loadRecordsList(); |
52
|
|
|
foreach ($relatedListModel->getRecordsListModel() as $id => $recordModel) { |
53
|
|
|
$row = []; |
54
|
|
|
foreach ($columns as $column) { |
55
|
|
|
if ($column) { |
56
|
|
|
$value = $recordModel->getListDisplayValue($column); |
57
|
|
|
} else { |
58
|
|
|
$value = $recordModel->getRelatedListActions(); |
59
|
|
|
} |
60
|
|
|
$row[] = $value; |
61
|
|
|
} |
62
|
|
|
$rows[] = $row; |
63
|
|
|
} |
64
|
|
|
$response = [ |
65
|
|
|
'draw' => $this->request->getInteger('draw'), |
66
|
|
|
'iTotalDisplayRecords' => \count($rows), |
67
|
|
|
'iTotalRecords' => $relatedListModel->getCount(), |
68
|
|
|
'aaData' => $rows, |
69
|
|
|
]; |
70
|
|
|
header('content-type: text/json; charset=UTF-8'); |
71
|
|
|
echo \App\Json::encode($response); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.