1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Filter to apply on GET requests to the statements API. |
16
|
|
|
* |
17
|
|
|
* @author Christian Flothmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class StatementsFilter |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array The generated filter |
23
|
|
|
*/ |
24
|
|
|
private $filter = array(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Filters by an Agent or an identified Group. |
28
|
|
|
* |
29
|
|
|
* @param Actor $actor The Actor to filter by |
30
|
|
|
* |
31
|
|
|
* @return self The statements filter |
32
|
|
|
*/ |
33
|
1 |
|
public function byActor(Actor $actor) |
34
|
|
|
{ |
35
|
1 |
|
$this->filter['agent'] = $actor; |
36
|
|
|
|
37
|
1 |
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Filters by a verb. |
42
|
|
|
* |
43
|
|
|
* @param Verb $verb The Verb to filter by |
44
|
|
|
* |
45
|
|
|
* @return self The statements filter |
46
|
|
|
*/ |
47
|
1 |
|
public function byVerb(Verb $verb) |
48
|
|
|
{ |
49
|
1 |
|
$this->filter['verb'] = $verb->getId()->getValue(); |
50
|
|
|
|
51
|
1 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Filter by an Activity. |
56
|
|
|
* |
57
|
|
|
* @param Activity $activity The Activity to filter by |
58
|
|
|
* |
59
|
|
|
* @return self The statements filter |
60
|
|
|
*/ |
61
|
1 |
|
public function byActivity(Activity $activity) |
62
|
|
|
{ |
63
|
1 |
|
$this->filter['activity'] = $activity->getId()->getValue(); |
64
|
|
|
|
65
|
1 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Filters for Statements matching the given registration id. |
70
|
|
|
* |
71
|
|
|
* @param string $registration A registration id |
72
|
|
|
* |
73
|
|
|
* @return self The statements filter |
74
|
|
|
*/ |
75
|
1 |
|
public function byRegistration($registration) |
76
|
|
|
{ |
77
|
1 |
|
$this->filter['registration'] = $registration; |
78
|
1 |
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Applies the Activity filter to Sub-Statements. |
84
|
|
|
* |
85
|
1 |
|
* @return self The statements filter |
86
|
|
|
*/ |
87
|
1 |
|
public function enableRelatedActivityFilter() |
88
|
1 |
|
{ |
89
|
|
|
$this->filter['related_activities'] = 'true'; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
1 |
|
* Don't apply the Activity filter to Sub-Statements. |
96
|
|
|
* |
97
|
1 |
|
* @return self The statements filter |
98
|
1 |
|
*/ |
99
|
|
|
public function disableRelatedActivityFilter() |
100
|
|
|
{ |
101
|
|
|
$this->filter['related_activities'] = 'false'; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
1 |
|
|
106
|
|
|
/** |
107
|
1 |
|
* Applies the Agent filter to Sub-Statements. |
108
|
1 |
|
* |
109
|
|
|
* @return self The statements filter |
110
|
|
|
*/ |
111
|
|
|
public function enableRelatedAgentFilter() |
112
|
|
|
{ |
113
|
|
|
$this->filter['related_agents'] = 'true'; |
114
|
|
|
|
115
|
1 |
|
return $this; |
116
|
|
|
} |
117
|
1 |
|
|
118
|
1 |
|
/** |
119
|
|
|
* Don't apply the Agent filter to Sub-Statements. |
120
|
|
|
* |
121
|
|
|
* @return self The statements filter |
122
|
|
|
*/ |
123
|
|
|
public function disableRelatedAgentFilter() |
124
|
|
|
{ |
125
|
|
|
$this->filter['related_agents'] = 'false'; |
126
|
|
|
|
127
|
1 |
|
return $this; |
128
|
|
|
} |
129
|
1 |
|
|
130
|
|
|
/** |
131
|
1 |
|
* Filters for Statements stored since the specified timestamp (exclusive). |
132
|
|
|
* |
133
|
|
|
* @param \DateTime $timestamp The timestamp |
134
|
|
|
* |
135
|
|
|
* @return self The statements filter |
136
|
|
|
*/ |
137
|
|
|
public function since(\DateTime $timestamp) |
138
|
|
|
{ |
139
|
|
|
$this->filter['since'] = $timestamp->format('c'); |
140
|
|
|
|
141
|
1 |
|
return $this; |
142
|
|
|
} |
143
|
1 |
|
|
144
|
|
|
/** |
145
|
1 |
|
* Filters for Statements stored at or before the specified timestamp. |
146
|
|
|
* |
147
|
|
|
* @param \DateTime $timestamp The timestamp as a unix timestamp |
148
|
|
|
* |
149
|
|
|
* @return self The statements filter |
150
|
|
|
*/ |
151
|
|
|
public function until(\DateTime $timestamp) |
152
|
|
|
{ |
153
|
|
|
$this->filter['until'] = $timestamp->format('c'); |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
2 |
|
* Sets the maximum number of Statements to return. The server side sets |
160
|
|
|
* the maximum number of results when this value is not set or when it is 0. |
161
|
2 |
|
* |
162
|
1 |
|
* @param int $limit Maximum number of Statements to return |
163
|
|
|
* |
164
|
|
|
* @return self The statements filter |
165
|
1 |
|
* |
166
|
|
|
* @throws \InvalidArgumentException if the limit is not a non-negative |
167
|
1 |
|
* integer |
168
|
|
|
*/ |
169
|
|
|
public function limit($limit) |
170
|
|
|
{ |
171
|
|
|
if ($limit < 0) { |
172
|
|
|
throw new \InvalidArgumentException('Limit must be a non-negative integer'); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$this->filter['limit'] = $limit; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Return statements in ascending order of stored time. |
182
|
|
|
* |
183
|
|
|
* @return self The statements filter |
184
|
|
|
*/ |
185
|
|
|
public function ascending() |
186
|
|
|
{ |
187
|
|
|
$this->filter['ascending'] = 'true'; |
188
|
|
|
|
189
|
|
|
return $this; |
190
|
4 |
|
} |
191
|
|
|
|
192
|
4 |
|
/** |
193
|
1 |
|
*Return statements in descending order of stored time (the default behavior). |
194
|
|
|
* |
195
|
|
|
* @return self The statements filter |
196
|
3 |
|
*/ |
197
|
3 |
|
public function descending() |
198
|
|
|
{ |
199
|
|
|
$this->filter['ascending'] = 'false'; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
1 |
|
/** |
205
|
|
|
* Returns the generated filter. |
206
|
1 |
|
* |
207
|
1 |
|
* @return array The filter |
208
|
|
|
*/ |
209
|
|
|
public function getFilter() |
210
|
|
|
{ |
211
|
|
|
return $this->filter; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|