DocumentQuery.php 7.5 KB

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