/lib/Zend/Gdata/YouTube/SubscriptionEntry.php

https://bitbucket.org/tschrock52/ethodeshare · PHP · 446 lines · 193 code · 35 blank · 218 comment · 44 complexity · ae651e1b77107fd3db6eaa6887e5820a MD5 · raw file

  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 YouTube
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: SubscriptionEntry.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /**
  23. * @see Zend_Gdata_Entry
  24. */
  25. #require_once 'Zend/Gdata/Entry.php';
  26. /**
  27. * @see Zend_Gdata_Extension_FeedLink
  28. */
  29. #require_once 'Zend/Gdata/Extension/FeedLink.php';
  30. /**
  31. * @see Zend_Gdata_YouTube_Extension_Description
  32. */
  33. #require_once 'Zend/Gdata/YouTube/Extension/Description.php';
  34. /**
  35. * @see Zend_Gdata_YouTube_Extension_PlaylistTitle
  36. */
  37. #require_once 'Zend/Gdata/YouTube/Extension/PlaylistTitle.php';
  38. /**
  39. * @see Zend_Gdata_YouTube_Extension_PlaylistId
  40. */
  41. #require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
  42. /**
  43. * @see Zend_Gdata_Media_Extension_MediaThumbnail
  44. */
  45. #require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
  46. /**
  47. * @see Zend_Gdata_YouTube_Extension_Username
  48. */
  49. #require_once 'Zend/Gdata/YouTube/Extension/Username.php';
  50. /**
  51. * @see Zend_Gdata_YouTube_Extension_CountHint
  52. */
  53. #require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
  54. /**
  55. * @see Zend_Gdata_YouTube_Extension_QueryString
  56. */
  57. #require_once 'Zend/Gdata/YouTube/Extension/QueryString.php';
  58. /**
  59. * Represents the YouTube video subscription flavor of an Atom entry
  60. *
  61. * @category Zend
  62. * @package Zend_Gdata
  63. * @subpackage YouTube
  64. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  65. * @license http://framework.zend.com/license/new-bsd New BSD License
  66. */
  67. class Zend_Gdata_YouTube_SubscriptionEntry extends Zend_Gdata_Entry
  68. {
  69. protected $_entryClassName = 'Zend_Gdata_YouTube_SubscriptionEntry';
  70. /**
  71. * Nested feed links
  72. *
  73. * @var array
  74. */
  75. protected $_feedLink = array();
  76. /**
  77. * The username of this entry.
  78. *
  79. * @var Zend_Gdata_YouTube_Extension_Username
  80. */
  81. protected $_username = null;
  82. /**
  83. * The playlist title for this entry.
  84. *
  85. * This element is only used on subscriptions to playlists.
  86. *
  87. * @var Zend_Gdata_YouTube_Extension_PlaylistTitle
  88. */
  89. protected $_playlistTitle = null;
  90. /**
  91. * The playlist id for this entry.
  92. *
  93. * This element is only used on subscriptions to playlists.
  94. *
  95. * @var Zend_Gdata_YouTube_Extension_PlaylistId
  96. */
  97. protected $_playlistId = null;
  98. /**
  99. * The media:thumbnail element for this entry.
  100. *
  101. * This element is only used on subscriptions to playlists.
  102. *
  103. * @var Zend_Gdata_Media_Extension_MediaThumbnail
  104. */
  105. protected $_mediaThumbnail = null;
  106. /**
  107. * The countHint for this entry.
  108. *
  109. * @var Zend_Gdata_YouTube_Extension_CountHint
  110. */
  111. protected $_countHint = null;
  112. /**
  113. * The queryString for this entry.
  114. *
  115. * @var Zend_Gdata_YouTube_Extension_QueryString
  116. */
  117. protected $_queryString = null;
  118. /**
  119. * Creates a subscription entry, representing an individual subscription
  120. * in a list of subscriptions, usually associated with an individual user.
  121. *
  122. * @param DOMElement $element (optional) DOMElement from which this
  123. * object should be constructed.
  124. */
  125. public function __construct($element = null)
  126. {
  127. $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
  128. parent::__construct($element);
  129. }
  130. /**
  131. * Retrieves a DOMElement which corresponds to this element and all
  132. * child properties. This is used to build an entry back into a DOM
  133. * and eventually XML text for sending to the server upon updates, or
  134. * for application storage/persistence.
  135. *
  136. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  137. * @return DOMElement The DOMElement representing this element and all
  138. * child properties.
  139. */
  140. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  141. {
  142. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  143. if ($this->_countHint != null) {
  144. $element->appendChild($this->_countHint->getDOM($element->ownerDocument));
  145. }
  146. if ($this->_playlistTitle != null) {
  147. $element->appendChild($this->_playlistTitle->getDOM($element->ownerDocument));
  148. }
  149. if ($this->_playlistId != null) {
  150. $element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
  151. }
  152. if ($this->_mediaThumbnail != null) {
  153. $element->appendChild($this->_mediaThumbnail->getDOM($element->ownerDocument));
  154. }
  155. if ($this->_username != null) {
  156. $element->appendChild($this->_username->getDOM($element->ownerDocument));
  157. }
  158. if ($this->_queryString != null) {
  159. $element->appendChild($this->_queryString->getDOM($element->ownerDocument));
  160. }
  161. if ($this->_feedLink != null) {
  162. foreach ($this->_feedLink as $feedLink) {
  163. $element->appendChild($feedLink->getDOM($element->ownerDocument));
  164. }
  165. }
  166. return $element;
  167. }
  168. /**
  169. * Creates individual Entry objects of the appropriate type and
  170. * stores them in the $_entry array based upon DOM data.
  171. *
  172. * @param DOMNode $child The DOMNode to process
  173. */
  174. protected function takeChildFromDOM($child)
  175. {
  176. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  177. switch ($absoluteNodeName) {
  178. case $this->lookupNamespace('gd') . ':' . 'feedLink':
  179. $feedLink = new Zend_Gdata_Extension_FeedLink();
  180. $feedLink->transferFromDOM($child);
  181. $this->_feedLink[] = $feedLink;
  182. break;
  183. case $this->lookupNamespace('media') . ':' . 'thumbnail':
  184. $mediaThumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
  185. $mediaThumbnail->transferFromDOM($child);
  186. $this->_mediaThumbnail = $mediaThumbnail;
  187. break;
  188. case $this->lookupNamespace('yt') . ':' . 'countHint':
  189. $countHint = new Zend_Gdata_YouTube_Extension_CountHint();
  190. $countHint->transferFromDOM($child);
  191. $this->_countHint = $countHint;
  192. break;
  193. case $this->lookupNamespace('yt') . ':' . 'playlistTitle':
  194. $playlistTitle = new Zend_Gdata_YouTube_Extension_PlaylistTitle();
  195. $playlistTitle->transferFromDOM($child);
  196. $this->_playlistTitle = $playlistTitle;
  197. break;
  198. case $this->lookupNamespace('yt') . ':' . 'playlistId':
  199. $playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
  200. $playlistId->transferFromDOM($child);
  201. $this->_playlistId = $playlistId;
  202. break;
  203. case $this->lookupNamespace('yt') . ':' . 'queryString':
  204. $queryString = new Zend_Gdata_YouTube_Extension_QueryString();
  205. $queryString->transferFromDOM($child);
  206. $this->_queryString = $queryString;
  207. break;
  208. case $this->lookupNamespace('yt') . ':' . 'username':
  209. $username = new Zend_Gdata_YouTube_Extension_Username();
  210. $username->transferFromDOM($child);
  211. $this->_username = $username;
  212. break;
  213. default:
  214. parent::takeChildFromDOM($child);
  215. break;
  216. }
  217. }
  218. /**
  219. * Sets the array of embedded feeds related to the video
  220. *
  221. * @param array $feedLink The array of embedded feeds relating to the video
  222. * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
  223. */
  224. public function setFeedLink($feedLink = null)
  225. {
  226. $this->_feedLink = $feedLink;
  227. return $this;
  228. }
  229. /**
  230. * Get the feed link property for this entry.
  231. *
  232. * @see setFeedLink
  233. * @param string $rel (optional) The rel value of the link to be found.
  234. * If null, the array of links is returned.
  235. * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
  236. * object corresponding to the requested rel value is returned
  237. * if found, or null if the requested value is not found. If
  238. * $rel is null or not specified, an array of all available
  239. * feed links for this entry is returned, or null if no feed
  240. * links are set.
  241. */
  242. public function getFeedLink($rel = null)
  243. {
  244. if ($rel == null) {
  245. return $this->_feedLink;
  246. } else {
  247. foreach ($this->_feedLink as $feedLink) {
  248. if ($feedLink->rel == $rel) {
  249. return $feedLink;
  250. }
  251. }
  252. return null;
  253. }
  254. }
  255. /**
  256. * Get the playlist title for a 'playlist' subscription.
  257. *
  258. * @throws Zend_Gdata_App_VersionException
  259. * @return Zend_Gdata_YouTube_Extension_PlaylistId
  260. */
  261. public function getPlaylistId()
  262. {
  263. if (($this->getMajorProtocolVersion() == null) ||
  264. ($this->getMajorProtocolVersion() == 1)) {
  265. #require_once 'Zend/Gdata/App/VersionException.php';
  266. throw new Zend_Gdata_App_VersionException('The getPlaylistId ' .
  267. ' method is only supported as of version 2 of the YouTube ' .
  268. 'API.');
  269. } else {
  270. return $this->_playlistId;
  271. }
  272. }
  273. /**
  274. * Sets the yt:playlistId element for a new playlist subscription.
  275. *
  276. * @param Zend_Gdata_YouTube_Extension_PlaylistId $id The id of
  277. * the playlist to which to subscribe to.
  278. * @throws Zend_Gdata_App_VersionException
  279. * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
  280. */
  281. public function setPlaylistId($id = null)
  282. {
  283. if (($this->getMajorProtocolVersion() == null) ||
  284. ($this->getMajorProtocolVersion() == 1)) {
  285. #require_once 'Zend/Gdata/App/VersionException.php';
  286. throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
  287. ' method is only supported as of version 2 of the YouTube ' .
  288. 'API.');
  289. } else {
  290. $this->_playlistId = $id;
  291. return $this;
  292. }
  293. }
  294. /**
  295. * Get the queryString of the subscription
  296. *
  297. * @return Zend_Gdata_YouTube_Extension_QueryString
  298. */
  299. public function getQueryString()
  300. {
  301. return $this->_queryString;
  302. }
  303. /**
  304. * Sets the yt:queryString element for a new keyword subscription.
  305. *
  306. * @param Zend_Gdata_YouTube_Extension_QueryString $queryString The query
  307. * string to subscribe to
  308. * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
  309. */
  310. public function setQueryString($queryString = null)
  311. {
  312. $this->_queryString = $queryString;
  313. return $this;
  314. }
  315. /**
  316. * Get the playlist title for a 'playlist' subscription.
  317. *
  318. * @throws Zend_Gdata_App_VersionException
  319. * @return Zend_Gdata_YouTube_Extension_PlaylistTitle
  320. */
  321. public function getPlaylistTitle()
  322. {
  323. if (($this->getMajorProtocolVersion() == null) ||
  324. ($this->getMajorProtocolVersion() == 1)) {
  325. #require_once 'Zend/Gdata/App/VersionException.php';
  326. throw new Zend_Gdata_App_VersionException('The getPlaylistTitle ' .
  327. ' method is only supported as of version 2 of the YouTube ' .
  328. 'API.');
  329. } else {
  330. return $this->_playlistTitle;
  331. }
  332. }
  333. /**
  334. * Sets the yt:playlistTitle element for a new playlist subscription.
  335. *
  336. * @param Zend_Gdata_YouTube_Extension_PlaylistTitle $title The title of
  337. * the playlist to which to subscribe to.
  338. * @throws Zend_Gdata_App_VersionException
  339. * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
  340. */
  341. public function setPlaylistTitle($title = null)
  342. {
  343. if (($this->getMajorProtocolVersion() == null) ||
  344. ($this->getMajorProtocolVersion() == 1)) {
  345. #require_once 'Zend/Gdata/App/VersionException.php';
  346. throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
  347. ' method is only supported as of version 2 of the YouTube ' .
  348. 'API.');
  349. } else {
  350. $this->_playlistTitle = $title;
  351. return $this;
  352. }
  353. }
  354. /**
  355. * Get the counthint for a subscription.
  356. *
  357. * @throws Zend_Gdata_App_VersionException
  358. * @return Zend_Gdata_YouTube_Extension_CountHint
  359. */
  360. public function getCountHint()
  361. {
  362. if (($this->getMajorProtocolVersion() == null) ||
  363. ($this->getMajorProtocolVersion() == 1)) {
  364. #require_once 'Zend/Gdata/App/VersionException.php';
  365. throw new Zend_Gdata_App_VersionException('The getCountHint ' .
  366. ' method is only supported as of version 2 of the YouTube ' .
  367. 'API.');
  368. } else {
  369. return $this->_countHint;
  370. }
  371. }
  372. /**
  373. * Get the thumbnail for a subscription.
  374. *
  375. * @throws Zend_Gdata_App_VersionException
  376. * @return Zend_Gdata_Media_Extension_MediaThumbnail
  377. */
  378. public function getMediaThumbnail()
  379. {
  380. if (($this->getMajorProtocolVersion() == null) ||
  381. ($this->getMajorProtocolVersion() == 1)) {
  382. #require_once 'Zend/Gdata/App/VersionException.php';
  383. throw new Zend_Gdata_App_VersionException('The getMediaThumbnail ' .
  384. ' method is only supported as of version 2 of the YouTube ' .
  385. 'API.');
  386. } else {
  387. return $this->_mediaThumbnail;
  388. }
  389. }
  390. /**
  391. * Get the username for a channel subscription.
  392. *
  393. * @return Zend_Gdata_YouTube_Extension_Username
  394. */
  395. public function getUsername()
  396. {
  397. return $this->_username;
  398. }
  399. /**
  400. * Sets the username for a new channel subscription.
  401. *
  402. * @param Zend_Gdata_YouTube_Extension_Username $username The username of
  403. * the channel to which to subscribe to.
  404. * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
  405. */
  406. public function setUsername($username = null)
  407. {
  408. $this->_username = $username;
  409. return $this;
  410. }
  411. }