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-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id: Statistics.php 16971 2009-07-22 18:05:45Z mikaelkael $
25 * @see Zend_Gdata_Extension
27 require_once 'Zend/Gdata/Extension.php';
30 * Represents the yt:statistics element used by the YouTube data API
35 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Gdata_YouTube_Extension_Statistics
extends Zend_Gdata_Extension
41 protected $_rootNamespace = 'yt';
42 protected $_rootElement = 'statistics';
45 * The videoWatchCount attribute specifies the number of videos
46 * that a user has watched on YouTube. The videoWatchCount attribute
47 * is only specified when the <yt:statistics> tag appears within a
52 protected $_videoWatchCount = null;
55 * When the viewCount attribute refers to a video entry, the attribute
56 * specifies the number of times that the video has been viewed.
57 * When the viewCount attribute refers to a user profile, the attribute
58 * specifies the number of times that the user's profile has been
63 protected $_viewCount = null;
66 * The subscriberCount attribute specifies the number of YouTube users
67 * who have subscribed to a particular user's YouTube channel.
68 * The subscriberCount attribute is only specified when the
69 * <yt:statistics> tag appears within a user profile entry.
73 protected $_subscriberCount = null;
76 * The lastWebAccess attribute indicates the most recent time that
77 * a particular user used YouTube.
81 protected $_lastWebAccess = null;
84 * The favoriteCount attribute specifies the number of YouTube users
85 * who have added a video to their list of favorite videos. The
86 * favoriteCount attribute is only specified when the
87 * <yt:statistics> tag appears within a video entry.
91 protected $_favoriteCount = null;
94 * Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
95 * @param string $viewCount(optional) The viewCount value
96 * @param string $videoWatchCount(optional) The videoWatchCount value
97 * @param string $subscriberCount(optional) The subscriberCount value
98 * @param string $lastWebAccess(optional) The lastWebAccess value
99 * @param string $favoriteCount(optional) The favoriteCount value
101 public function __construct($viewCount = null, $videoWatchCount = null,
102 $subscriberCount = null, $lastWebAccess = null,
103 $favoriteCount = null)
105 $this->registerAllNamespaces(Zend_Gdata_YouTube
::$namespaces);
106 parent
::__construct();
107 $this->_viewCount
= $viewCount;
108 $this->_videoWatchCount
= $videoWatchCount;
109 $this->_subscriberCount
= $subscriberCount;
110 $this->_lastWebAccess
= $lastWebAccess;
111 $this->_favoriteCount
= $favoriteCount;
115 * Retrieves a DOMElement which corresponds to this element and all
116 * child properties. This is used to build an entry back into a DOM
117 * and eventually XML text for sending to the server upon updates, or
118 * for application storage/persistence.
120 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
121 * @return DOMElement The DOMElement representing this element and all
124 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
126 $element = parent
::getDOM($doc, $majorVersion, $minorVersion);
127 if ($this->_videoWatchCount
!== null) {
128 $element->setAttribute('watchCount', $this->_videoWatchCount
);
130 if ($this->_viewCount
!== null) {
131 $element->setAttribute('viewCount', $this->_viewCount
);
133 if ($this->_subscriberCount
!== null) {
134 $element->setAttribute('subscriberCount',
135 $this->_subscriberCount
);
137 if ($this->_lastWebAccess
!== null) {
138 $element->setAttribute('lastWebAccess',
139 $this->_lastWebAccess
);
141 if ($this->_favoriteCount
!== null) {
142 $element->setAttribute('favoriteCount',
143 $this->_favoriteCount
);
149 * Given a DOMNode representing an attribute, tries to map the data into
150 * instance members. If no mapping is defined, the name and valueare
151 * stored in an array.
152 * TODO: Convert attributes to proper types
154 * @param DOMNode $attribute The DOMNode attribute needed to be handled
156 protected function takeAttributeFromDOM($attribute)
158 switch ($attribute->localName
) {
159 case 'videoWatchCount':
160 $this->_videoWatchCount
= $attribute->nodeValue
;
163 $this->_viewCount
= $attribute->nodeValue
;
165 case 'subscriberCount':
166 $this->_subscriberCount
= $attribute->nodeValue
;
168 case 'lastWebAccess':
169 $this->_lastWebAccess
= $attribute->nodeValue
;
171 case 'favoriteCount':
172 $this->_favoriteCount
= $attribute->nodeValue
;
175 parent
::takeAttributeFromDOM($attribute);
180 * Get the value for this element's viewCount attribute.
182 * @return int The value associated with this attribute.
184 public function getViewCount()
186 return $this->_viewCount
;
190 * Set the value for this element's viewCount attribute.
192 * @param int $value The desired value for this attribute.
193 * @return Zend_Gdata_YouTube_Extension_Statistics The element being
196 public function setViewCount($value)
198 $this->_viewCount
= $value;
203 * Get the value for this element's videoWatchCount attribute.
205 * @return int The value associated with this attribute.
207 public function getVideoWatchCount()
209 return $this->_videoWatchCount
;
213 * Set the value for this element's videoWatchCount attribute.
215 * @param int $value The desired value for this attribute.
216 * @return Zend_Gdata_YouTube_Extension_Statistics The element being
219 public function setVideoWatchCount($value)
221 $this->_videoWatchCount
= $value;
226 * Get the value for this element's subscriberCount attribute.
228 * @return int The value associated with this attribute.
230 public function getSubscriberCount()
232 return $this->_subscriberCount
;
236 * Set the value for this element's subscriberCount attribute.
238 * @param int $value The desired value for this attribute.
239 * @return Zend_Gdata_YouTube_Extension_Statistics The element being
242 public function setSubscriberCount($value)
244 $this->_subscriberCount
= $value;
249 * Get the value for this element's lastWebAccess attribute.
251 * @return int The value associated with this attribute.
253 public function getLastWebAccess()
255 return $this->_lastWebAccess
;
259 * Set the value for this element's lastWebAccess attribute.
261 * @param int $value The desired value for this attribute.
262 * @return Zend_Gdata_YouTube_Extension_Statistics The element being
265 public function setLastWebAccess($value)
267 $this->_lastWebAccess
= $value;
272 * Get the value for this element's favoriteCount attribute.
274 * @return int The value associated with this attribute.
276 public function getFavoriteCount()
278 return $this->_favoriteCount
;
282 * Set the value for this element's favoriteCount attribute.
284 * @param int $value The desired value for this attribute.
285 * @return Zend_Gdata_YouTube_Extension_Statistics The element being
288 public function setFavoriteCount($value)
290 $this->_favoriteCount
= $value;
295 * Magic toString method allows using this directly via echo
296 * Works best in PHP >= 4.2.0
300 public function __toString()
302 return 'View Count=' . $this->_viewCount
.
303 ' VideoWatchCount=' . $this->_videoWatchCount
.
304 ' SubscriberCount=' . $this->_subscriberCount
.
305 ' LastWebAccess=' . $this->_lastWebAccess
.
306 ' FavoriteCount=' . $this->_favoriteCount
;