Completed
Push — master ( f1b857...d82134 )
by Nils
02:25
created

Datatable110Version::tableView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Datatable110QueryParser;
9
use OpenSkill\Datatable\Queries\QueryConfiguration;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use Symfony\Component\HttpFoundation\RequestStack;
12
13
/**
14
 * Class Datatable110Version
15
 * @package OpenSkill\Datatable\Versions
16
 *
17
 * Version that supports the 1.10 version of datatables
18
 * http://datatables.net/index
19
 *
20
 */
21 View Code Duplication
class Datatable110Version extends DatatableVersion
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
22
{
23
    /**
24
     * Datatable110Version constructor.
25
     *
26
     * @param RequestStack $requestStack The current request
27
     */
28
    public function __construct(RequestStack $requestStack)
29
    {
30
        parent::__construct($requestStack, new Datatable110QueryParser());
31
    }
32
33
    /**
34
     * Is responsible to take the generated data and prepare a response for it.
35
     * @param ResponseData $data The processed data.
36
     * @param QueryConfiguration $queryConfiguration the query configuration for the current request.
37
     * @param ColumnConfiguration[] $columnConfigurations the column configurations for the current data table.
38
     * @return JsonResponse the response that should be returned to the client.
39
     */
40
    public function createResponse(
41
        ResponseData $data,
42
        QueryConfiguration $queryConfiguration,
43
        array $columnConfigurations
44
    ) {
45
        $responseData = [
46
            'draw' => $queryConfiguration->drawCall(),
47
            'recordsTotal' => $data->totalDataCount(),
48
            'recordsFiltered' => $data->data()->count(),
49
            'data' => $data->data()->toArray()
50
        ];
51
        return new JsonResponse($responseData);
52
    }
53
54
    /**
55
     * @return string The name of the view that this version should use fot the table.
56
     */
57
    public function tableView()
58
    {
59
        return "datatable::table";
60
    }
61
62
    /**
63
     * @return string The name of the view that this version should use for the script.
64
     */
65
    public function scriptView()
66
    {
67
        return "datatable::datatable110";
68
    }
69
}