-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseRestrictions.php
100 lines (74 loc) · 3.12 KB
/
DatabaseRestrictions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Polyplus\Api\Database;
/**
* Description of Restricions
*
* @author rodrigohitec
*/
class DatabaseRestrictions {
public static function group(array $criterions, $constraint) {
$content = "";
$parameters = array();
foreach ($criterions as $criterion) {
$criterionContent = $criterion->toString();
$content .= "($criterionContent) $constraint ";
$parameters = array_merge($parameters, $criterion->getParameters());
}
$positionsToCut = (strlen($constraint)+2)*-1;
$content = substr($content, 0, $positionsToCut);
return new DatabaseCriterion($content, $parameters);
}
public static function compare($param1, $param2, $constraint) {
return new DatabaseCriterion("$param1 $constraint ?", array($param2));
}
public static function conjunction(array $criterions) {
return DatabaseRestrictions::group($criterions, "and");
}
public static function disjunction(array $criterions) {
return DatabaseRestrictions::group($criterions, "or");
}
public static function eq($property, $value) {
return DatabaseRestrictions::compare($property, $value, "=");
}
public static function eqProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, "=");
}
public static function ge($property, $value) {
return DatabaseRestrictions::compare($property, $value, ">=");
}
public static function geProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, ">=");
}
public static function gt($property, $value) {
return DatabaseRestrictions::compare($property, $value, ">");
}
public static function gtProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, ">");
}
public static function le($property, $value) {
return DatabaseRestrictions::compare($property, $value, "<=");
}
public static function leProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, "<=");
}
public static function lt($property, $value) {
return DatabaseRestrictions::compare($property, $value, "<");
}
public static function ltProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, "<");
}
public static function ne($property, $value) {
return DatabaseRestrictions::compare($property, $value, "!=");
}
public static function neProperty($property1, $property2) {
return DatabaseRestrictions::compare($property1, $property2, "!=");
}
public static function not(DatabaseCriterion $criterion) {
$content = $criterion->toString();
return new DatabaseCriterion("not ($content)", $criterion->getParameters());
}
public static function like($property, $value) {
return DatabaseRestrictions::compare($property, "'$value'", "like");
}
}
?>