7
7
*/
8
8
class Order {
9
9
10
- public function __construct ($ propertyName , $ ascending = TRUE ) {
10
+ public function __construct ($ propertyName , $ ascending = TRUE , $ isSql = FALSE ) {
11
11
$ this ->propertyName = $ propertyName ;
12
12
$ this ->ascending = $ ascending ;
13
13
$ this ->ignoreCase = FALSE ;
14
+ $ this ->sql = $ isSql ;
14
15
}
15
16
16
17
/*
@@ -31,16 +32,20 @@ public function toSqlString($localQuery, $overallQuery) {
31
32
$ lower = $ this ->ignoreCase ;
32
33
33
34
$ rc = '' ;
34
- if ($ lower ) {
35
- $ rc .= 'LOWER( ' ;
36
- }
37
- $ rc .= $ overallQuery ->quoteName ($ localQuery ->getAlias (), $ this ->propertyName );
38
- if ($ lower ) {
39
- $ rc .= ') ' ;
40
- }
35
+ if (!$ this ->sql ) {
36
+ if ($ lower ) {
37
+ $ rc .= 'LOWER( ' ;
38
+ }
39
+ $ rc .= $ overallQuery ->quoteName ($ localQuery ->getAlias (), $ this ->propertyName );
40
+ if ($ lower ) {
41
+ $ rc .= ') ' ;
42
+ }
41
43
42
- if (!$ this ->ascending ) {
43
- $ rc .= ' DESC ' ;
44
+ if (!$ this ->ascending ) {
45
+ $ rc .= ' DESC ' ;
46
+ }
47
+ } else {
48
+ $ rc = $ this ->propertyName ;
44
49
}
45
50
return $ rc ;
46
51
}
@@ -53,6 +58,10 @@ public static function desc($propertyName) {
53
58
return new Order ($ propertyName , FALSE );
54
59
}
55
60
61
+ public static function sql ($ sql ) {
62
+ return new Order ($ sql , TRUE , TRUE );
63
+ }
64
+
56
65
/**
57
66
* Creates the order object.
58
67
* @param mixed $orders - string or order object (fieldname ASC/DESC)
@@ -67,9 +76,8 @@ public static function toOrder($order) {
67
76
$ lastWord = strtolower (substr ($ s , $ pos +1 ));
68
77
if ($ lastWord == 'desc ' ) return Order::desc (substr ($ s , 0 , $ pos ));
69
78
if ($ lastWord == 'asc ' ) return Order::asc (substr ($ s , 0 , $ pos ));
70
- return Order::asc ($ s );
71
79
}
72
- return Order::asc ($ s );
80
+ return Order::sql ($ s );
73
81
}
74
82
75
83
}
0 commit comments