Query.php 5.7 KB

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