1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Soluble\FlexStore\Column\ColumnModel\Search; |
4
|
|
|
|
5
|
|
|
use Soluble\FlexStore\Column\Column; |
6
|
|
|
use Soluble\FlexStore\Column\ColumnSettableInterface; |
7
|
|
|
use Soluble\FlexStore\Column\Exception; |
8
|
|
|
use Soluble\FlexStore\Formatter\FormatterInterface; |
9
|
|
|
use ArrayObject; |
10
|
|
|
|
11
|
|
|
class Result implements ColumnSettableInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* |
15
|
|
|
* @var ArrayObject |
16
|
|
|
*/ |
17
|
|
|
protected $columns; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $results; |
24
|
|
|
|
25
|
10 |
|
public function __construct(array $results, ArrayObject $columns) |
26
|
|
|
{ |
27
|
10 |
|
$this->columns = $columns; |
28
|
10 |
|
$this->results = $results; |
29
|
10 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* @param FormatterInterface $formatter |
34
|
|
|
* @return Result |
35
|
|
|
*/ |
36
|
3 |
|
public function setFormatter(FormatterInterface $formatter) |
37
|
|
|
{ |
38
|
3 |
|
foreach ($this->results as $name) { |
39
|
3 |
|
$this->columns->offsetGet($name)->setFormatter($formatter); |
40
|
3 |
|
} |
41
|
3 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
* @throws Exception\InvalidArgumentException |
48
|
|
|
* @param string|\Soluble\FlexStore\Column\Type\AbstractType $type |
49
|
|
|
* @return Result |
50
|
|
|
*/ |
51
|
1 |
|
public function setType($type) |
52
|
|
|
{ |
53
|
1 |
|
foreach ($this->results as $name) { |
54
|
1 |
|
$this->columns->offsetGet($name)->setType($type); |
55
|
1 |
|
} |
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @param boolean $virtual |
63
|
|
|
* @return Result |
64
|
|
|
*/ |
65
|
1 |
|
public function setVirtual($virtual = true) |
66
|
|
|
{ |
67
|
1 |
|
foreach ($this->results as $name) { |
68
|
1 |
|
$this->columns->offsetGet($name)->setVirtual($virtual); |
69
|
1 |
|
} |
70
|
1 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
* @param boolean $excluded |
76
|
|
|
* @return Result |
77
|
|
|
*/ |
78
|
7 |
|
public function setExcluded($excluded = true) |
79
|
|
|
{ |
80
|
7 |
|
foreach ($this->results as $name) { |
81
|
7 |
|
$this->columns->offsetGet($name)->setExcluded($excluded); |
82
|
7 |
|
} |
83
|
7 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
* @param boolean $editable |
89
|
|
|
* @return Result |
90
|
|
|
*/ |
91
|
1 |
|
public function setEditable($editable = true) |
92
|
|
|
{ |
93
|
1 |
|
foreach ($this->results as $name) { |
94
|
1 |
|
$this->columns->offsetGet($name)->setEditable($editable); |
95
|
1 |
|
} |
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* @param boolean $hidden |
102
|
|
|
* @return Result |
103
|
|
|
*/ |
104
|
1 |
|
public function setHidden($hidden = true) |
105
|
|
|
{ |
106
|
1 |
|
foreach ($this->results as $name) { |
107
|
1 |
|
$this->columns->offsetGet($name)->setHidden($hidden); |
108
|
1 |
|
} |
109
|
1 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
* @param boolean $sortable |
115
|
|
|
* @return Result |
116
|
|
|
*/ |
117
|
1 |
|
public function setSortable($sortable = true) |
118
|
|
|
{ |
119
|
1 |
|
foreach ($this->results as $name) { |
120
|
1 |
|
$this->columns->offsetGet($name)->setSortable($sortable); |
121
|
1 |
|
} |
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* |
127
|
|
|
* @param boolean $groupable |
128
|
|
|
* @return Result |
129
|
|
|
*/ |
130
|
1 |
|
public function setGroupable($groupable = true) |
131
|
|
|
{ |
132
|
1 |
|
foreach ($this->results as $name) { |
133
|
1 |
|
$this->columns->offsetGet($name)->setGroupable($groupable); |
134
|
1 |
|
} |
135
|
1 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* |
140
|
|
|
* @param boolean $filterable |
141
|
|
|
* @return Result |
142
|
|
|
*/ |
143
|
1 |
|
public function setFilterable($filterable = true) |
144
|
|
|
{ |
145
|
1 |
|
foreach ($this->results as $name) { |
146
|
1 |
|
$this->columns->offsetGet($name)->setFilterable($filterable); |
147
|
1 |
|
} |
148
|
1 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set recommended width for the column |
153
|
|
|
* |
154
|
|
|
* @throws Exception\InvalidArgumentException |
155
|
|
|
* @param float|int|string $width |
156
|
|
|
* @return Result |
157
|
|
|
*/ |
158
|
1 |
|
public function setWidth($width) |
159
|
|
|
{ |
160
|
1 |
|
foreach ($this->results as $name) { |
161
|
1 |
|
$this->columns->offsetGet($name)->setWidth($width); |
162
|
1 |
|
} |
163
|
1 |
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set recommended horizontal align |
168
|
|
|
* |
169
|
|
|
* @throws Exception\InvalidArgumentException |
170
|
|
|
* @param string $align can be left|center|right |
171
|
|
|
* @return Column |
172
|
|
|
*/ |
173
|
1 |
|
public function setAlign($align) |
174
|
|
|
{ |
175
|
1 |
|
foreach ($this->results as $name) { |
176
|
1 |
|
$this->columns->offsetGet($name)->setAlign($align); |
177
|
1 |
|
} |
178
|
1 |
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Set recommended css class |
182
|
|
|
* |
183
|
|
|
* @throws Exception\InvalidArgumentException |
184
|
|
|
* @param string $class css class |
185
|
2 |
|
* @return Column |
186
|
|
|
*/ |
187
|
2 |
|
public function setClass($class) |
188
|
|
|
{ |
189
|
|
|
foreach ($this->results as $name) { |
190
|
|
|
$this->columns->offsetGet($name)->setClass($class); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Set table header for this column |
197
|
|
|
* |
198
|
|
|
* @throws Exception\InvalidArgumentException |
199
|
|
|
* @param string|null $header |
200
|
|
|
* @return Result |
201
|
|
|
*/ |
202
|
|
|
public function setHeader($header) |
203
|
|
|
{ |
204
|
|
|
foreach ($this->results as $name) { |
205
|
|
|
$this->columns->offsetGet($name)->setHeader($header); |
206
|
|
|
} |
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* |
212
|
|
|
* @return array |
213
|
|
|
*/ |
214
|
|
|
public function toArray() |
215
|
|
|
{ |
216
|
|
|
return $this->results; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|