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

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

new extension: Google2Piwigo

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