2
0

DocumentQuery.php 7.5 KB

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