|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class ExactHierarchyOrFilter |
|
5
|
|
|
* |
|
6
|
|
|
* @package dms |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class ExactHierarchyOrFilter extends SearchFilter |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
// @codeCoverageIgnoreStart |
|
12
|
|
View Code Duplication |
public function setModifiers(array $modifiers) |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
if (($extras = array_diff($modifiers, array('not'))) != array()) { |
|
15
|
|
|
throw new InvalidArgumentException( |
|
16
|
|
|
get_class($this) . 'only used for filtering many_many relation, so does not accept ' |
|
17
|
|
|
.implode(', ', $extras) . ' as modifiers' |
|
18
|
|
|
); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
parent::setModifiers($modifiers); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function applyOne(DataQuery $query) |
|
25
|
|
|
{ |
|
26
|
|
|
/* NO OP */ |
|
27
|
|
|
} |
|
28
|
|
|
protected function excludeOne(DataQuery $query) |
|
29
|
|
|
{ |
|
30
|
|
|
/* NO OP */ |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
protected function excludeMany(DataQuery $query) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
|
|
36
|
|
|
$values = array(); |
|
37
|
|
|
$relationModelClass = $this->model; |
|
38
|
|
|
foreach ($this->getValue() as $value) { |
|
|
|
|
|
|
39
|
|
|
$relationModel = $relationModelClass::get_by_id($relationModelClass, (int)$value); |
|
40
|
|
|
if ($relationModel) { |
|
41
|
|
|
$values = array_merge($values, $relationModel->getHierarchicalIDs()); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$valueStr = "'" . implode("', '", $values) . "'"; |
|
46
|
|
|
$dbName = singleton($relationModelClass)->getDBName(); |
|
47
|
|
|
return $query->where(sprintf( |
|
48
|
|
|
'%s NOT IN (%s)', |
|
49
|
|
|
$dbName, |
|
50
|
|
|
$valueStr |
|
51
|
|
|
)); |
|
52
|
|
|
} |
|
53
|
|
|
// @codeCoverageIgnoreEnd |
|
54
|
|
View Code Duplication |
protected function applyMany(DataQuery $query) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
|
|
57
|
|
|
$values = array(); |
|
58
|
|
|
$relationModelClass = $this->model; |
|
59
|
|
|
foreach ($this->getValue() as $value) { |
|
|
|
|
|
|
60
|
|
|
$relationModel = $relationModelClass::get_by_id($relationModelClass, (int)$value); |
|
61
|
|
|
if ($relationModel) { |
|
62
|
|
|
$values = array_merge($values, $relationModel->getHierarchicalIDs()); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$valueStr = "'" . implode("', '", $values) . "'"; |
|
67
|
|
|
$dbName = singleton($relationModelClass)->getDBName(); |
|
68
|
|
|
return $query->where(sprintf( |
|
69
|
|
|
'%s IN (%s)', |
|
70
|
|
|
$dbName, |
|
71
|
|
|
$valueStr |
|
72
|
|
|
)); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.