/libraries/Zend/GData/Spreadsheets/CellQuery.php

https://github.com/kiranatama/sagalaya · PHP · 404 lines · 203 code · 36 blank · 165 comment · 49 complexity · d7ce6884a4ecda7663b41ce5b22f1df5 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Spreadsheets
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. namespace Zend\GData\Spreadsheets;
  22. use Zend\GData\App;
  23. /**
  24. * Assists in constructing queries for Google Spreadsheets cells
  25. *
  26. * @link http://code.google.com/apis/gdata/spreadsheets/
  27. *
  28. * @category Zend
  29. * @package Zend_Gdata
  30. * @subpackage Spreadsheets
  31. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class CellQuery extends \Zend\GData\Query
  35. {
  36. const SPREADSHEETS_CELL_FEED_URI = 'https://spreadsheets.google.com/feeds/cells';
  37. protected $_defaultFeedUri = self::SPREADSHEETS_CELL_FEED_URI;
  38. protected $_visibility = 'private';
  39. protected $_projection = 'full';
  40. protected $_spreadsheetKey = null;
  41. protected $_worksheetId = 'default';
  42. protected $_cellId = null;
  43. /**
  44. * Constructs a new Zend_Gdata_Spreadsheets_CellQuery object.
  45. *
  46. * @param string $url Base URL to use for queries
  47. */
  48. public function __construct($url = null)
  49. {
  50. parent::__construct($url);
  51. }
  52. /**
  53. * Sets the spreadsheet key for this query.
  54. *
  55. * @param string $value
  56. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  57. */
  58. public function setSpreadsheetKey($value)
  59. {
  60. $this->_spreadsheetKey = $value;
  61. return $this;
  62. }
  63. /**
  64. * Gets the spreadsheet key for this query.
  65. *
  66. * @return string spreadsheet key
  67. */
  68. public function getSpreadsheetKey()
  69. {
  70. return $this->_spreadsheetKey;
  71. }
  72. /**
  73. * Sets the worksheet id for this query.
  74. *
  75. * @param string $value
  76. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  77. */
  78. public function setWorksheetId($value)
  79. {
  80. $this->_worksheetId = $value;
  81. return $this;
  82. }
  83. /**
  84. * Gets the worksheet id for this query.
  85. *
  86. * @return string worksheet id
  87. */
  88. public function getWorksheetId()
  89. {
  90. return $this->_worksheetId;
  91. }
  92. /**
  93. * Sets the cell id for this query.
  94. *
  95. * @param string $value
  96. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  97. */
  98. public function setCellId($value)
  99. {
  100. $this->_cellId = $value;
  101. return $this;
  102. }
  103. /**
  104. * Gets the cell id for this query.
  105. *
  106. * @return string cell id
  107. */
  108. public function getCellId()
  109. {
  110. return $this->_cellId;
  111. }
  112. /**
  113. * Sets the projection for this query.
  114. *
  115. * @param string $value
  116. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  117. */
  118. public function setProjection($value)
  119. {
  120. $this->_projection = $value;
  121. return $this;
  122. }
  123. /**
  124. * Sets the visibility for this query.
  125. *
  126. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  127. */
  128. public function setVisibility($value)
  129. {
  130. $this->_visibility = $value;
  131. return $this;
  132. }
  133. /**
  134. * Gets the projection for this query.
  135. *
  136. * @return string projection
  137. */
  138. public function getProjection()
  139. {
  140. return $this->_projection;
  141. }
  142. /**
  143. * Gets the visibility for this query.
  144. *
  145. * @return string visibility
  146. */
  147. public function getVisibility()
  148. {
  149. return $this->_visibility;
  150. }
  151. /**
  152. * Sets the min-row attribute for this query.
  153. *
  154. * @param string $value
  155. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  156. */
  157. public function setMinRow($value)
  158. {
  159. if ($value != null) {
  160. $this->_params['min-row'] = $value;
  161. } else {
  162. unset($this->_params['min-row']);
  163. }
  164. return $this;
  165. }
  166. /**
  167. * Gets the min-row attribute for this query.
  168. *
  169. * @return string min-row
  170. */
  171. public function getMinRow()
  172. {
  173. if (array_key_exists('min-row', $this->_params)) {
  174. return $this->_params['min-row'];
  175. } else {
  176. return null;
  177. }
  178. }
  179. /**
  180. * Sets the max-row attribute for this query.
  181. *
  182. * @param string $value
  183. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  184. */
  185. public function setMaxRow($value)
  186. {
  187. if ($value != null) {
  188. $this->_params['max-row'] = $value;
  189. } else {
  190. unset($this->_params['max-row']);
  191. }
  192. return $this;
  193. }
  194. /**
  195. * Gets the max-row attribute for this query.
  196. *
  197. * @return string max-row
  198. */
  199. public function getMaxRow()
  200. {
  201. if (array_key_exists('max-row', $this->_params)) {
  202. return $this->_params['max-row'];
  203. } else {
  204. return null;
  205. }
  206. }
  207. /**
  208. * Sets the min-col attribute for this query.
  209. *
  210. * @param string $value
  211. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  212. */
  213. public function setMinCol($value)
  214. {
  215. if ($value != null) {
  216. $this->_params['min-col'] = $value;
  217. } else {
  218. unset($this->_params['min-col']);
  219. }
  220. return $this;
  221. }
  222. /**
  223. * Gets the min-col attribute for this query.
  224. *
  225. * @return string min-col
  226. */
  227. public function getMinCol()
  228. {
  229. if (array_key_exists('min-col', $this->_params)) {
  230. return $this->_params['min-col'];
  231. } else {
  232. return null;
  233. }
  234. }
  235. /**
  236. * Sets the max-col attribute for this query.
  237. *
  238. * @param string $value
  239. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  240. */
  241. public function setMaxCol($value)
  242. {
  243. if ($value != null) {
  244. $this->_params['max-col'] = $value;
  245. } else {
  246. unset($this->_params['max-col']);
  247. }
  248. return $this;
  249. }
  250. /**
  251. * Gets the max-col attribute for this query.
  252. *
  253. * @return string max-col
  254. */
  255. public function getMaxCol()
  256. {
  257. if (array_key_exists('max-col', $this->_params)) {
  258. return $this->_params['max-col'];
  259. } else {
  260. return null;
  261. }
  262. }
  263. /**
  264. * Sets the range attribute for this query.
  265. *
  266. * @param string $value
  267. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  268. */
  269. public function setRange($value)
  270. {
  271. if ($value != null) {
  272. $this->_params['range'] = $value;
  273. } else {
  274. unset($this->_params['range']);
  275. }
  276. return $this;
  277. }
  278. /**
  279. * Gets the range attribute for this query.
  280. *
  281. * @return string range
  282. */
  283. public function getRange()
  284. {
  285. if (array_key_exists('range', $this->_params)) {
  286. return $this->_params['range'];
  287. } else {
  288. return null;
  289. }
  290. }
  291. /**
  292. * Sets the return-empty attribute for this query.
  293. *
  294. * @param mixed $value String or bool value for whether to return empty cells
  295. * @return \Zend\GData\Spreadsheets\CellQuery Provides a fluent interface
  296. */
  297. public function setReturnEmpty($value)
  298. {
  299. if (is_bool($value)) {
  300. $this->_params['return-empty'] = ($value?'true':'false');
  301. } else if ($value != null) {
  302. $this->_params['return-empty'] = $value;
  303. } else {
  304. unset($this->_params['return-empty']);
  305. }
  306. return $this;
  307. }
  308. /**
  309. * Gets the return-empty attribute for this query.
  310. *
  311. * @return string return-empty
  312. */
  313. public function getReturnEmpty()
  314. {
  315. if (array_key_exists('return-empty', $this->_params)) {
  316. return $this->_params['return-empty'];
  317. } else {
  318. return null;
  319. }
  320. }
  321. /**
  322. * Gets the full query URL for this query.
  323. *
  324. * @return string url
  325. */
  326. public function getQueryUrl()
  327. {
  328. if ($this->_url == null) {
  329. $uri = $this->_defaultFeedUri;
  330. if ($this->_spreadsheetKey != null) {
  331. $uri .= '/'.$this->_spreadsheetKey;
  332. } else {
  333. throw new App\Exception('A spreadsheet key must be provided for cell queries.');
  334. }
  335. if ($this->_worksheetId != null) {
  336. $uri .= '/'.$this->_worksheetId;
  337. } else {
  338. throw new App\Exception('A worksheet id must be provided for cell queries.');
  339. }
  340. if ($this->_visibility != null) {
  341. $uri .= '/'.$this->_visibility;
  342. } else {
  343. throw new App\Exception('A visibility must be provided for cell queries.');
  344. }
  345. if ($this->_projection != null) {
  346. $uri .= '/'.$this->_projection;
  347. } else {
  348. throw new App\Exception('A projection must be provided for cell queries.');
  349. }
  350. if ($this->_cellId != null) {
  351. $uri .= '/'.$this->_cellId;
  352. }
  353. } else {
  354. $uri = $this->_url;
  355. }
  356. $uri .= $this->getQueryString();
  357. return $uri;
  358. }
  359. /**
  360. * Gets the attribute query string for this query.
  361. *
  362. * @return string query string
  363. */
  364. public function getQueryString()
  365. {
  366. return parent::getQueryString();
  367. }
  368. }