|
1 <?php |
|
2 |
|
3 /** |
|
4 * Zend Framework |
|
5 * |
|
6 * LICENSE |
|
7 * |
|
8 * This source file is subject to the new BSD license that is bundled |
|
9 * with this package in the file LICENSE.txt. |
|
10 * It is also available through the world-wide-web at this URL: |
|
11 * http://framework.zend.com/license/new-bsd |
|
12 * If you did not receive a copy of the license and are unable to |
|
13 * obtain it through the world-wide-web, please send an email |
|
14 * to license@zend.com so we can send you a copy immediately. |
|
15 * |
|
16 * @category Zend |
|
17 * @package Zend_Gdata |
|
18 * @subpackage Health |
|
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 * @version $Id: Query.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @see Zend_Gdata_Query |
|
26 */ |
|
27 require_once('Zend/Gdata/Query.php'); |
|
28 |
|
29 /** |
|
30 * Assists in constructing queries for Google Health |
|
31 * |
|
32 * @link http://code.google.com/apis/health |
|
33 * |
|
34 * @category Zend |
|
35 * @package Zend_Gdata |
|
36 * @subpackage Health |
|
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
38 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
39 */ |
|
40 class Zend_Gdata_Health_Query extends Zend_Gdata_Query |
|
41 { |
|
42 /** |
|
43 * URI of a user's profile feed. |
|
44 */ |
|
45 const HEALTH_PROFILE_FEED_URI = |
|
46 'https://www.google.com/health/feeds/profile/default'; |
|
47 |
|
48 /** |
|
49 * URI of register (notices) feed. |
|
50 */ |
|
51 const HEALTH_REGISTER_FEED_URI = |
|
52 'https://www.google.com/health/feeds/register/default'; |
|
53 |
|
54 /** |
|
55 * Namespace for an item category |
|
56 */ |
|
57 const ITEM_CATEGORY_NS = 'http://schemas.google.com/health/item'; |
|
58 |
|
59 /** |
|
60 * The default URI for POST methods |
|
61 * |
|
62 * @var string |
|
63 */ |
|
64 protected $_defaultFeedUri = self::HEALTH_PROFILE_FEED_URI; |
|
65 |
|
66 /** |
|
67 * Sets the digest parameter's value. |
|
68 * |
|
69 * @param string $value |
|
70 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
71 */ |
|
72 public function setDigest($value) |
|
73 { |
|
74 if ($value !== null) { |
|
75 $this->_params['digest'] = $value; |
|
76 } |
|
77 return $this; |
|
78 } |
|
79 |
|
80 /** |
|
81 * Returns the digest parameter's value. |
|
82 * |
|
83 * @return string The value set for the digest parameter. |
|
84 */ |
|
85 public function getDigest() |
|
86 { |
|
87 if (array_key_exists('digest', $this->_params)) { |
|
88 return $this->_params['digest']; |
|
89 } else { |
|
90 return null; |
|
91 } |
|
92 } |
|
93 |
|
94 /** |
|
95 * Setter for category queries. |
|
96 * |
|
97 * @param string $item A category to query. |
|
98 * @param string $name (optional) A specific item to search a category for. |
|
99 * An example would be 'Lipitor' if $item is set to 'medication'. |
|
100 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
101 */ |
|
102 public function setCategory($item, $name = null) |
|
103 { |
|
104 $this->_category = $item . |
|
105 ($name ? '/' . urlencode('{' . self::ITEM_CATEGORY_NS . '}' . $name) : null); |
|
106 return $this; |
|
107 } |
|
108 |
|
109 /** |
|
110 * Returns the query object's category. |
|
111 * |
|
112 * @return string id |
|
113 */ |
|
114 public function getCategory() |
|
115 { |
|
116 return $this->_category; |
|
117 } |
|
118 |
|
119 /** |
|
120 * Setter for the grouped parameter. |
|
121 * |
|
122 * @param string $value setting a count of results per group. |
|
123 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
124 */ |
|
125 public function setGrouped($value) |
|
126 { |
|
127 if ($value !== null) { |
|
128 $this->_params['grouped'] = $value; |
|
129 } |
|
130 return $this; |
|
131 } |
|
132 |
|
133 /** |
|
134 * Returns the value set for the grouped parameter. |
|
135 * |
|
136 * @return string grouped parameter. |
|
137 */ |
|
138 public function getGrouped() |
|
139 { |
|
140 if (array_key_exists('grouped', $this->_params)) { |
|
141 return $this->_params['grouped']; |
|
142 } else { |
|
143 return null; |
|
144 } |
|
145 } |
|
146 |
|
147 /** |
|
148 * Setter for the max-results-group parameter. |
|
149 * |
|
150 * @param int $value Specifies the maximum number of groups to be |
|
151 * retrieved. Must be an integer value greater than zero. This parameter |
|
152 * is only valid if grouped=true. |
|
153 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
154 */ |
|
155 public function setMaxResultsGroup($value) |
|
156 { |
|
157 if ($value !== null) { |
|
158 if ($value <= 0 || $this->getGrouped() !== 'true') { |
|
159 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
|
160 throw new Zend_Gdata_App_InvalidArgumentException( |
|
161 'The max-results-group parameter must be set to a value |
|
162 greater than 0 and can only be used if grouped=true'); |
|
163 } else { |
|
164 $this->_params['max-results-group'] = $value; |
|
165 } |
|
166 } |
|
167 return $this; |
|
168 } |
|
169 |
|
170 /** |
|
171 * Returns the value set for max-results-group. |
|
172 * |
|
173 * @return int Returns max-results-group parameter. |
|
174 */ |
|
175 public function getMaxResultsGroup() |
|
176 { |
|
177 if (array_key_exists('max-results-group', $this->_params)) { |
|
178 return $this->_params['max-results-group']; |
|
179 } else { |
|
180 return null; |
|
181 } |
|
182 } |
|
183 |
|
184 /** |
|
185 * Setter for the max-results-group parameter. |
|
186 * |
|
187 * @param int $value Specifies the maximum number of records to be |
|
188 * retrieved from each group. The limits that you specify with this |
|
189 * parameter apply to all groups. Must be an integer value greater than |
|
190 * zero. This parameter is only valid if grouped=true. |
|
191 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
192 */ |
|
193 public function setMaxResultsInGroup($value) |
|
194 { |
|
195 if ($value !== null) { |
|
196 if ($value <= 0 || $this->getGrouped() !== 'true') { |
|
197 throw new Zend_Gdata_App_InvalidArgumentException( |
|
198 'The max-results-in-group parameter must be set to a value |
|
199 greater than 0 and can only be used if grouped=true'); |
|
200 } else { |
|
201 $this->_params['max-results-in-group'] = $value; |
|
202 } |
|
203 } |
|
204 return $this; |
|
205 } |
|
206 |
|
207 /** |
|
208 * Returns the value set for max-results-in-group. |
|
209 * |
|
210 * @return int Returns max-results-in-group parameter. |
|
211 */ |
|
212 public function getMaxResultsInGroup() |
|
213 { |
|
214 if (array_key_exists('max-results-in-group', $this->_params)) { |
|
215 return $this->_params['max-results-in-group']; |
|
216 } else { |
|
217 return null; |
|
218 } |
|
219 } |
|
220 |
|
221 /** |
|
222 * Setter for the start-index-group parameter. |
|
223 * |
|
224 * @param int $value Retrieves only items whose group ranking is at |
|
225 * least start-index-group. This should be set to a 1-based index of the |
|
226 * first group to be retrieved. The range is applied per category. |
|
227 * This parameter is only valid if grouped=true. |
|
228 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
229 */ |
|
230 public function setStartIndexGroup($value) |
|
231 { |
|
232 if ($value !== null && $this->getGrouped() !== 'true') { |
|
233 throw new Zend_Gdata_App_InvalidArgumentException( |
|
234 'The start-index-group can only be used if grouped=true'); |
|
235 } else { |
|
236 $this->_params['start-index-group'] = $value; |
|
237 } |
|
238 return $this; |
|
239 } |
|
240 |
|
241 /** |
|
242 * Returns the value set for start-index-group. |
|
243 * |
|
244 * @return int Returns start-index-group parameter. |
|
245 */ |
|
246 public function getStartIndexGroup() |
|
247 { |
|
248 if (array_key_exists('start-index-group', $this->_params)) { |
|
249 return $this->_params['start-index-group']; |
|
250 } else { |
|
251 return null; |
|
252 } |
|
253 } |
|
254 |
|
255 /** |
|
256 * Setter for the start-index-in-group parameter. |
|
257 * |
|
258 * @param int $value A 1-based index of the records to be retrieved from |
|
259 * each group. This parameter is only valid if grouped=true. |
|
260 * @return Zend_Gdata_Health_Query Provides a fluent interface |
|
261 */ |
|
262 public function setStartIndexInGroup($value) |
|
263 { |
|
264 if ($value !== null && $this->getGrouped() !== 'true') { |
|
265 throw new Zend_Gdata_App_InvalidArgumentException('start-index-in-group'); |
|
266 } else { |
|
267 $this->_params['start-index-in-group'] = $value; |
|
268 } |
|
269 return $this; |
|
270 } |
|
271 |
|
272 /** |
|
273 * Returns the value set for start-index-in-group. |
|
274 * |
|
275 * @return int Returns start-index-in-group parameter. |
|
276 */ |
|
277 public function getStartIndexInGroup() |
|
278 { |
|
279 if (array_key_exists('start-index-in-group', $this->_params)) { |
|
280 return $this->_params['start-index-in-group']; |
|
281 } else { |
|
282 return null; |
|
283 } |
|
284 } |
|
285 } |