source: extensions/Google2Piwigo/include/Zend/Gdata/YouTube/SubscriptionEntry.php @ 17475

Last change on this file since 17475 was 17475, checked in by mistic100, 12 years ago

new extension: Google2Piwigo

File size: 14.5 KB
Line 
1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
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.
15 *
16 * @category   Zend
17 * @package    Zend_Gdata
18 * @subpackage YouTube
19 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21 * @version    $Id: SubscriptionEntry.php 24594 2012-01-05 21:27:01Z matthew $
22 */
23
24/**
25 * @see Zend_Gdata_Entry
26 */
27require_once 'Zend/Gdata/Entry.php';
28
29/**
30 * @see Zend_Gdata_Extension_FeedLink
31 */
32require_once 'Zend/Gdata/Extension/FeedLink.php';
33
34/**
35 * @see Zend_Gdata_YouTube_Extension_Description
36 */
37require_once 'Zend/Gdata/YouTube/Extension/Description.php';
38
39/**
40 * @see Zend_Gdata_YouTube_Extension_PlaylistTitle
41 */
42require_once 'Zend/Gdata/YouTube/Extension/PlaylistTitle.php';
43
44/**
45 * @see Zend_Gdata_YouTube_Extension_PlaylistId
46 */
47require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
48
49/**
50 * @see Zend_Gdata_Media_Extension_MediaThumbnail
51 */
52require_once 'Zend/Gdata/Media/Extension/MediaThumbnail.php';
53
54/**
55 * @see Zend_Gdata_YouTube_Extension_Username
56 */
57require_once 'Zend/Gdata/YouTube/Extension/Username.php';
58
59/**
60 * @see Zend_Gdata_YouTube_Extension_CountHint
61 */
62require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
63
64/**
65 * @see Zend_Gdata_YouTube_Extension_QueryString
66 */
67require_once 'Zend/Gdata/YouTube/Extension/QueryString.php';
68
69/**
70 * Represents the YouTube video subscription flavor of an Atom entry
71 *
72 * @category   Zend
73 * @package    Zend_Gdata
74 * @subpackage YouTube
75 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
76 * @license    http://framework.zend.com/license/new-bsd     New BSD License
77 */
78class Zend_Gdata_YouTube_SubscriptionEntry extends Zend_Gdata_Entry
79{
80
81    protected $_entryClassName = 'Zend_Gdata_YouTube_SubscriptionEntry';
82
83    /**
84     * Nested feed links
85     *
86     * @var array
87     */
88    protected $_feedLink = array();
89
90    /**
91     * The username of this entry.
92     *
93     * @var Zend_Gdata_YouTube_Extension_Username
94     */
95    protected $_username = null;
96
97    /**
98     * The playlist title for this entry.
99     *
100     * This element is only used on subscriptions to playlists.
101     *
102     * @var Zend_Gdata_YouTube_Extension_PlaylistTitle
103     */
104    protected $_playlistTitle = null;
105
106    /**
107     * The playlist id for this entry.
108     *
109     * This element is only used on subscriptions to playlists.
110     *
111     * @var Zend_Gdata_YouTube_Extension_PlaylistId
112     */
113    protected $_playlistId = null;
114
115    /**
116     * The media:thumbnail element for this entry.
117     *
118     * This element is only used on subscriptions to playlists.
119     *
120     * @var Zend_Gdata_Media_Extension_MediaThumbnail
121     */
122    protected $_mediaThumbnail = null;
123
124    /**
125     * The countHint for this entry.
126     *
127     * @var Zend_Gdata_YouTube_Extension_CountHint
128     */
129    protected $_countHint = null;
130
131    /**
132     * The queryString for this entry.
133     *
134     * @var Zend_Gdata_YouTube_Extension_QueryString
135     */
136    protected $_queryString = null;
137
138    /**
139     * Creates a subscription entry, representing an individual subscription
140     * in a list of subscriptions, usually associated with an individual user.
141     *
142     * @param DOMElement $element (optional) DOMElement from which this
143     *          object should be constructed.
144     */
145    public function __construct($element = null)
146    {
147        $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
148        parent::__construct($element);
149    }
150
151    /**
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.
156     *
157     * @param DOMDocument $doc The DOMDocument used to construct DOMElements
158     * @return DOMElement The DOMElement representing this element and all
159     * child properties.
160     */
161    public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
162    {
163        $element = parent::getDOM($doc, $majorVersion, $minorVersion);
164        if ($this->_countHint != null) {
165            $element->appendChild($this->_countHint->getDOM($element->ownerDocument));
166        }
167        if ($this->_playlistTitle != null) {
168            $element->appendChild($this->_playlistTitle->getDOM($element->ownerDocument));
169        }
170        if ($this->_playlistId != null) {
171            $element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
172        }
173        if ($this->_mediaThumbnail != null) {
174            $element->appendChild($this->_mediaThumbnail->getDOM($element->ownerDocument));
175        }
176        if ($this->_username != null) {
177            $element->appendChild($this->_username->getDOM($element->ownerDocument));
178        }
179        if ($this->_queryString != null) {
180            $element->appendChild($this->_queryString->getDOM($element->ownerDocument));
181        }
182        if ($this->_feedLink != null) {
183            foreach ($this->_feedLink as $feedLink) {
184                $element->appendChild($feedLink->getDOM($element->ownerDocument));
185            }
186        }
187        return $element;
188    }
189
190    /**
191     * Creates individual Entry objects of the appropriate type and
192     * stores them in the $_entry array based upon DOM data.
193     *
194     * @param DOMNode $child The DOMNode to process
195     */
196    protected function takeChildFromDOM($child)
197    {
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;
204            break;
205        case $this->lookupNamespace('media') . ':' . 'thumbnail':
206            $mediaThumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail();
207            $mediaThumbnail->transferFromDOM($child);
208            $this->_mediaThumbnail = $mediaThumbnail;
209            break;
210        case $this->lookupNamespace('yt') . ':' . 'countHint':
211            $countHint = new Zend_Gdata_YouTube_Extension_CountHint();
212            $countHint->transferFromDOM($child);
213            $this->_countHint = $countHint;
214            break;
215        case $this->lookupNamespace('yt') . ':' . 'playlistTitle':
216            $playlistTitle = new Zend_Gdata_YouTube_Extension_PlaylistTitle();
217            $playlistTitle->transferFromDOM($child);
218            $this->_playlistTitle = $playlistTitle;
219            break;
220        case $this->lookupNamespace('yt') . ':' . 'playlistId':
221            $playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
222            $playlistId->transferFromDOM($child);
223            $this->_playlistId = $playlistId;
224            break;
225        case $this->lookupNamespace('yt') . ':' . 'queryString':
226            $queryString = new Zend_Gdata_YouTube_Extension_QueryString();
227            $queryString->transferFromDOM($child);
228            $this->_queryString = $queryString;
229            break;
230        case $this->lookupNamespace('yt') . ':' . 'username':
231            $username = new Zend_Gdata_YouTube_Extension_Username();
232            $username->transferFromDOM($child);
233            $this->_username = $username;
234            break;
235        default:
236            parent::takeChildFromDOM($child);
237            break;
238        }
239    }
240
241    /**
242     * Sets the array of embedded feeds related to the video
243     *
244     * @param array $feedLink The array of embedded feeds relating to the video
245     * @return Zend_Gdata_YouTube_SubscriptionEntry Provides a fluent interface
246     */
247    public function setFeedLink($feedLink = null)
248    {
249        $this->_feedLink = $feedLink;
250        return $this;
251    }
252
253    /**
254     * Get the feed link property for this entry.
255     *
256     * @see setFeedLink
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
264     *          links are set.
265     */
266    public function getFeedLink($rel = null)
267    {
268        if ($rel == null) {
269            return $this->_feedLink;
270        } else {
271            foreach ($this->_feedLink as $feedLink) {
272                if ($feedLink->rel == $rel) {
273                    return $feedLink;
274                }
275            }
276            return null;
277        }
278    }
279
280    /**
281     * Get the playlist title for a 'playlist' subscription.
282     *
283     * @throws Zend_Gdata_App_VersionException
284     * @return Zend_Gdata_YouTube_Extension_PlaylistId
285     */
286    public function getPlaylistId()
287    {
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 ' .
293                'API.');
294        } else {
295            return $this->_playlistId;
296        }
297    }
298
299    /**
300     * Sets the yt:playlistId element for a new playlist subscription.
301     *
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
306     */
307    public function setPlaylistId($id = null)
308    {
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 ' .
314                'API.');
315        } else {
316            $this->_playlistId = $id;
317            return $this;
318        }
319    }
320
321    /**
322     * Get the queryString of the subscription
323     *
324     * @return Zend_Gdata_YouTube_Extension_QueryString
325     */
326    public function getQueryString()
327    {
328        return $this->_queryString;
329    }
330
331    /**
332     * Sets the yt:queryString element for a new keyword subscription.
333     *
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
337     */
338    public function setQueryString($queryString = null)
339    {
340        $this->_queryString = $queryString;
341        return $this;
342    }
343
344    /**
345     * Get the playlist title for a 'playlist' subscription.
346     *
347     * @throws Zend_Gdata_App_VersionException
348     * @return Zend_Gdata_YouTube_Extension_PlaylistTitle
349     */
350    public function getPlaylistTitle()
351    {
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 ' .
357                'API.');
358        } else {
359            return $this->_playlistTitle;
360        }
361    }
362
363    /**
364     * Sets the yt:playlistTitle element for a new playlist subscription.
365     *
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
370     */
371    public function setPlaylistTitle($title = null)
372    {
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 ' .
378                'API.');
379        } else {
380            $this->_playlistTitle = $title;
381            return $this;
382        }
383    }
384
385    /**
386     * Get the counthint for a subscription.
387     *
388     * @throws Zend_Gdata_App_VersionException
389     * @return Zend_Gdata_YouTube_Extension_CountHint
390     */
391    public function getCountHint()
392    {
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 ' .
398                'API.');
399        } else {
400            return $this->_countHint;
401        }
402    }
403
404    /**
405     * Get the thumbnail for a subscription.
406     *
407     * @throws Zend_Gdata_App_VersionException
408     * @return Zend_Gdata_Media_Extension_MediaThumbnail
409     */
410    public function getMediaThumbnail()
411    {
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 ' .
417                'API.');
418        } else {
419            return $this->_mediaThumbnail;
420        }
421    }
422
423    /**
424     * Get the username for a channel subscription.
425     *
426     * @return Zend_Gdata_YouTube_Extension_Username
427     */
428    public function getUsername()
429    {
430        return $this->_username;
431    }
432
433    /**
434     * Sets the username for a new channel subscription.
435     *
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
439     */
440    public function setUsername($username = null)
441    {
442        $this->_username = $username;
443        return $this;
444    }
445
446}
Note: See TracBrowser for help on using the repository browser.