PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/DevApp/library/Zend/Gdata/YouTube/VideoQuery.php

http://firephp.googlecode.com/
PHP | 296 lines | 177 code | 19 blank | 100 comment | 32 complexity | d05a5485f5b1df5e2f182d3ad883f3db MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  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. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * Zend_Gdata_YouTube
  22. */
  23. require_once('Zend/Gdata/YouTube.php');
  24. /**
  25. * Zend_Gdata_Query
  26. */
  27. require_once('Zend/Gdata/Query.php');
  28. /**
  29. * Assists in constructing queries for YouTube videos
  30. *
  31. * @link http://code.google.com/apis/youtube/
  32. *
  33. * @category Zend
  34. * @package Zend_Gdata
  35. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Gdata_YouTube_VideoQuery extends Zend_Gdata_Query
  39. {
  40. /**
  41. * Create Gdata_YouTube_VideoQuery object
  42. */
  43. public function __construct($url = null)
  44. {
  45. parent::__construct($url);
  46. }
  47. /**
  48. * Sets the type of feed this query should be used to search
  49. *
  50. * @param string $feedType The type of feed
  51. * @param string $videoId The ID of the video associated with this query
  52. * @param string $entry The ID of the entry associated with this query
  53. */
  54. public function setFeedType($feedType, $videoId = null, $entry = null)
  55. {
  56. switch ($feedType) {
  57. case 'top rated':
  58. $this->_url = Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI;
  59. break;
  60. case 'most viewed':
  61. $this->_url = Zend_Gdata_YouTube::STANDARD_MOST_VIEWED_URI;
  62. break;
  63. case 'recently featured':
  64. $this->_url = Zend_Gdata_YouTube::STANDARD_RECENTLY_FEATURED_URI;
  65. break;
  66. case 'mobile':
  67. $this->_url = Zend_Gdata_YouTube::STANDARD_WATCH_ON_MOBILE_URI;
  68. break;
  69. case 'related':
  70. if ($videoId === null) {
  71. require_once 'Zend/Gdata/App/Exception.php';
  72. throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
  73. } else {
  74. $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . '/related';
  75. }
  76. break;
  77. case 'responses':
  78. if ($videoId === null) {
  79. require_once 'Zend/Gdata/App/Exception.php';
  80. throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
  81. } else {
  82. $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 'responses';
  83. }
  84. break;
  85. case 'comments':
  86. if ($videoId === null) {
  87. require_once 'Zend/Gdata/App/Exception.php';
  88. throw new Zend_Gdata_App_Exception('Video ID must be set for feed of type: ' . $feedType);
  89. } else {
  90. $this->_url = Zend_Gdata_YouTube::VIDEO_URI . '/' . $videoId . 'comments';
  91. if ($entry !== null) {
  92. $this->_url .= '/' . $entry;
  93. }
  94. }
  95. break;
  96. default:
  97. require_once 'Zend/Gdata/App/Exception.php';
  98. throw new Zend_Gdata_App_Exception('Unknown feed type');
  99. break;
  100. }
  101. }
  102. /**
  103. * Sets the time period over which this query should apply
  104. *
  105. * @param string $value
  106. * @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
  107. */
  108. public function setTime($value = null)
  109. {
  110. switch ($value) {
  111. case 'today':
  112. $this->_params['time'] = 'today';
  113. break;
  114. case 'this_week':
  115. $this->_params['time'] = 'this_week';
  116. break;
  117. case 'this_month':
  118. $this->_params['time'] = 'this_month';
  119. break;
  120. case 'all_time':
  121. $this->_params['time'] = 'all_time';
  122. break;
  123. case null:
  124. unset($this->_params['time']);
  125. default:
  126. require_once 'Zend/Gdata/App/Exception.php';
  127. throw new Zend_Gdata_App_Exception('Unknown time value');
  128. break;
  129. }
  130. return $this;
  131. }
  132. /**
  133. * Sets the formatted video query (vq) URL param value
  134. *
  135. * @param string $value
  136. * @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
  137. */
  138. public function setVideoQuery($value = null)
  139. {
  140. if ($value != null) {
  141. $this->_params['vq'] = $value;
  142. } else {
  143. unset($this->_params['vq']);
  144. }
  145. return $this;
  146. }
  147. /**
  148. * Sets the param to return videos of a specific format
  149. *
  150. * @param string $value
  151. * @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
  152. */
  153. public function setFormat($value = null)
  154. {
  155. if ($value != null) {
  156. $this->_params['format'] = $value;
  157. } else {
  158. unset($this->_params['format']);
  159. }
  160. return $this;
  161. }
  162. /**
  163. * Sets whether or not to include racy videos in the search results
  164. *
  165. * @param string $value
  166. * @return Zend_Gdata_YouTube_VideoQuery Provides a fluent interface
  167. */
  168. public function setRacy($value = null)
  169. {
  170. switch ($value) {
  171. case 'include':
  172. $this->_params['racy'] = $value;
  173. break;
  174. case 'exclude':
  175. $this->_params['racy'] = $value;
  176. break;
  177. case null:
  178. unset($this->_params['racy']);
  179. break;
  180. }
  181. return $this;
  182. }
  183. /**
  184. * @param string $value
  185. * @return Zend_Gdata_YouTube_Query Provides a fluent interface
  186. */
  187. public function setOrderBy($value)
  188. {
  189. if ($value != null) {
  190. $this->_params['orderby'] = $value;
  191. } else {
  192. unset($this->_params['orderby']);
  193. }
  194. return $this;
  195. }
  196. /**
  197. * Whether or not to include racy videos in the search results
  198. *
  199. * @return string racy
  200. */
  201. public function getRacy()
  202. {
  203. if (array_key_exists('racy', $this->_params)) {
  204. return $this->_params['racy'];
  205. } else {
  206. return null;
  207. }
  208. }
  209. /**
  210. * The format used for videos
  211. *
  212. * @return string format
  213. */
  214. public function getFormat()
  215. {
  216. if (array_key_exists('format', $this->_params)) {
  217. return $this->_params['format'];
  218. } else {
  219. return null;
  220. }
  221. }
  222. /**
  223. * The video query
  224. *
  225. * @return string video query
  226. */
  227. public function getVideoQuery()
  228. {
  229. if (array_key_exists('vq', $this->_params)) {
  230. return $this->_params['vq'];
  231. } else {
  232. return null;
  233. }
  234. }
  235. /**
  236. * The time
  237. *
  238. * @return string time
  239. */
  240. public function getTime()
  241. {
  242. if (array_key_exists('time', $this->_params)) {
  243. return $this->_params['time'];
  244. } else {
  245. return null;
  246. }
  247. }
  248. /**
  249. * @return string orderby
  250. */
  251. public function getOrderBy()
  252. {
  253. if (array_key_exists('orderby', $this->_params)) {
  254. return $this->_params['orderby'];
  255. } else {
  256. return null;
  257. }
  258. }
  259. /**
  260. * Returns the generated full query URL
  261. *
  262. * @return string The URL
  263. */
  264. public function getQueryUrl()
  265. {
  266. if (isset($this->_url)) {
  267. $url = $this->_url;
  268. } else {
  269. $url = Zend_Gdata_YouTube::VIDEO_URI;
  270. }
  271. if ($this->getCategory() !== null) {
  272. $url .= '/-/' . $this->getCategory();
  273. }
  274. $url = $url . $this->getQueryString();
  275. return $url;
  276. }
  277. }