|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Queries; |
|
4
|
|
|
|
|
5
|
|
|
class QueryBuilderOptions |
|
6
|
|
|
{ |
|
7
|
|
|
private $options; |
|
8
|
|
|
|
|
9
|
3 |
|
private function __construct(array $options) |
|
10
|
|
|
{ |
|
11
|
3 |
|
$this->options = $options; |
|
12
|
3 |
|
} |
|
13
|
|
|
|
|
14
|
3 |
|
public static function fromArray(array $options) |
|
15
|
|
|
{ |
|
16
|
3 |
|
return new self($options); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
3 |
|
public function get($option, $defaultValue = null) |
|
20
|
|
|
{ |
|
21
|
3 |
|
$this->validateOption($option, $defaultValue); |
|
22
|
|
|
|
|
23
|
|
|
if ( |
|
24
|
3 |
|
!isset($this->options[$option]) |
|
25
|
3 |
|
|| empty($this->options[$option]) |
|
26
|
|
|
) { |
|
27
|
1 |
|
return $defaultValue; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
2 |
|
return $this->options[$option]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getAndFilters() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->get('filters', []); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getOrFilters() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->get('orFilters', []); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getSorting() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->get('sorting', []); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getRel() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->get('rel'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getPrinting() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->get('printing', []); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getSelect() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->get('select'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
public function validateOption($option, $defaultValue) |
|
64
|
|
|
{ |
|
65
|
|
|
$optionIsDefinedNegativeAndNotNull = ( |
|
|
|
|
|
|
66
|
3 |
|
!isset($this->options[$option]) |
|
67
|
3 |
|
|| $this->options[$option] < 0 |
|
68
|
3 |
|
) && $defaultValue == null; |
|
69
|
|
|
|
|
70
|
3 |
|
if ('limit' == $option && $optionIsDefinedNegativeAndNotNull) { |
|
71
|
2 |
|
$this->options[$option] = PHP_INT_MAX; |
|
72
|
|
|
} |
|
73
|
3 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|