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\Tests\Fixtures\Provider; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesColumnInterface; |
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesOptionsInterface; |
16
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesResponseInterface; |
17
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Factory\DataTablesFactory; |
18
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesCSVExporterInterface; |
19
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesEditorInterface; |
20
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface; |
21
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesRouterInterface; |
22
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\Entity\Office; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Office DataTables provider. |
26
|
|
|
* |
27
|
|
|
* @author webeweb <https://github.com/webeweb> |
28
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\Provider |
29
|
|
|
*/ |
30
|
|
|
class OfficeDataTablesProvider implements DataTablesProviderInterface, DataTablesRouterInterface { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritDoc} |
34
|
|
|
*/ |
35
|
|
|
public function getCSVExporter(): ?DataTablesCSVExporterInterface { |
36
|
|
|
return null; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
*/ |
42
|
|
|
public function getColumns(): array { |
43
|
|
|
|
44
|
|
|
$dtColumns = []; |
45
|
|
|
|
46
|
|
|
$dtColumns[] = DataTablesFactory::newColumn("name", "Name"); |
47
|
|
|
$dtColumns[] = DataTablesFactory::newColumn("actions", "Actions")->setOrderable(false)->setSearchable(false); |
48
|
|
|
|
49
|
|
|
return $dtColumns; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
public function getEditor(): ?DataTablesEditorInterface { |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
*/ |
62
|
|
|
public function getEntity(): string { |
63
|
|
|
return Office::class; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
|
|
public function getMethod(): string { |
70
|
|
|
return "POST"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritDoc} |
75
|
|
|
*/ |
76
|
|
|
public function getName(): string { |
77
|
|
|
return "office"; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritDoc} |
82
|
|
|
*/ |
83
|
|
|
public function getOptions(): ?DataTablesOptionsInterface { |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritDoc} |
89
|
|
|
*/ |
90
|
|
|
public function getPrefix(): string { |
91
|
|
|
return "o"; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritDoc} |
96
|
|
|
*/ |
97
|
|
|
public function getUrl(): string { |
98
|
|
|
return "url"; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritDoc} |
103
|
|
|
*/ |
104
|
|
|
public function getView(): ?string { |
105
|
|
|
return null; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritDoc} |
110
|
|
|
*/ |
111
|
|
|
public function renderColumn(DataTablesColumnInterface $dtColumn, $entity): ?string { |
112
|
|
|
|
113
|
|
|
$output = null; |
114
|
|
|
|
115
|
|
|
switch ($dtColumn->getData()) { |
116
|
|
|
|
117
|
|
|
case "actions": |
118
|
|
|
$output = ""; |
119
|
|
|
break; |
120
|
|
|
|
121
|
|
|
case "name": |
122
|
|
|
$output = $entity->getName(); |
123
|
|
|
break; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $output; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritDoc} |
131
|
|
|
*/ |
132
|
|
|
public function renderRow(string $dtRow, $entity, int $rowNumber) { |
133
|
|
|
|
134
|
|
|
$output = null; |
135
|
|
|
|
136
|
|
|
switch ($dtRow) { |
137
|
|
|
|
138
|
|
|
case DataTablesResponseInterface::DATATABLES_ROW_ATTR: |
139
|
|
|
break; |
140
|
|
|
|
141
|
|
|
case DataTablesResponseInterface::DATATABLES_ROW_CLASS: |
142
|
|
|
$output = (0 === $rowNumber % 2 ? "even" : "odd"); |
143
|
|
|
break; |
144
|
|
|
|
145
|
|
|
case DataTablesResponseInterface::DATATABLES_ROW_DATA: |
146
|
|
|
$output = ["pkey" => $entity->getId()]; |
147
|
|
|
break; |
148
|
|
|
|
149
|
|
|
case DataTablesResponseInterface::DATATABLES_ROW_ID: |
150
|
|
|
$output = "office_" . $entity->getId(); |
151
|
|
|
break; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $output; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|