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\Model; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesOptionsInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* DataTables options. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Model |
21
|
|
|
*/ |
22
|
|
|
class DataTablesOptions implements DataTablesOptionsInterface { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Options. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private $options; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
*/ |
34
|
|
|
public function __construct() { |
35
|
|
|
$this->setOptions([]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
|
|
public function addOption(string $name, $value): DataTablesOptionsInterface { |
42
|
|
|
if (false === array_key_exists($name, $this->options)) { |
43
|
|
|
$this->options[$name] = $value; |
44
|
|
|
} |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
|
|
public function getOption(string $name) { |
52
|
|
|
if (true === array_key_exists($name, $this->options)) { |
53
|
|
|
return $this->options[$name]; |
54
|
|
|
} |
55
|
|
|
return null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
|
|
*/ |
61
|
|
|
public function getOptions(): array { |
62
|
|
|
return $this->options; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritDoc} |
67
|
|
|
*/ |
68
|
|
|
public function hasOption(string $name): bool { |
69
|
|
|
return array_key_exists($name, $this->options); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
*/ |
75
|
|
|
public function removeOption(string $name): DataTablesOptionsInterface { |
76
|
|
|
if (true === array_key_exists($name, $this->options)) { |
77
|
|
|
unset($this->options[$name]); |
78
|
|
|
} |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function setOption(string $name, $value): DataTablesOptionsInterface { |
86
|
|
|
$this->options[$name] = $value; |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Set the options. |
92
|
|
|
* |
93
|
|
|
* @param array $options The options. |
94
|
|
|
* @return DataTablesOptionsInterface Returns this options. |
95
|
|
|
*/ |
96
|
|
|
protected function setOptions(array $options): DataTablesOptionsInterface { |
97
|
|
|
$this->options = $options; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|