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\Parser\QueryParser; |
10
|
|
|
use OpenSkill\Datatable\Queries\QueryConfiguration; |
11
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
12
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Datatable19Version |
16
|
|
|
* @package OpenSkill\Datatable\Versions |
17
|
|
|
* |
18
|
|
|
* Version that supports the 1.9 version of datatables |
19
|
|
|
* http://legacy.datatables.net/index |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class Datatable19Version extends DatatableVersion |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Datatable19Version constructor. |
26
|
|
|
* |
27
|
|
|
* @param RequestStack $requestStack The current request |
28
|
|
|
*/ |
29
|
|
|
public function __construct(RequestStack $requestStack) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($requestStack, new Datatable19QueryParser()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Is responsible to take the generated data and prepare a response for it. |
36
|
|
|
* @param ResponseData $data The processed data. |
37
|
|
|
* @param QueryConfiguration $queryConfiguration the query configuration for the current request. |
38
|
|
|
* @param ColumnConfiguration[] $columnConfigurations the column configurations for the current data table. |
39
|
|
|
* @return JsonResponse the response that should be returned to the client. |
40
|
|
|
*/ |
41
|
|
|
public function createResponse( |
42
|
|
|
ResponseData $data, |
43
|
|
|
QueryConfiguration $queryConfiguration, |
44
|
|
|
array $columnConfigurations |
45
|
|
|
) { |
46
|
|
|
$responseData = [ |
47
|
|
|
'sEcho' => $queryConfiguration->drawCall(), |
48
|
|
|
'iTotalRecords' => $data->totalDataCount(), |
49
|
|
|
'iTotalDisplayRecords' => $data->data()->count(), |
50
|
|
|
'aaData' => $data->data()->toArray() |
51
|
|
|
]; |
52
|
|
|
return new JsonResponse($responseData); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string The name of the view that this version should use fot the table. |
57
|
|
|
*/ |
58
|
|
|
public function tableView() |
59
|
|
|
{ |
60
|
|
|
return "datatable::table"; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string The name of the view that this version should use for the script. |
65
|
|
|
*/ |
66
|
|
|
public function scriptView() |
67
|
|
|
{ |
68
|
|
|
return "datatable::datatable19"; |
69
|
|
|
} |
70
|
|
|
} |
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.