|
1
|
|
|
<?php |
|
2
|
|
|
class ODataParams |
|
3
|
|
|
{ |
|
4
|
|
|
public $filter = false; |
|
5
|
|
|
public $expand = false; |
|
6
|
|
|
public $select = false; |
|
7
|
|
|
public $orderby = false; |
|
8
|
|
|
public $top = false; |
|
9
|
|
|
public $skip = false; |
|
10
|
|
|
public $count = false; |
|
11
|
|
|
public $search = false; |
|
12
|
|
|
|
|
13
|
|
|
function __construct($params) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
View Code Duplication |
if(isset($params['filter'])) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$this->filter = new \Data\Filter($params['filter']); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
else if(isset($params['$filter'])) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->filter = new \Data\Filter($params['$filter']); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
if(isset($params['$expand'])) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->expand = explode(',',$params['$expand']); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if(isset($params['select'])) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->select = explode(',',$params['select']); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
else if(isset($params['$select'])) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->select = explode(',',$params['$select']); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if(isset($params['$orderby'])) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->orderby = array(); |
|
|
|
|
|
|
41
|
|
|
$orderby = explode(',',$params['$orderby']); |
|
42
|
|
|
$count = count($orderby); |
|
43
|
|
|
for($i = 0; $i < $count; $i++) |
|
44
|
|
|
{ |
|
45
|
|
|
$exp = explode(' ',$orderby[$i]); |
|
46
|
|
|
if(count($exp) === 1) |
|
47
|
|
|
{ |
|
48
|
|
|
//Default to assending |
|
49
|
|
|
$this->orderby[$exp[0]] = 1; |
|
50
|
|
|
} |
|
51
|
|
|
else |
|
52
|
|
|
{ |
|
53
|
|
|
switch($exp[1]) |
|
54
|
|
|
{ |
|
55
|
|
|
case 'asc': |
|
56
|
|
|
$this->orderby[$exp[0]] = 1; |
|
57
|
|
|
break; |
|
58
|
|
|
case 'desc': |
|
59
|
|
|
$this->orderby[$exp[0]] = -1; |
|
60
|
|
|
break; |
|
61
|
|
|
default: |
|
62
|
|
|
throw new Exception('Unknown orderby operation'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if(isset($params['$top'])) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->top = $params['$top']; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if(isset($params['$skip'])) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->skip = $params['$skip']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if(isset($params['$count']) && $params['$count'] === 'true') |
|
79
|
|
|
{ |
|
80
|
|
|
$this->count = true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if(isset($params['$seach'])) |
|
84
|
|
|
{ |
|
85
|
|
|
throw new Exception('Search not yet implemented'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
?> |
|
|
|
|
|
|
90
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.