Completed
Push — master ( d9d5ce...5f84b6 )
by WEBEWEB
06:30
created

DataTablesResponse::newInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A DataTablesResponse::setDraw() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DatatablesBundle\Response;
13
14
use JsonSerializable;
15
use WBW\Bundle\JQuery\DatatablesBundle\Request\DataTablesRequest;
16
17
/**
18
 * DataTables response.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\JQuery\DatatablesBundle\Response
22
 * @final
23
 */
24
final class DataTablesResponse implements JsonSerializable {
25
26
    /**
27
     * Data.
28
     *
29
     * @var array
30
     */
31
    private $data;
32
33
    /**
34
     * Draw.
35
     *
36
     * @var integer
37
     */
38
    private $draw;
39
40
    /**
41
     * Error.
42
     *
43
     * @var string
44
     */
45
    private $error;
46
47
    /**
48
     * Records filtered.
49
     *
50
     * @var integer
51
     */
52
    private $recordsFiltered;
53
54
    /**
55
     * Records total.
56
     *
57
     * @var integer
58
     */
59
    private $recordsTotal;
60
61
    /**
62
     * Constructor.
63
     *
64
     * @param DataTablesRequest $dtRequest The DataTables request.
65
     */
66
    public function __construct(DataTablesRequest $dtRequest) {
67
68
        // Set the attributes.
69
        $this->setData([]);
70
        $this->setDraw($dtRequest->getDraw());
71
        $this->setRecordsFiltered(0);
72
        $this->setRecordsTotal(0);
73
    }
74
75
    /**
76
     * Get the data.
77
     *
78
     * @return array Returns the data.
79
     */
80
    public function getData() {
81
        return $this->data;
82
    }
83
84
    /**
85
     * Get the draw
86
     *
87
     * @return integer Returns the draw.
88
     */
89
    public function getDraw() {
90
        return $this->draw;
91
    }
92
93
    /**
94
     * Get the error.
95
     *
96
     * @return string Returns the error.
97
     */
98
    public function getError() {
99
        return $this->error;
100
    }
101
102
    /**
103
     * Get the records filtered.
104
     *
105
     * @return integer The records filtered.
106
     */
107
    public function getRecordsFiltered() {
108
        return $this->recordsFiltered;
109
    }
110
111
    /**
112
     * Get the records total.
113
     *
114
     * @return integer Returns the records total.
115
     */
116
    public function getRecordsTotal() {
117
        return $this->recordsTotal;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function jsonSerialize() {
124
        return $this->toArray();
125
    }
126
127
    /**
128
     * Set the draw.
129
     *
130
     * @param integer $draw The draw.
131
     * @return DataTablesResponse Returns the DataTables response.
132
     */
133
    private function setDraw($draw) {
134
        $this->draw = $draw;
135
        return $this;
136
    }
137
138
    /**
139
     * Set the data.
140
     *
141
     * @param array $data The data.
142
     * @return DataTablesResponse Returns the DataTables response.
143
     */
144
    private function setData(array $data) {
145
        $this->data = $data;
146
        return $this;
147
    }
148
149
    /**
150
     * Set the error.
151
     *
152
     * @param string $error The error.
153
     * @return DataTablesResponse Returns the DataTables response.
154
     */
155
    public function setError($error) {
156
        $this->error = $error;
157
        return $this;
158
    }
159
160
    /**
161
     * Set the records filtered.
162
     *
163
     * @param integer $recordsFiltered The records filtered.
164
     * @return DataTablesResponse Returns the DataTables response.
165
     */
166
    public function setRecordsFiltered($recordsFiltered) {
167
        $this->recordsFiltered = $recordsFiltered;
168
        return $this;
169
    }
170
171
    /**
172
     * Set the records total.
173
     *
174
     * @param integer $recordsTotal The records total.
175
     * @return DataTablesResponse Returns the DataTables response.
176
     */
177
    public function setRecordsTotal($recordsTotal) {
178
        $this->recordsTotal = $recordsTotal;
179
        return $this;
180
    }
181
182
    /**
183
     * Convert into an array representing this instance.
184
     *
185
     * @return array Returns an array representing this instance.
186
     */
187
    public function toArray() {
188
189
        // Initialize the output.
190
        $output = [];
191
192
        $output["data"]            = $this->data;
193
        $output["draw"]            = $this->draw;
194
        $output["recordsFiltered"] = $this->recordsFiltered;
195
        $output["recordsTotal"]    = $this->recordsTotal;
196
197
        // Return the output.
198
        return $output;
199
    }
200
201
}
202