8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
18 * @subpackage Spreadsheets
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id: DocumentQuery.php 16971 2009-07-22 18:05:45Z mikaelkael $
27 require_once('Zend/Gdata/App/Util.php');
32 require_once('Zend/Gdata/Query.php');
35 * Assists in constructing queries for Google Spreadsheets documents
37 * @link http://code.google.com/apis/gdata/spreadsheets/
41 * @subpackage Spreadsheets
42 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
43 * @license http://framework.zend.com/license/new-bsd New BSD License
45 class Zend_Gdata_Spreadsheets_DocumentQuery
extends Zend_Gdata_Query
48 const SPREADSHEETS_FEED_URI
= 'http://spreadsheets.google.com/feeds';
50 protected $_defaultFeedUri = self
::SPREADSHEETS_FEED_URI
;
51 protected $_documentType;
52 protected $_visibility = 'private';
53 protected $_projection = 'full';
54 protected $_spreadsheetKey = null;
55 protected $_worksheetId = null;
58 * Constructs a new Zend_Gdata_Spreadsheets_DocumentQuery object.
60 public function __construct()
62 parent
::__construct();
66 * Sets the spreadsheet key for this query.
67 * @param string $value
68 * @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
70 public function setSpreadsheetKey($value)
72 $this->_spreadsheetKey
= $value;
77 * Gets the spreadsheet key for this query.
78 * @return string spreadsheet key
80 public function getSpreadsheetKey()
82 return $this->_spreadsheetKey
;
86 * Sets the worksheet id for this query.
87 * @param string $value
88 * @return Zend_Gdata_Spreadsheets_CellQuery Provides a fluent interface
90 public function setWorksheetId($value)
92 $this->_worksheetId
= $value;
97 * Gets the worksheet id for this query.
98 * @return string worksheet id
100 public function getWorksheetId()
102 return $this->_worksheetId
;
106 * Sets the document type for this query.
107 * @param string $value spreadsheets or worksheets
108 * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
110 public function setDocumentType($value)
112 $this->_documentType
= $value;
117 * Gets the document type for this query.
118 * @return string document type
120 public function getDocumentType()
122 return $this->_documentType
;
126 * Sets the projection for this query.
127 * @param string $value
128 * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
130 public function setProjection($value)
132 $this->_projection
= $value;
137 * Sets the visibility for this query.
138 * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
140 public function setVisibility($value)
142 $this->_visibility
= $value;
147 * Gets the projection for this query.
148 * @return string projection
150 public function getProjection()
152 return $this->_projection
;
156 * Gets the visibility for this query.
157 * @return string visibility
159 public function getVisibility()
161 return $this->_visibility
;
165 * Sets the title attribute for this query.
166 * @param string $value
167 * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
169 public function setTitle($value)
171 if ($value != null) {
172 $this->_params
['title'] = $value;
174 unset($this->_params
['title']);
180 * Sets the title-exact attribute for this query.
181 * @param string $value
182 * @return Zend_Gdata_Spreadsheets_DocumentQuery Provides a fluent interface
184 public function setTitleExact($value)
186 if ($value != null) {
187 $this->_params
['title-exact'] = $value;
189 unset($this->_params
['title-exact']);
195 * Gets the title attribute for this query.
196 * @return string title
198 public function getTitle()
200 if (array_key_exists('title', $this->_params
)) {
201 return $this->_params
['title'];
208 * Gets the title-exact attribute for this query.
209 * @return string title-exact
211 public function getTitleExact()
213 if (array_key_exists('title-exact', $this->_params
)) {
214 return $this->_params
['title-exact'];
220 private function appendVisibilityProjection()
224 if ($this->_visibility
!= null) {
225 $uri .= '/'.$this->_visibility
;
227 require_once 'Zend/Gdata/App/Exception.php';
228 throw new Zend_Gdata_App_Exception('A visibility must be provided for document queries.');
231 if ($this->_projection
!= null) {
232 $uri .= '/'.$this->_projection
;
234 require_once 'Zend/Gdata/App/Exception.php';
235 throw new Zend_Gdata_App_Exception('A projection must be provided for document queries.');
243 * Gets the full query URL for this query.
246 public function getQueryUrl()
248 $uri = $this->_defaultFeedUri
;
250 if ($this->_documentType
!= null) {
251 $uri .= '/'.$this->_documentType
;
253 require_once 'Zend/Gdata/App/Exception.php';
254 throw new Zend_Gdata_App_Exception('A document type must be provided for document queries.');
257 if ($this->_documentType
== 'spreadsheets') {
258 $uri .= $this->appendVisibilityProjection();
259 if ($this->_spreadsheetKey
!= null) {
260 $uri .= '/'.$this->_spreadsheetKey
;
262 } else if ($this->_documentType
== 'worksheets') {
263 if ($this->_spreadsheetKey
!= null) {
264 $uri .= '/'.$this->_spreadsheetKey
;
266 require_once 'Zend/Gdata/App/Exception.php';
267 throw new Zend_Gdata_App_Exception('A spreadsheet key must be provided for worksheet document queries.');
269 $uri .= $this->appendVisibilityProjection();
270 if ($this->_worksheetId
!= null) {
271 $uri .= '/'.$this->_worksheetId
;
275 $uri .= $this->getQueryString();
280 * Gets the attribute query string for this query.
281 * @return string query string
283 public function getQueryString()
285 return parent
::getQueryString();