|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Objects; |
|
4
|
|
|
|
|
5
|
|
|
class Filter |
|
6
|
|
|
{ |
|
7
|
|
|
private $rawFilter; |
|
8
|
|
|
|
|
9
|
|
|
private $ids; |
|
10
|
|
|
|
|
11
|
|
|
private $operator; |
|
12
|
|
|
|
|
13
|
8 |
|
public static function box(array $params) |
|
14
|
|
|
{ |
|
15
|
8 |
|
$rawIds = $params['ids']; |
|
16
|
8 |
|
$operator = key($rawIds); |
|
17
|
8 |
|
$ids = join(',', current($rawIds)); |
|
18
|
8 |
|
$path = $params['path']; |
|
19
|
|
|
|
|
20
|
8 |
|
return new self([ |
|
21
|
8 |
|
'raw_filter' => self::buildRawFilter($path, $operator), |
|
22
|
8 |
|
'ids' => $ids, |
|
23
|
8 |
|
'operator' => $operator, |
|
24
|
8 |
|
'path' => $path, |
|
25
|
|
|
]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
8 |
|
private static function buildRawFilter($path, $operator) |
|
29
|
|
|
{ |
|
30
|
8 |
|
return $path . '.id|' . $operator; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
8 |
|
private function __construct(array $params) |
|
34
|
|
|
{ |
|
35
|
8 |
|
$this->rawFilter = $params['raw_filter']; |
|
36
|
8 |
|
$this->ids = $params['ids']; |
|
37
|
8 |
|
$this->operator = $params['operator']; |
|
38
|
8 |
|
$this->path = $params['path']; |
|
|
|
|
|
|
39
|
8 |
|
} |
|
40
|
|
|
|
|
41
|
6 |
|
public function getRawFilter() |
|
42
|
|
|
{ |
|
43
|
6 |
|
return $this->rawFilter; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
6 |
|
public function getIds() |
|
47
|
|
|
{ |
|
48
|
6 |
|
return $this->ids; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
6 |
|
public function getOperator() |
|
52
|
|
|
{ |
|
53
|
6 |
|
return $this->operator; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
3 |
|
public function getPath() |
|
57
|
|
|
{ |
|
58
|
3 |
|
return $this->path; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function withPath($path) |
|
62
|
|
|
{ |
|
63
|
1 |
|
return new self([ |
|
64
|
1 |
|
'raw_filter' => self::buildRawFilter($path, $this->operator), |
|
65
|
1 |
|
'ids' => $this->ids, |
|
66
|
1 |
|
'operator' => $this->operator, |
|
67
|
1 |
|
'path' => $path, |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function withFullPath($path) |
|
72
|
|
|
{ |
|
73
|
1 |
|
$explodedPath = explode('|', $path); |
|
74
|
|
|
|
|
75
|
1 |
|
$path = $explodedPath[0]; |
|
76
|
1 |
|
$operator = $explodedPath[1]; |
|
77
|
|
|
|
|
78
|
1 |
|
return new self([ |
|
79
|
1 |
|
'raw_filter' => join('|', $explodedPath), |
|
80
|
1 |
|
'ids' => $this->ids, |
|
81
|
1 |
|
'operator' => $operator, |
|
82
|
1 |
|
'path' => $path, |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|