2
0

Query.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 Docs
  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_Query
  24. */
  25. require_once('Zend/Gdata/Query.php');
  26. /**
  27. * Assists in constructing queries for Google Document List documents
  28. *
  29. * @link http://code.google.com/apis/gdata/spreadsheets/
  30. *
  31. * @category Zend
  32. * @package Zend_Gdata
  33. * @subpackage Docs
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Gdata_Docs_Query extends Zend_Gdata_Query
  38. {
  39. /**
  40. * The base URL for retrieving a document list
  41. *
  42. * @var string
  43. */
  44. const DOCUMENTS_LIST_FEED_URI = 'https://docs.google.com/feeds/documents';
  45. /**
  46. * The generic base URL used by some inherited methods
  47. *
  48. * @var string
  49. */
  50. protected $_defaultFeedUri = self::DOCUMENTS_LIST_FEED_URI;
  51. /**
  52. * The visibility to be used when querying for the feed. A request for a
  53. * feed with private visbility requires the user to be authenricated.
  54. * Private is the only avilable visibility for the documents list.
  55. *
  56. * @var string
  57. */
  58. protected $_visibility = 'private';
  59. /**
  60. * The projection determines how much detail should be given in the
  61. * result of the query. Full is the only valid projection for the
  62. * documents list.
  63. *
  64. * @var string
  65. */
  66. protected $_projection = 'full';
  67. /**
  68. * Constructs a new instance of a Zend_Gdata_Docs_Query object.
  69. */
  70. public function __construct()
  71. {
  72. parent::__construct();
  73. }
  74. /**
  75. * Sets the projection for this query. Common values for projection
  76. * include 'full'.
  77. *
  78. * @param string $value
  79. * @return Zend_Gdata_Docs_Query Provides a fluent interface
  80. */
  81. public function setProjection($value)
  82. {
  83. $this->_projection = $value;
  84. return $this;
  85. }
  86. /**
  87. * Sets the visibility for this query. Common values for visibility
  88. * include 'private'.
  89. *
  90. * @return Zend_Gdata_Docs_Query Provides a fluent interface
  91. */
  92. public function setVisibility($value)
  93. {
  94. $this->_visibility = $value;
  95. return $this;
  96. }
  97. /**
  98. * Gets the projection for this query.
  99. *
  100. * @return string projection
  101. */
  102. public function getProjection()
  103. {
  104. return $this->_projection;
  105. }
  106. /**
  107. * Gets the visibility for this query.
  108. *
  109. * @return string visibility
  110. */
  111. public function getVisibility()
  112. {
  113. return $this->_visibility;
  114. }
  115. /**
  116. * Sets the title attribute for this query. The title parameter is used
  117. * to restrict the results to documents whose titles either contain or
  118. * completely match the title.
  119. *
  120. * @param string $value
  121. * @return Zend_Gdata_Docs_Query Provides a fluent interface
  122. */
  123. public function setTitle($value)
  124. {
  125. if ($value !== null) {
  126. $this->_params['title'] = $value;
  127. } else {
  128. unset($this->_params['title']);
  129. }
  130. return $this;
  131. }
  132. /**
  133. * Gets the title attribute for this query.
  134. *
  135. * @return string title
  136. */
  137. public function getTitle()
  138. {
  139. if (array_key_exists('title', $this->_params)) {
  140. return $this->_params['title'];
  141. } else {
  142. return null;
  143. }
  144. }
  145. /**
  146. * Sets the title-exact attribute for this query.
  147. * If title-exact is set to true, the title query parameter will be used
  148. * in an exact match. Only documents with a title identical to the
  149. * title parameter will be returned.
  150. *
  151. * @param boolean $value Use either true or false
  152. * @return Zend_Gdata_Docs_Query Provides a fluent interface
  153. */
  154. public function setTitleExact($value)
  155. {
  156. if ($value) {
  157. $this->_params['title-exact'] = $value;
  158. } else {
  159. unset($this->_params['title-exact']);
  160. }
  161. return $this;
  162. }
  163. /**
  164. * Gets the title-exact attribute for this query.
  165. *
  166. * @return string title-exact
  167. */
  168. public function getTitleExact()
  169. {
  170. if (array_key_exists('title-exact', $this->_params)) {
  171. return $this->_params['title-exact'];
  172. } else {
  173. return false;
  174. }
  175. }
  176. /**
  177. * Gets the full query URL for this query.
  178. *
  179. * @return string url
  180. */
  181. public function getQueryUrl()
  182. {
  183. $uri = $this->_defaultFeedUri;
  184. if ($this->_visibility !== null) {
  185. $uri .= '/' . $this->_visibility;
  186. } else {
  187. require_once 'Zend/Gdata/App/Exception.php';
  188. throw new Zend_Gdata_App_Exception(
  189. 'A visibility must be provided for cell queries.');
  190. }
  191. if ($this->_projection !== null) {
  192. $uri .= '/' . $this->_projection;
  193. } else {
  194. require_once 'Zend/Gdata/App/Exception.php';
  195. throw new Zend_Gdata_App_Exception(
  196. 'A projection must be provided for cell queries.');
  197. }
  198. $uri .= $this->getQueryString();
  199. return $uri;
  200. }
  201. }