1111use Models \Module ;
1212use Util \Query ;
1313
14+ use Illuminate \Http \JsonResponse ;
15+ use Illuminate \Http \Request ;
16+ use Illuminate \Routing \Controller ;
17+
18+
1419#[Post(
1520 uriTemplate: '/datatables/list/{id_module}/{id_plugin}/{id_parent} ' ,
16- processor : DataTablesController::class,
21+ controller : DataTablesController::class,
1722 input: DataTablesLoadRequest::class,
1823 output: DataTablesLoadResponse::class,
1924)]
2025class DataTablesResource
2126{
2227}
2328
24- final class DataTablesController implements ProcessorInterface
29+ final class DataTablesController extends BaseController
2530{
26- public function process ( mixed $ data , Operation $ operation , array $ uriVariables = [], array $ context = [] ): DataTablesLoadResponse
31+ public function __invoke ( Request $ request ): JsonResponse
2732 {
28- if (!$ data instanceof DataTablesLoadRequest) {
33+ $ request_body = $ this ->_cast ($ request , DataTablesLoadRequest::class);
34+
35+ $ id_module = (int ) $ request_body ->getIdModule ();
36+ $ id_plugin = (int ) $ request_body ->getIdPlugin ();
37+ $ id_parent = (int ) $ request_body ->getIdParent ();
38+
39+ $ module = \Modules::get ($ id_module );
40+ \Modules::setCurrent ($ id_module );
41+
42+ $ plugin = null ;
43+ if (!empty ($ id_plugin )) {
44+ \Plugins::setCurrent ($ id_plugin );
45+ $ plugin = \Plugins::get ($ id_plugin );
46+ }
47+
48+ $ structure = $ plugin ?? $ module ;
49+
50+ return new JsonResponse ($ this ->retrieveRecords ($ structure , $ request_body , $ id_module , $ id_plugin , $ id_parent ));
51+ }
52+
53+ /*
54+ public function process(mixed $request, Operation $operation, array $uriVariables = [], array $context = []): DataTablesLoadResponse
55+ {
56+ if (!$request instanceof DataTablesLoadRequest) {
2957 throw new \InvalidArgumentException();
3058 }
3159
@@ -44,21 +72,23 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
4472
4573 $structure = $plugin ?? $module;
4674
47- return $ this ->retrieveRecords ($ structure , $ data , $ id_module , $ id_plugin , $ id_parent );
48- }
75+ return $this->retrieveRecords($structure, $request , $id_module, $id_plugin, $id_parent);
76+ }*/
4977
50- private function retrieveRecords ($ structure , DataTablesLoadRequest $ data , $ id_module , $ id_plugin , $ id_parent ): DataTablesLoadResponse
78+ private function retrieveRecords ($ structure , DataTablesLoadRequest $ request , $ id_module , $ id_plugin , $ id_parent ): DataTablesLoadResponse
5179 {
5280 // Informazioni fondamentali
53- $ order = $ data ->order ? $ data ->order [0 ] : [];
81+ $ order = $ request ->order ? $ request ->order [0 ] : [];
5482
5583 if (!empty ($ order )) {
56- $ order[ ' column ' ] = $ order[ ' column ' ] - 1 ;
84+ $ order-> column = $ order-> column - 1 ;
5785 }
5886
87+ $ order_array = $ order ->toArray ();
88+
5989 $ query_structure = Query::readQuery ($ structure );
6090
61- $ response = new DataTablesLoadResponse ($ data ->draw );
91+ $ response = new DataTablesLoadResponse ($ request ->draw );
6292
6393 $ query = Query::getQuery ($ structure , [], [], [], $ query_structure );
6494 if (empty ($ query )) {
@@ -67,7 +97,7 @@ private function retrieveRecords($structure, DataTablesLoadRequest $data, $id_mo
6797
6898 // Ricerca
6999 $ search = [];
70- $ columns = $ data ->columns ;
100+ $ columns = $ request ->columns ;
71101 array_shift ($ columns );
72102 for ($ i = 0 ; $ i < count ($ columns ); ++$ i ) {
73103 $ col = Column::fromArray ($ columns [$ i ]);
@@ -80,7 +110,7 @@ private function retrieveRecords($structure, DataTablesLoadRequest $data, $id_mo
80110 $ response ->recordsTotal = database ()->fetchNum ($ query );
81111
82112 // CONTEGGIO RECORD FILTRATI (senza LIMIT)
83- $ query_filtered = Query::getQuery ($ structure , $ search , $ order , [], $ query_structure );
113+ $ query_filtered = Query::getQuery ($ structure , $ search , $ order_array , [], $ query_structure );
84114 if (empty ($ id_plugin )) {
85115 $ query_filtered = \Modules::replaceAdditionals ($ id_module , $ query_filtered );
86116 }
@@ -93,11 +123,11 @@ private function retrieveRecords($structure, DataTablesLoadRequest $data, $id_mo
93123 $ response ->avg = Query::getAverages ($ structure , $ search );
94124
95125 $ limit = [
96- 'start ' => $ data ->start ,
97- 'length ' => $ data ->length ,
126+ 'start ' => $ request ->start ,
127+ 'length ' => $ request ->length ,
98128 ];
99129 // RISULTATI VISIBILI (con LIMIT)
100- $ query = Query::getQuery ($ structure , $ search , $ order , $ limit , $ query_structure );
130+ $ query = Query::getQuery ($ structure , $ search , $ order_array , $ limit , $ query_structure );
101131
102132 // Filtri derivanti dai permessi (eventuali)
103133 if (empty ($ id_plugin )) {
@@ -154,17 +184,17 @@ private function getSingleRow($r, $query_structure, $align, $id_module, $id_plug
154184
155185 $ result = [
156186 'id ' => $ r ['id ' ],
157- '<span class="hide" data -id=" ' .$ r ['id ' ].'"></span> ' , // Colonna ID
187+ '<span class="hide" request -id=" ' .$ r ['id ' ].'"></span> ' , // Colonna ID
158188 ];
159189
160190 foreach ($ query_structure ['fields ' ] as $ pos => $ field ) {
161191 $ column = [];
162192
163193 if (!empty ($ r ['_bg_ ' ])) {
164194 if (preg_match ('/-light$/ ' , (string ) $ r ['_bg_ ' ])) {
165- $ column ['data -background ' ] = substr ((string ) $ r ['_bg_ ' ], 0 , -6 ); // Remove the "-light" suffix from the word
195+ $ column ['request -background ' ] = substr ((string ) $ r ['_bg_ ' ], 0 , -6 ); // Remove the "-light" suffix from the word
166196 } else {
167- $ column ['data -background ' ] = $ r ['_bg_ ' ];
197+ $ column ['request -background ' ] = $ r ['_bg_ ' ];
168198 }
169199 }
170200
@@ -211,7 +241,7 @@ private function getSingleRow($r, $query_structure, $align, $id_module, $id_plug
211241 }
212242
213243 $ column ['class ' ] = 'text-center small ' ;
214- $ column ['data -background ' ] = $ r [$ field ];
244+ $ column ['request -background ' ] = $ r [$ field ];
215245 }
216246
217247 // Icona di stampa
@@ -245,8 +275,8 @@ private function getSingleRow($r, $query_structure, $align, $id_module, $id_plug
245275 }
246276
247277 // Colore del testo
248- if (!empty ($ column ['data -background ' ])) {
249- $ column ['data -color ' ] ??= color_inverse (trim ((string ) $ column ['data -background ' ]));
278+ if (!empty ($ column ['request -background ' ])) {
279+ $ column ['request -color ' ] ??= color_inverse (trim ((string ) $ column ['request -background ' ]));
250280 } elseif (preg_match ('/^mailto_(.+?)$/ ' , trim ((string ) $ field ), $ m )) {
251281 $ column ['class ' ] = '' ;
252282 $ value = ($ r [$ field ] ? '<a class="btn btn-default btn-sm btn-block" style="font-weight:normal;" href="mailto: ' .$ r [$ field ].'" target="_blank"><i class="fa fa-envelope text-primary"></i> ' .$ r [$ field ].'</a> ' : '' );
@@ -269,13 +299,13 @@ private function getSingleRow($r, $query_structure, $align, $id_module, $id_plug
269299
270300 // Link per i moduli
271301 if (empty ($ id_plugin )) {
272- $ column ['data -link ' ] = base_path_osm ().'/editor.php?id_module= ' .$ id_module .'&id_record= ' .$ id_record .$ hash ;
302+ $ column ['request -link ' ] = base_path_osm ().'/editor.php?id_module= ' .$ id_module .'&id_record= ' .$ id_record .$ hash ;
273303 }
274304 // Link per i plugin
275305 else {
276- $ column ['data -link ' ] = base_path_osm ().'/add.php?id_module= ' .$ id_module .'&id_record= ' .$ id_record .'&id_plugin= ' .$ id_plugin .'&id_parent= ' .$ id_parent .'&edit=1 ' .$ hash ;
306+ $ column ['request -link ' ] = base_path_osm ().'/add.php?id_module= ' .$ id_module .'&id_record= ' .$ id_record .'&id_plugin= ' .$ id_plugin .'&id_parent= ' .$ id_parent .'&edit=1 ' .$ hash ;
277307
278- $ column ['data -type ' ] = 'dialog ' ;
308+ $ column ['request -type ' ] = 'dialog ' ;
279309 }
280310 }
281311
0 commit comments