mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadido ci4/app/Models/Collection.php
This commit is contained in:
43
ci4/app/Models/Collection.php
Normal file
43
ci4/app/Models/Collection.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Collection
|
||||
{
|
||||
/**
|
||||
* Return data to colection map datatable.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $recordsTotal
|
||||
* @param int $recordsFiltered
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function datatable(array $data, int $recordsTotal, int $recordsFiltered, string $error = null)
|
||||
{
|
||||
$draw = 1;
|
||||
$req = service('request');
|
||||
if (!empty($req->getPostGet('data'))) :
|
||||
$reqData = $req->getPostGet('data');
|
||||
$draw = $reqData['draw'];
|
||||
elseif (!empty($req->getPostGet('draw'))) :
|
||||
$draw = $req->getPostGet('draw');
|
||||
endif;
|
||||
|
||||
$response = [
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $recordsTotal,
|
||||
'recordsFiltered' => $recordsFiltered,
|
||||
'data' => $data,
|
||||
'token' => csrf_hash(), // in case the CSRF token is regenerated
|
||||
];
|
||||
|
||||
if (!empty($error)) {
|
||||
$response['error'] = $error;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user