File indexing completed on 2024-12-22 05:36:47
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage Gdata 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * Zend_Gdata_App_Util 0026 */ 0027 // require_once 'Zend/Gdata/App/Util.php'; 0028 0029 /** 0030 * Provides a mechanism to build a query URL for Gdata services. 0031 * Queries are not defined for APP, but are provided by Gdata services 0032 * as an extension. 0033 * 0034 * @category Zend 0035 * @package Zend_Gdata 0036 * @subpackage Gdata 0037 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0038 * @license http://framework.zend.com/license/new-bsd New BSD License 0039 */ 0040 class Zend_Gdata_Query 0041 { 0042 0043 /** 0044 * Query parameters. 0045 * 0046 * @var array 0047 */ 0048 protected $_params = array(); 0049 0050 /** 0051 * Default URL 0052 * 0053 * @var string 0054 */ 0055 protected $_defaultFeedUri = null; 0056 0057 /** 0058 * Base URL 0059 * TODO: Add setters and getters 0060 * 0061 * @var string 0062 */ 0063 protected $_url = null; 0064 0065 /** 0066 * Category for the query 0067 * 0068 * @var string 0069 */ 0070 protected $_category = null; 0071 0072 /** 0073 * Create Gdata_Query object 0074 */ 0075 public function __construct($url = null) 0076 { 0077 $this->_url = $url; 0078 } 0079 0080 /** 0081 * @return string querystring 0082 */ 0083 public function getQueryString() 0084 { 0085 $queryArray = array(); 0086 foreach ($this->_params as $name => $value) { 0087 if (substr($name, 0, 1) == '_') { 0088 continue; 0089 } 0090 $queryArray[] = urlencode($name) . '=' . urlencode($value); 0091 } 0092 if (count($queryArray) > 0) { 0093 return '?' . implode('&', $queryArray); 0094 } else { 0095 return ''; 0096 } 0097 } 0098 0099 /** 0100 * 0101 */ 0102 public function resetParameters() 0103 { 0104 $this->_params = array(); 0105 } 0106 0107 /** 0108 * @return string url 0109 */ 0110 public function getQueryUrl() 0111 { 0112 if ($this->_url == null) { 0113 $url = $this->_defaultFeedUri; 0114 } else { 0115 $url = $this->_url; 0116 } 0117 if ($this->getCategory() !== null) { 0118 $url .= '/-/' . $this->getCategory(); 0119 } 0120 $url .= $this->getQueryString(); 0121 return $url; 0122 } 0123 0124 /** 0125 * @param string $name 0126 * @param string $value 0127 * @return Zend_Gdata_Query Provides a fluent interface 0128 */ 0129 public function setParam($name, $value) 0130 { 0131 $this->_params[$name] = $value; 0132 return $this; 0133 } 0134 0135 /** 0136 * @param string $name 0137 */ 0138 public function getParam($name) 0139 { 0140 return $this->_params[$name]; 0141 } 0142 0143 /** 0144 * @param string $value 0145 * @return Zend_Gdata_Query Provides a fluent interface 0146 */ 0147 public function setAlt($value) 0148 { 0149 if ($value != null) { 0150 $this->_params['alt'] = $value; 0151 } else { 0152 unset($this->_params['alt']); 0153 } 0154 return $this; 0155 } 0156 0157 /** 0158 * @param int $value 0159 * @return Zend_Gdata_Query Provides a fluent interface 0160 */ 0161 public function setMaxResults($value) 0162 { 0163 if ($value != null) { 0164 $this->_params['max-results'] = $value; 0165 } else { 0166 unset($this->_params['max-results']); 0167 } 0168 return $this; 0169 } 0170 0171 /** 0172 * @param string $value 0173 * @return Zend_Gdata_Query Provides a fluent interface 0174 */ 0175 public function setQuery($value) 0176 { 0177 if ($value != null) { 0178 $this->_params['q'] = $value; 0179 } else { 0180 unset($this->_params['q']); 0181 } 0182 return $this; 0183 } 0184 0185 /** 0186 * @param int $value 0187 * @return Zend_Gdata_Query Provides a fluent interface 0188 */ 0189 public function setStartIndex($value) 0190 { 0191 if ($value != null) { 0192 $this->_params['start-index'] = $value; 0193 } else { 0194 unset($this->_params['start-index']); 0195 } 0196 return $this; 0197 } 0198 0199 /** 0200 * @param string $value 0201 * @return Zend_Gdata_Query Provides a fluent interface 0202 */ 0203 public function setUpdatedMax($value) 0204 { 0205 if ($value != null) { 0206 $this->_params['updated-max'] = Zend_Gdata_App_Util::formatTimestamp($value); 0207 } else { 0208 unset($this->_params['updated-max']); 0209 } 0210 return $this; 0211 } 0212 0213 /** 0214 * @param string $value 0215 * @return Zend_Gdata_Query Provides a fluent interface 0216 */ 0217 public function setUpdatedMin($value) 0218 { 0219 if ($value != null) { 0220 $this->_params['updated-min'] = Zend_Gdata_App_Util::formatTimestamp($value); 0221 } else { 0222 unset($this->_params['updated-min']); 0223 } 0224 return $this; 0225 } 0226 0227 /** 0228 * @param string $value 0229 * @return Zend_Gdata_Query Provides a fluent interface 0230 */ 0231 public function setPublishedMax($value) 0232 { 0233 if ($value !== null) { 0234 $this->_params['published-max'] = Zend_Gdata_App_Util::formatTimestamp($value); 0235 } else { 0236 unset($this->_params['published-max']); 0237 } 0238 return $this; 0239 } 0240 0241 /** 0242 * @param string $value 0243 * @return Zend_Gdata_Query Provides a fluent interface 0244 */ 0245 public function setPublishedMin($value) 0246 { 0247 if ($value != null) { 0248 $this->_params['published-min'] = Zend_Gdata_App_Util::formatTimestamp($value); 0249 } else { 0250 unset($this->_params['published-min']); 0251 } 0252 return $this; 0253 } 0254 0255 /** 0256 * @param string $value 0257 * @return Zend_Gdata_Query Provides a fluent interface 0258 */ 0259 public function setAuthor($value) 0260 { 0261 if ($value != null) { 0262 $this->_params['author'] = $value; 0263 } else { 0264 unset($this->_params['author']); 0265 } 0266 return $this; 0267 } 0268 0269 /** 0270 * @return string rss or atom 0271 */ 0272 public function getAlt() 0273 { 0274 if (array_key_exists('alt', $this->_params)) { 0275 return $this->_params['alt']; 0276 } else { 0277 return null; 0278 } 0279 } 0280 0281 /** 0282 * @return int maxResults 0283 */ 0284 public function getMaxResults() 0285 { 0286 if (array_key_exists('max-results', $this->_params)) { 0287 return intval($this->_params['max-results']); 0288 } else { 0289 return null; 0290 } 0291 } 0292 0293 /** 0294 * @return string query 0295 */ 0296 public function getQuery() 0297 { 0298 if (array_key_exists('q', $this->_params)) { 0299 return $this->_params['q']; 0300 } else { 0301 return null; 0302 } 0303 } 0304 0305 /** 0306 * @return int startIndex 0307 */ 0308 public function getStartIndex() 0309 { 0310 if (array_key_exists('start-index', $this->_params)) { 0311 return intval($this->_params['start-index']); 0312 } else { 0313 return null; 0314 } 0315 } 0316 0317 /** 0318 * @return string updatedMax 0319 */ 0320 public function getUpdatedMax() 0321 { 0322 if (array_key_exists('updated-max', $this->_params)) { 0323 return $this->_params['updated-max']; 0324 } else { 0325 return null; 0326 } 0327 } 0328 0329 /** 0330 * @return string updatedMin 0331 */ 0332 public function getUpdatedMin() 0333 { 0334 if (array_key_exists('updated-min', $this->_params)) { 0335 return $this->_params['updated-min']; 0336 } else { 0337 return null; 0338 } 0339 } 0340 0341 /** 0342 * @return string publishedMax 0343 */ 0344 public function getPublishedMax() 0345 { 0346 if (array_key_exists('published-max', $this->_params)) { 0347 return $this->_params['published-max']; 0348 } else { 0349 return null; 0350 } 0351 } 0352 0353 /** 0354 * @return string publishedMin 0355 */ 0356 public function getPublishedMin() 0357 { 0358 if (array_key_exists('published-min', $this->_params)) { 0359 return $this->_params['published-min']; 0360 } else { 0361 return null; 0362 } 0363 } 0364 0365 /** 0366 * @return string author 0367 */ 0368 public function getAuthor() 0369 { 0370 if (array_key_exists('author', $this->_params)) { 0371 return $this->_params['author']; 0372 } else { 0373 return null; 0374 } 0375 } 0376 0377 /** 0378 * @param string $value 0379 * @return Zend_Gdata_Query Provides a fluent interface 0380 */ 0381 public function setCategory($value) 0382 { 0383 $this->_category = $value; 0384 return $this; 0385 } 0386 0387 /* 0388 * @return string id 0389 */ 0390 public function getCategory() 0391 { 0392 return $this->_category; 0393 } 0394 0395 0396 public function __get($name) 0397 { 0398 $method = 'get'.ucfirst($name); 0399 if (method_exists($this, $method)) { 0400 return call_user_func(array(&$this, $method)); 0401 } else { 0402 // require_once 'Zend/Gdata/App/Exception.php'; 0403 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist'); 0404 } 0405 } 0406 0407 public function __set($name, $val) 0408 { 0409 $method = 'set'.ucfirst($name); 0410 if (method_exists($this, $method)) { 0411 return call_user_func(array(&$this, $method), $val); 0412 } else { 0413 // require_once 'Zend/Gdata/App/Exception.php'; 0414 throw new Zend_Gdata_App_Exception('Property ' . $name . ' does not exist'); 0415 } 0416 } 0417 0418 }