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.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_Entry
27 require_once 'Zend/Gdata/Entry.php';
30 * @see Zend_Gdata_Extension_FeedLink
32 require_once 'Zend/Gdata/Extension/FeedLink.php';
35 * @see Zend_Gdata_YouTube_Extension_Description
37 require_once 'Zend/Gdata/YouTube/Extension/Description.php';
40 * @see Zend_Gdata_YouTube_Extension_PlaylistTitle
42 require_once 'Zend/Gdata/YouTube/Extension/PlaylistTitle.php';
45 * @see Zend_Gdata_YouTube_Extension_PlaylistId
47 require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
50 * @see Zend_Gdata_Media_Extension_MediaThumbnail
52 require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
55 * @see Zend_Gdata_YouTube_Extension_Username
57 require_once 'Zend/Gdata/YouTube/Extension/Username.php';
60 * @see Zend_Gdata_YouTube_Extension_CountHint
62 require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
65 * @see Zend_Gdata_YouTube_Extension_QueryString
67 require_once 'Zend/Gdata/YouTube/Extension/QueryString.php';
70 * Represents the YouTube video subscription flavor of an Atom entry
75 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
76 * @license http://framework.zend.com/license/new-bsd New BSD License
78 class Zend_Gdata_YouTube_SubscriptionEntry extends Zend_Gdata_Entry
81 protected $_entryClassName = 'Zend_Gdata_YouTube_SubscriptionEntry';
88 protected $_feedLink = array();
91 * The username of this entry.
93 * @var Zend_Gdata_YouTube_Extension_Username
95 protected $_username = null;
98 * The playlist title for this entry.
100 * This element is only used on subscriptions to playlists.
102 * @var Zend_Gdata_YouTube_Extension_PlaylistTitle
104 protected $_playlistTitle = null;
107 * The playlist id for this entry.
109 * This element is only used on subscriptions to playlists.
111 * @var Zend_Gdata_YouTube_Extension_PlaylistId
113 protected $_playlistId = null;
116 * The media:thumbnail element for this entry.
118 * This element is only used on subscriptions to playlists.
120 * @var Zend_Gdata_Media_Extension_MediaThumbnail
122 protected $_mediaThumbnail = null;
125 * The countHint for this entry.
127 * @var Zend_Gdata_YouTube_Extension_CountHint
129 protected $_countHint = null;
132 * The queryString for this entry.
134 * @var Zend_Gdata_YouTube_Extension_QueryString
136 protected $_queryString = null;
139 * Creates a subscription entry, representing an individual subscription
140 * in a list of subscriptions, usually associated with an individual user.
142 * @param DOMElement $element (optional) DOMElement from which this
143 * object should be constructed.
145 public function __construct($element = null)
147 $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
148 parent::__construct($element);
152 * Retrieves a DOMElement which corresponds to this element and all
153 * child properties. This is used to build an entry back into a DOM
154 * and eventually XML text for sending to the server upon updates, or
155 * for application storage/persistence.
157 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
158 * @return DOMElement The DOMElement representing this element and all
161 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
163 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
164 if ($this->_countHint != null) {
165 $element->appendChild($this->_countHint->getDOM($element->ownerDocument));
167 if ($this->_playlistTitle != null) {
168 $element->appendChild($this->_playlistTitle->getDOM($element->ownerDocument));
170 if ($this->_playlistId != null) {
171 $element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
173 if ($this->_mediaThumbnail != null) {
174 $element->appendChild($this->_mediaThumbnail->getDOM($element->ownerDocument));
176 if ($this->_username != null) {
177 $element->appendChild($this->_username->getDOM($element->ownerDocument));
179 if ($this->_queryString != null) {
180 $element->appendChild($this->_queryString->getDOM($element->ownerDocument));
182 if ($this->_feedLink != null) {
183 foreach ($this->_feedLink as $feedLink) {
184 $element->appendChild($feedLink->getDOM($element->ownerDocument));
191 * Creates individual Entry objects of the appropriate type and
192 * stores them in the $_entry array based upon DOM data.
194 * @param DOMNode $child The DOMNode to process
196 protected function takeChildFromDOM($child)
198 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
199 switch ($absoluteNodeName) {
200 case $this->lookupNamespace('gd') . ':' . 'feedLink':
201 $feedLink = new Zend_Gdata_Extension_FeedLink();
202 $feedLink->transferFromDOM($child);
203 $this->_feedLink[] = $feedLink;
205 case $this->lookupNamespace('media') . ':' . 'thumbnail':
206 $mediaThumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
207 $mediaThumbnail->transferFromDOM($child);
208 $this->_mediaThumbnail = $mediaThumbnail;
210 case $this->lookupNamespace('yt') . ':' . 'countHint':
211 $countHint = new Zend_Gdata_YouTube_Extension_CountHint();
212 $countHint->transferFromDOM($child);
213 $this->_countHint = $countHint;
215 case $this->lookupNamespace('yt') . ':' . 'playlistTitle':
216 $playlistTitle = new Zend_Gdata_YouTube_Extension_PlaylistTitle();
217 $playlistTitle->transferFromDOM($child);
218 $this->_playlistTitle = $playlistTitle;
220 case $this->lookupNamespace('yt') . ':' . 'playlistId':
221 $playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
222 $playlistId->transferFromDOM($child);
223 $this->_playlistId = $playlistId;
225 case $this->lookupNamespace('yt') . ':' . 'queryString':
226 $queryString = new Zend_Gdata_YouTube_Extension_QueryString();
227 $queryString->transferFromDOM($child);
228 $this->_queryString = $queryString;
230 case $this->lookupNamespace('yt') . ':' . 'username':
231 $username = new Zend_Gdata_YouTube_Extension_Username();
232 $username->transferFromDOM($child);
233 $this->_username = $username;
236 parent::takeChildFromDOM($child);
242 * Sets the array of embedded feeds related to the video
244 * @param array $feedLink The array of embedded feeds relating to the video
245 * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
247 public function setFeedLink($feedLink = null)
249 $this->_feedLink = $feedLink;
254 * Get the feed link property for this entry.
257 * @param string $rel (optional) The rel value of the link to be found.
258 * If null, the array of links is returned.
259 * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
260 * object corresponding to the requested rel value is returned
261 * if found, or null if the requested value is not found. If
262 * $rel is null or not specified, an array of all available
263 * feed links for this entry is returned, or null if no feed
266 public function getFeedLink($rel = null)
269 return $this->_feedLink;
271 foreach ($this->_feedLink as $feedLink) {
272 if ($feedLink->rel == $rel) {
281 * Get the playlist title for a 'playlist' subscription.
283 * @throws Zend_Gdata_App_VersionException
284 * @return Zend_Gdata_YouTube_Extension_PlaylistId
286 public function getPlaylistId()
288 if (($this->getMajorProtocolVersion() == null) ||
289 ($this->getMajorProtocolVersion() == 1)) {
290 require_once 'Zend/Gdata/App/VersionException.php';
291 throw new Zend_Gdata_App_VersionException('The getPlaylistId ' .
292 ' method is only supported as of version 2 of the YouTube ' .
295 return $this->_playlistId;
300 * Sets the yt:playlistId element for a new playlist subscription.
302 * @param Zend_Gdata_YouTube_Extension_PlaylistId $id The id of
303 * the playlist to which to subscribe to.
304 * @throws Zend_Gdata_App_VersionException
305 * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
307 public function setPlaylistId($id = null)
309 if (($this->getMajorProtocolVersion() == null) ||
310 ($this->getMajorProtocolVersion() == 1)) {
311 require_once 'Zend/Gdata/App/VersionException.php';
312 throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
313 ' method is only supported as of version 2 of the YouTube ' .
316 $this->_playlistId = $id;
322 * Get the queryString of the subscription
324 * @return Zend_Gdata_YouTube_Extension_QueryString
326 public function getQueryString()
328 return $this->_queryString;
332 * Sets the yt:queryString element for a new keyword subscription.
334 * @param Zend_Gdata_YouTube_Extension_QueryString $queryString The query
335 * string to subscribe to
336 * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
338 public function setQueryString($queryString = null)
340 $this->_queryString = $queryString;
345 * Get the playlist title for a 'playlist' subscription.
347 * @throws Zend_Gdata_App_VersionException
348 * @return Zend_Gdata_YouTube_Extension_PlaylistTitle
350 public function getPlaylistTitle()
352 if (($this->getMajorProtocolVersion() == null) ||
353 ($this->getMajorProtocolVersion() == 1)) {
354 require_once 'Zend/Gdata/App/VersionException.php';
355 throw new Zend_Gdata_App_VersionException('The getPlaylistTitle ' .
356 ' method is only supported as of version 2 of the YouTube ' .
359 return $this->_playlistTitle;
364 * Sets the yt:playlistTitle element for a new playlist subscription.
366 * @param Zend_Gdata_YouTube_Extension_PlaylistTitle $title The title of
367 * the playlist to which to subscribe to.
368 * @throws Zend_Gdata_App_VersionException
369 * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
371 public function setPlaylistTitle($title = null)
373 if (($this->getMajorProtocolVersion() == null) ||
374 ($this->getMajorProtocolVersion() == 1)) {
375 require_once 'Zend/Gdata/App/VersionException.php';
376 throw new Zend_Gdata_App_VersionException('The setPlaylistTitle ' .
377 ' method is only supported as of version 2 of the YouTube ' .
380 $this->_playlistTitle = $title;
386 * Get the counthint for a subscription.
388 * @throws Zend_Gdata_App_VersionException
389 * @return Zend_Gdata_YouTube_Extension_CountHint
391 public function getCountHint()
393 if (($this->getMajorProtocolVersion() == null) ||
394 ($this->getMajorProtocolVersion() == 1)) {
395 require_once 'Zend/Gdata/App/VersionException.php';
396 throw new Zend_Gdata_App_VersionException('The getCountHint ' .
397 ' method is only supported as of version 2 of the YouTube ' .
400 return $this->_countHint;
405 * Get the thumbnail for a subscription.
407 * @throws Zend_Gdata_App_VersionException
408 * @return Zend_Gdata_Media_Extension_MediaThumbnail
410 public function getMediaThumbnail()
412 if (($this->getMajorProtocolVersion() == null) ||
413 ($this->getMajorProtocolVersion() == 1)) {
414 require_once 'Zend/Gdata/App/VersionException.php';
415 throw new Zend_Gdata_App_VersionException('The getMediaThumbnail ' .
416 ' method is only supported as of version 2 of the YouTube ' .
419 return $this->_mediaThumbnail;
424 * Get the username for a channel subscription.
426 * @return Zend_Gdata_YouTube_Extension_Username
428 public function getUsername()
430 return $this->_username;
434 * Sets the username for a new channel subscription.
436 * @param Zend_Gdata_YouTube_Extension_Username $username The username of
437 * the channel to which to subscribe to.
438 * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
440 public function setUsername($username = null)
442 $this->_username = $username;