2
0

SubscriptionEntry.php 14 KB

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