Result::setGroupable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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