1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenSkill\Datatable\Versions; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use OpenSkill\Datatable\Columns\ColumnConfiguration; |
7
|
|
|
use OpenSkill\Datatable\Data\ResponseData; |
8
|
|
|
use OpenSkill\Datatable\Queries\Parser\Datatable19QueryParser; |
9
|
|
|
use OpenSkill\Datatable\Queries\QueryConfiguration; |
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
11
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Datatable19Version |
15
|
|
|
* @package OpenSkill\Datatable\Versions |
16
|
|
|
* |
17
|
|
|
* Version that supports the 1.9 version of datatables |
18
|
|
|
* http://legacy.datatables.net/index |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
class Datatable19Version extends Version |
22
|
|
|
{ |
23
|
|
|
/** @var Datatable19QueryParser */ |
24
|
|
|
private $queryParser; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Datatable19Version constructor. |
28
|
|
|
* |
29
|
|
|
* @param RequestStack $requestStack The current request |
30
|
|
|
*/ |
31
|
|
|
public function __construct(RequestStack $requestStack) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($requestStack); |
34
|
|
|
$this->queryParser = new Datatable19QueryParser(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Method to determine if this parser can handle the query parameters. If so then the parser should return true |
39
|
|
|
* and be able to return a DTQueryConfiguration |
40
|
|
|
* |
41
|
|
|
* @return bool true if the parser is able to parse the query parameters and to return a DTQueryConfiguration |
42
|
|
|
*/ |
43
|
|
|
public function canParseRequest() |
44
|
|
|
{ |
45
|
|
|
return $this->queryParser->canParse($this->requestStack->getCurrentRequest()); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Method that should parse the request and return a DTQueryConfiguration |
50
|
|
|
* |
51
|
|
|
* @param ColumnConfiguration[] $columnConfiguration The configuration of the columns |
52
|
|
|
* |
53
|
|
|
* @return QueryConfiguration the configuration the provider can use to prepare the data |
54
|
|
|
*/ |
55
|
|
|
public function parseRequest(array $columnConfiguration) |
56
|
|
|
{ |
57
|
|
|
return $this->queryParser->parse($this->requestStack->getCurrentRequest(), $columnConfiguration); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Is responsible to take the generated data and prepare a response for it. |
62
|
|
|
* @param ResponseData $data The processed data. |
63
|
|
|
* @param QueryConfiguration $queryConfiguration the query configuration for the current request. |
64
|
|
|
* @param ColumnConfiguration[] $columnConfigurations the column configurations for the current data table. |
65
|
|
|
* @return JsonResponse the response that should be returned to the client. |
66
|
|
|
*/ |
67
|
|
|
public function createResponse(ResponseData $data, QueryConfiguration $queryConfiguration, array $columnConfigurations) |
68
|
|
|
{ |
69
|
|
|
$responseData = [ |
70
|
|
|
'sEcho' => $queryConfiguration->drawCall(), |
71
|
|
|
'iTotalRecords' => $data->totalDataCount(), |
72
|
|
|
'iTotalDisplayRecords' => $data->data()->count(), |
73
|
|
|
'aaData' => $data->data()->toArray() |
74
|
|
|
]; |
75
|
|
|
return new JsonResponse($responseData); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string The name of the view that this version should use fot the table. |
80
|
|
|
*/ |
81
|
|
|
public function getTableView() |
82
|
|
|
{ |
83
|
|
|
return "viewTableStuff"; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string The name of the view that this version should use for the script. |
88
|
|
|
*/ |
89
|
|
|
public function getScriptView() |
90
|
|
|
{ |
91
|
|
|
return "scriptViewStuff"; |
92
|
|
|
} |
93
|
|
|
} |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: