PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Gdata/YouTube/PlaylistListEntry.php

https://github.com/kervin/kyzstudio
PHP | 300 lines | 125 code | 24 blank | 151 comment | 28 complexity | bc21b4bff916051f43ed0d839266a77f 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: PlaylistListEntry.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /**
  23. * @see Zend_Gdata_YouTube
  24. */
  25. #require_once 'Zend/Gdata/YouTube.php';
  26. /**
  27. * @see Zend_Gdata_Entry
  28. */
  29. #require_once 'Zend/Gdata/Entry.php';
  30. /**
  31. * @see Zend_Gdata_Extension_FeedLink
  32. */
  33. #require_once 'Zend/Gdata/Extension/FeedLink.php';
  34. /**
  35. * @see Zend_Gdata_YouTube_Extension_Description
  36. */
  37. #require_once 'Zend/Gdata/YouTube/Extension/Description.php';
  38. /**
  39. * @see Zend_Gdata_YouTube_Extension_PlaylistId
  40. */
  41. #require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
  42. /**
  43. * @see Zend_Gdata_YouTube_Extension_CountHint
  44. */
  45. #require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
  46. /**
  47. * Represents the YouTube video playlist flavor of an Atom entry
  48. *
  49. * @category Zend
  50. * @package Zend_Gdata
  51. * @subpackage YouTube
  52. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  53. * @license http://framework.zend.com/license/new-bsd New BSD License
  54. */
  55. class Zend_Gdata_YouTube_PlaylistListEntry extends Zend_Gdata_Entry
  56. {
  57. protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistListEntry';
  58. /**
  59. * Nested feed links
  60. *
  61. * @var array
  62. */
  63. protected $_feedLink = array();
  64. /**
  65. * Description of this playlist
  66. *
  67. * @deprecated Deprecated as of version 2 of the YouTube API.
  68. * @var Zend_Gdata_YouTube_Extension_Description
  69. */
  70. protected $_description = null;
  71. /**
  72. * Id of this playlist
  73. *
  74. * @var Zend_Gdata_YouTube_Extension_PlaylistId
  75. */
  76. protected $_playlistId = null;
  77. /**
  78. * CountHint for this playlist.
  79. *
  80. * @var Zend_Gdata_YouTube_Extension_CountHint
  81. */
  82. protected $_countHint = null;
  83. /**
  84. * Creates a Playlist list entry, representing an individual playlist
  85. * in a list of playlists, usually associated with an individual user.
  86. *
  87. * @param DOMElement $element (optional) DOMElement from which this
  88. * object should be constructed.
  89. */
  90. public function __construct($element = null)
  91. {
  92. $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
  93. parent::__construct($element);
  94. }
  95. /**
  96. * Retrieves a DOMElement which corresponds to this element and all
  97. * child properties. This is used to build an entry back into a DOM
  98. * and eventually XML text for sending to the server upon updates, or
  99. * for application storage/persistence.
  100. *
  101. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  102. * @return DOMElement The DOMElement representing this element and all
  103. * child properties.
  104. */
  105. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  106. {
  107. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  108. if ($this->_description != null) {
  109. $element->appendChild($this->_description->getDOM($element->ownerDocument));
  110. }
  111. if ($this->_countHint != null) {
  112. $element->appendChild($this->_countHint->getDOM($element->ownerDocument));
  113. }
  114. if ($this->_playlistId != null) {
  115. $element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
  116. }
  117. if ($this->_feedLink != null) {
  118. foreach ($this->_feedLink as $feedLink) {
  119. $element->appendChild($feedLink->getDOM($element->ownerDocument));
  120. }
  121. }
  122. return $element;
  123. }
  124. /**
  125. * Creates individual Entry objects of the appropriate type and
  126. * stores them in the $_entry array based upon DOM data.
  127. *
  128. * @param DOMNode $child The DOMNode to process
  129. */
  130. protected function takeChildFromDOM($child)
  131. {
  132. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  133. switch ($absoluteNodeName) {
  134. case $this->lookupNamespace('yt') . ':' . 'description':
  135. $description = new Zend_Gdata_YouTube_Extension_Description();
  136. $description->transferFromDOM($child);
  137. $this->_description = $description;
  138. break;
  139. case $this->lookupNamespace('yt') . ':' . 'countHint':
  140. $countHint = new Zend_Gdata_YouTube_Extension_CountHint();
  141. $countHint->transferFromDOM($child);
  142. $this->_countHint = $countHint;
  143. break;
  144. case $this->lookupNamespace('yt') . ':' . 'playlistId':
  145. $playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
  146. $playlistId->transferFromDOM($child);
  147. $this->_playlistId = $playlistId;
  148. break;
  149. case $this->lookupNamespace('gd') . ':' . 'feedLink':
  150. $feedLink = new Zend_Gdata_Extension_FeedLink();
  151. $feedLink->transferFromDOM($child);
  152. $this->_feedLink[] = $feedLink;
  153. break;
  154. default:
  155. parent::takeChildFromDOM($child);
  156. break;
  157. }
  158. }
  159. /**
  160. * Sets the description relating to the playlist.
  161. *
  162. * @deprecated Deprecated as of version 2 of the YouTube API.
  163. * @param Zend_Gdata_YouTube_Extension_Description $description The description relating to the video
  164. * @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
  165. */
  166. public function setDescription($description = null)
  167. {
  168. if ($this->getMajorProtocolVersion() >= 2) {
  169. $this->setSummary($description);
  170. } else {
  171. $this->_description = $description;
  172. }
  173. return $this;
  174. }
  175. /**
  176. * Returns the description relating to the video.
  177. *
  178. * @return Zend_Gdata_YouTube_Extension_Description The description
  179. * relating to the video
  180. */
  181. public function getDescription()
  182. {
  183. if ($this->getMajorProtocolVersion() >= 2) {
  184. return $this->getSummary();
  185. } else {
  186. return $this->_description;
  187. }
  188. }
  189. /**
  190. * Returns the countHint relating to the playlist.
  191. *
  192. * The countHint is the number of videos on a playlist.
  193. *
  194. * @throws Zend_Gdata_App_VersionException
  195. * @return Zend_Gdata_YouTube_Extension_CountHint The count of videos on
  196. * a playlist.
  197. */
  198. public function getCountHint()
  199. {
  200. if (($this->getMajorProtocolVersion() == null) ||
  201. ($this->getMajorProtocolVersion() == 1)) {
  202. #require_once 'Zend/Gdata/App/VersionException.php';
  203. throw new Zend_Gdata_App_VersionException('The yt:countHint ' .
  204. 'element is not supported in versions earlier than 2.');
  205. } else {
  206. return $this->_countHint;
  207. }
  208. }
  209. /**
  210. * Returns the Id relating to the playlist.
  211. *
  212. * @throws Zend_Gdata_App_VersionException
  213. * @return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
  214. */
  215. public function getPlaylistId()
  216. {
  217. if (($this->getMajorProtocolVersion() == null) ||
  218. ($this->getMajorProtocolVersion() == 1)) {
  219. #require_once 'Zend/Gdata/App/VersionException.php';
  220. throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
  221. 'element is not supported in versions earlier than 2.');
  222. } else {
  223. return $this->_playlistId;
  224. }
  225. }
  226. /**
  227. * Sets the array of embedded feeds related to the playlist
  228. *
  229. * @param array $feedLink The array of embedded feeds relating to the video
  230. * @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
  231. */
  232. public function setFeedLink($feedLink = null)
  233. {
  234. $this->_feedLink = $feedLink;
  235. return $this;
  236. }
  237. /**
  238. * Get the feed link property for this entry.
  239. *
  240. * @see setFeedLink
  241. * @param string $rel (optional) The rel value of the link to be found.
  242. * If null, the array of links is returned.
  243. * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
  244. * object corresponding to the requested rel value is returned
  245. * if found, or null if the requested value is not found. If
  246. * $rel is null or not specified, an array of all available
  247. * feed links for this entry is returned, or null if no feed
  248. * links are set.
  249. */
  250. public function getFeedLink($rel = null)
  251. {
  252. if ($rel == null) {
  253. return $this->_feedLink;
  254. } else {
  255. foreach ($this->_feedLink as $feedLink) {
  256. if ($feedLink->rel == $rel) {
  257. return $feedLink;
  258. }
  259. }
  260. return null;
  261. }
  262. }
  263. /**
  264. * Returns the URL of the playlist video feed
  265. *
  266. * @return string The URL of the playlist video feed
  267. */
  268. public function getPlaylistVideoFeedUrl()
  269. {
  270. if ($this->getMajorProtocolVersion() >= 2) {
  271. return $this->getContent()->getSrc();
  272. } else {
  273. return $this->getFeedLink(Zend_Gdata_YouTube::PLAYLIST_REL)->href;
  274. }
  275. }
  276. }