PageRenderTime 29ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/Zend/Gdata/Spreadsheets/DocumentQuery.php

http://firephp.googlecode.com/
PHP | 285 lines | 146 code | 32 blank | 107 comment | 31 complexity | c5bfadc2cd79e4d9ded3266bdbf77318 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  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. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * Zend_Gdata_App_util
  22. */
  23. require_once('Zend/Gdata/App/Util.php');
  24. /**
  25. * Zend_Gdata_Query
  26. */
  27. require_once('Zend/Gdata/Query.php');
  28. /**
  29. * Assists in constructing queries for Google Spreadsheets documents
  30. *
  31. * @link http://code.google.com/apis/gdata/spreadsheets/
  32. *
  33. * @category Zend
  34. * @package Zend_Gdata
  35. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Gdata_Spreadsheets_DocumentQuery extends Zend_Gdata_Query
  39. {
  40. const SPREADSHEETS_FEED_URI = 'http://spreadsheets.google.com/feeds';
  41. protected $_defaultFeedUri = self::SPREADSHEETS_FEED_URI;
  42. protected $_documentType;
  43. protected $_visibility = 'private';
  44. protected $_projection = 'full';
  45. protected $_spreadsheetKey = null;
  46. protected $_worksheetId = null;
  47. /**
  48. * Constructs a new Zend_Gdata_Spreadsheets_DocumentQuery object.
  49. */
  50. public function __construct()
  51. {
  52. parent::__construct();
  53. }
  54. /**
  55. * Sets the spreadsheet key for this query.
  56. * @param string $value
  57. * @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
  58. */
  59. public function setSpreadsheetKey($value)
  60. {
  61. $this->_spreadsheetKey = $value;
  62. return $this;
  63. }
  64. /**
  65. * Gets the spreadsheet key for this query.
  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. * @param string $value
  75. * @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
  76. */
  77. public function setWorksheetId($value)
  78. {
  79. $this->_worksheetId = $value;
  80. return $this;
  81. }
  82. /**
  83. * Gets the worksheet id for this query.
  84. * @return string worksheet id
  85. */
  86. public function getWorksheetId()
  87. {
  88. return $this->_worksheetId;
  89. }
  90. /**
  91. * Sets the document type for this query.
  92. * @param string $value spreadsheets or worksheets
  93. * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
  94. */
  95. public function setDocumentType($value)
  96. {
  97. $this->_documentType = $value;
  98. return $this;
  99. }
  100. /**
  101. * Gets the document type for this query.
  102. * @return string document type
  103. */
  104. public function getDocumentType()
  105. {
  106. return $this->_documentType;
  107. }
  108. /**
  109. * Sets the projection for this query.
  110. * @param string $value
  111. * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
  112. */
  113. public function setProjection($value)
  114. {
  115. $this->_projection = $value;
  116. return $this;
  117. }
  118. /**
  119. * Sets the visibility for this query.
  120. * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
  121. */
  122. public function setVisibility($value)
  123. {
  124. $this->_visibility = $value;
  125. return $this;
  126. }
  127. /**
  128. * Gets the projection for this query.
  129. * @return string projection
  130. */
  131. public function getProjection()
  132. {
  133. return $this->_projection;
  134. }
  135. /**
  136. * Gets the visibility for this query.
  137. * @return string visibility
  138. */
  139. public function getVisibility()
  140. {
  141. return $this->_visibility;
  142. }
  143. /**
  144. * Sets the title attribute for this query.
  145. * @param string $value
  146. * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
  147. */
  148. public function setTitle($value)
  149. {
  150. if ($value != null) {
  151. $this->_params['title'] = $value;
  152. } else {
  153. unset($this->_params['title']);
  154. }
  155. return $this;
  156. }
  157. /**
  158. * Sets the title-exact attribute for this query.
  159. * @param string $value
  160. * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
  161. */
  162. public function setTitleExact($value)
  163. {
  164. if ($value != null) {
  165. $this->_params['title-exact'] = $value;
  166. } else {
  167. unset($this->_params['title-exact']);
  168. }
  169. return $this;
  170. }
  171. /**
  172. * Gets the title attribute for this query.
  173. * @return string title
  174. */
  175. public function getTitle()
  176. {
  177. if (array_key_exists('title', $this->_params)) {
  178. return $this->_params['title'];
  179. } else {
  180. return null;
  181. }
  182. }
  183. /**
  184. * Gets the title-exact attribute for this query.
  185. * @return string title-exact
  186. */
  187. public function getTitleExact()
  188. {
  189. if (array_key_exists('title-exact', $this->_params)) {
  190. return $this->_params['title-exact'];
  191. } else {
  192. return null;
  193. }
  194. }
  195. private function appendVisibilityProjection()
  196. {
  197. $uri = '';
  198. if ($this->_visibility != null) {
  199. $uri .= '/'.$this->_visibility;
  200. } else {
  201. require_once 'Zend/Gdata/App/Exception.php';
  202. throw new Zend_Gdata_App_Exception('A visibility must be provided for document queries.');
  203. }
  204. if ($this->_projection != null) {
  205. $uri .= '/'.$this->_projection;
  206. } else {
  207. require_once 'Zend/Gdata/App/Exception.php';
  208. throw new Zend_Gdata_App_Exception('A projection must be provided for document queries.');
  209. }
  210. return $uri;
  211. }
  212. /**
  213. * Gets the full query URL for this query.
  214. * @return string url
  215. */
  216. public function getQueryUrl()
  217. {
  218. $uri = $this->_defaultFeedUri;
  219. if ($this->_documentType != null) {
  220. $uri .= '/'.$this->_documentType;
  221. } else {
  222. require_once 'Zend/Gdata/App/Exception.php';
  223. throw new Zend_Gdata_App_Exception('A document type must be provided for document queries.');
  224. }
  225. if ($this->_documentType == 'spreadsheets') {
  226. $uri .= $this->appendVisibilityProjection();
  227. if ($this->_spreadsheetKey != null) {
  228. $uri .= '/'.$this->_spreadsheetKey;
  229. }
  230. } else if ($this->_documentType == 'worksheets') {
  231. if ($this->_spreadsheetKey != null) {
  232. $uri .= '/'.$this->_spreadsheetKey;
  233. } else {
  234. require_once 'Zend/Gdata/App/Exception.php';
  235. throw new Zend_Gdata_App_Exception('A spreadsheet key must be provided for worksheet document queries.');
  236. }
  237. $uri .= $this->appendVisibilityProjection();
  238. if ($this->_worksheetId != null) {
  239. $uri .= '/'.$this->_worksheetId;
  240. }
  241. }
  242. $uri .= $this->getQueryString();
  243. return $uri;
  244. }
  245. /**
  246. * Gets the attribute query string for this query.
  247. * @return string query string
  248. */
  249. public function getQueryString()
  250. {
  251. return parent::getQueryString();
  252. }
  253. }