[44] | 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-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
| 20 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * @see Zend_Gdata_Extension
|
---|
| 25 | */
|
---|
| 26 | require_once 'Zend/Gdata/Extension.php';
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * Represents the yt:statistics element used by the YouTube data API
|
---|
| 30 | *
|
---|
| 31 | * @category Zend
|
---|
| 32 | * @package Zend_Gdata
|
---|
| 33 | * @subpackage YouTube
|
---|
| 34 | * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
| 35 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
| 36 | */
|
---|
| 37 | class Zend_Gdata_YouTube_Extension_Statistics extends Zend_Gdata_Extension
|
---|
| 38 | {
|
---|
| 39 |
|
---|
| 40 | protected $_rootNamespace = 'yt';
|
---|
| 41 | protected $_rootElement = 'statistics';
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * The videoWatchCount attribute specifies the number of videos
|
---|
| 45 | * that a user has watched on YouTube. The videoWatchCount attribute
|
---|
| 46 | * is only specified when the <yt:statistics> tag appears within a
|
---|
| 47 | * user profile entry.
|
---|
| 48 | *
|
---|
| 49 | * @var integer
|
---|
| 50 | */
|
---|
| 51 | protected $_videoWatchCount = null;
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | * When the viewCount attribute refers to a video entry, the attribute
|
---|
| 55 | * specifies the number of times that the video has been viewed.
|
---|
| 56 | * When the viewCount attribute refers to a user profile, the attribute
|
---|
| 57 | * specifies the number of times that the user's profile has been
|
---|
| 58 | * viewed.
|
---|
| 59 | *
|
---|
| 60 | * @var integer
|
---|
| 61 | */
|
---|
| 62 | protected $_viewCount = null;
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * The subscriberCount attribute specifies the number of YouTube users
|
---|
| 66 | * who have subscribed to a particular user's YouTube channel.
|
---|
| 67 | * The subscriberCount attribute is only specified when the
|
---|
| 68 | * <yt:statistics> tag appears within a user profile entry.
|
---|
| 69 | *
|
---|
| 70 | * @var integer
|
---|
| 71 | */
|
---|
| 72 | protected $_subscriberCount = null;
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * The lastWebAccess attribute indicates the most recent time that
|
---|
| 76 | * a particular user used YouTube.
|
---|
| 77 | *
|
---|
| 78 | * @var string
|
---|
| 79 | */
|
---|
| 80 | protected $_lastWebAccess = null;
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * The favoriteCount attribute specifies the number of YouTube users
|
---|
| 84 | * who have added a video to their list of favorite videos. The
|
---|
| 85 | * favoriteCount attribute is only specified when the
|
---|
| 86 | * <yt:statistics> tag appears within a video entry.
|
---|
| 87 | *
|
---|
| 88 | * @var integer
|
---|
| 89 | */
|
---|
| 90 | protected $_favoriteCount = null;
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
|
---|
| 94 | * @param string $viewCount(optional) The viewCount value
|
---|
| 95 | * @param string $videoWatchCount(optional) The videoWatchCount value
|
---|
| 96 | * @param string $subscriberCount(optional) The subscriberCount value
|
---|
| 97 | * @param string $lastWebAccess(optional) The lastWebAccess value
|
---|
| 98 | * @param string $favoriteCount(optional) The favoriteCount value
|
---|
| 99 | */
|
---|
| 100 | public function __construct($viewCount = null, $videoWatchCount = null,
|
---|
| 101 | $subscriberCount = null, $lastWebAccess = null,
|
---|
| 102 | $favoriteCount = null)
|
---|
| 103 | {
|
---|
| 104 | $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
|
---|
| 105 | parent::__construct();
|
---|
| 106 | $this->_viewCount = $viewCount;
|
---|
| 107 | $this->_videoWatchCount = $videoWatchCount;
|
---|
| 108 | $this->_subscriberCount = $subscriberCount;
|
---|
| 109 | $this->_lastWebAccess = $lastWebAccess;
|
---|
| 110 | $this->_favoriteCount = $favoriteCount;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /**
|
---|
| 114 | * Retrieves a DOMElement which corresponds to this element and all
|
---|
| 115 | * child properties. This is used to build an entry back into a DOM
|
---|
| 116 | * and eventually XML text for sending to the server upon updates, or
|
---|
| 117 | * for application storage/persistence.
|
---|
| 118 | *
|
---|
| 119 | * @param DOMDocument $doc The DOMDocument used to construct DOMElements
|
---|
| 120 | * @return DOMElement The DOMElement representing this element and all
|
---|
| 121 | * child properties.
|
---|
| 122 | */
|
---|
| 123 | public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
---|
| 124 | {
|
---|
| 125 | $element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
---|
| 126 | if ($this->_videoWatchCount !== null) {
|
---|
| 127 | $element->setAttribute('watchCount', $this->_videoWatchCount);
|
---|
| 128 | }
|
---|
| 129 | if ($this->_viewCount !== null) {
|
---|
| 130 | $element->setAttribute('viewCount', $this->_viewCount);
|
---|
| 131 | }
|
---|
| 132 | if ($this->_subscriberCount !== null) {
|
---|
| 133 | $element->setAttribute('subscriberCount',
|
---|
| 134 | $this->_subscriberCount);
|
---|
| 135 | }
|
---|
| 136 | if ($this->_lastWebAccess !== null) {
|
---|
| 137 | $element->setAttribute('lastWebAccess',
|
---|
| 138 | $this->_lastWebAccess);
|
---|
| 139 | }
|
---|
| 140 | if ($this->_favoriteCount !== null) {
|
---|
| 141 | $element->setAttribute('favoriteCount',
|
---|
| 142 | $this->_favoriteCount);
|
---|
| 143 | }
|
---|
| 144 | return $element;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | /**
|
---|
| 148 | * Given a DOMNode representing an attribute, tries to map the data into
|
---|
| 149 | * instance members. If no mapping is defined, the name and valueare
|
---|
| 150 | * stored in an array.
|
---|
| 151 | * TODO: Convert attributes to proper types
|
---|
| 152 | *
|
---|
| 153 | * @param DOMNode $attribute The DOMNode attribute needed to be handled
|
---|
| 154 | */
|
---|
| 155 | protected function takeAttributeFromDOM($attribute)
|
---|
| 156 | {
|
---|
| 157 | switch ($attribute->localName) {
|
---|
| 158 | case 'videoWatchCount':
|
---|
| 159 | $this->_videoWatchCount = $attribute->nodeValue;
|
---|
| 160 | break;
|
---|
| 161 | case 'viewCount':
|
---|
| 162 | $this->_viewCount = $attribute->nodeValue;
|
---|
| 163 | break;
|
---|
| 164 | case 'subscriberCount':
|
---|
| 165 | $this->_subscriberCount = $attribute->nodeValue;
|
---|
| 166 | break;
|
---|
| 167 | case 'lastWebAccess':
|
---|
| 168 | $this->_lastWebAccess = $attribute->nodeValue;
|
---|
| 169 | break;
|
---|
| 170 | case 'favoriteCount':
|
---|
| 171 | $this->_favoriteCount = $attribute->nodeValue;
|
---|
| 172 | break;
|
---|
| 173 | default:
|
---|
| 174 | parent::takeAttributeFromDOM($attribute);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /**
|
---|
| 179 | * Get the value for this element's viewCount attribute.
|
---|
| 180 | *
|
---|
| 181 | * @return int The value associated with this attribute.
|
---|
| 182 | */
|
---|
| 183 | public function getViewCount()
|
---|
| 184 | {
|
---|
| 185 | return $this->_viewCount;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | /**
|
---|
| 189 | * Set the value for this element's viewCount attribute.
|
---|
| 190 | *
|
---|
| 191 | * @param int $value The desired value for this attribute.
|
---|
| 192 | * @return Zend_Gdata_YouTube_Extension_Statistics The element being
|
---|
| 193 | * modified.
|
---|
| 194 | */
|
---|
| 195 | public function setViewCount($value)
|
---|
| 196 | {
|
---|
| 197 | $this->_viewCount = $value;
|
---|
| 198 | return $this;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /**
|
---|
| 202 | * Get the value for this element's videoWatchCount attribute.
|
---|
| 203 | *
|
---|
| 204 | * @return int The value associated with this attribute.
|
---|
| 205 | */
|
---|
| 206 | public function getVideoWatchCount()
|
---|
| 207 | {
|
---|
| 208 | return $this->_videoWatchCount;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | /**
|
---|
| 212 | * Set the value for this element's videoWatchCount attribute.
|
---|
| 213 | *
|
---|
| 214 | * @param int $value The desired value for this attribute.
|
---|
| 215 | * @return Zend_Gdata_YouTube_Extension_Statistics The element being
|
---|
| 216 | * modified.
|
---|
| 217 | */
|
---|
| 218 | public function setVideoWatchCount($value)
|
---|
| 219 | {
|
---|
| 220 | $this->_videoWatchCount = $value;
|
---|
| 221 | return $this;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | /**
|
---|
| 225 | * Get the value for this element's subscriberCount attribute.
|
---|
| 226 | *
|
---|
| 227 | * @return int The value associated with this attribute.
|
---|
| 228 | */
|
---|
| 229 | public function getSubscriberCount()
|
---|
| 230 | {
|
---|
| 231 | return $this->_subscriberCount;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | /**
|
---|
| 235 | * Set the value for this element's subscriberCount attribute.
|
---|
| 236 | *
|
---|
| 237 | * @param int $value The desired value for this attribute.
|
---|
| 238 | * @return Zend_Gdata_YouTube_Extension_Statistics The element being
|
---|
| 239 | * modified.
|
---|
| 240 | */
|
---|
| 241 | public function setSubscriberCount($value)
|
---|
| 242 | {
|
---|
| 243 | $this->_subscriberCount = $value;
|
---|
| 244 | return $this;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | /**
|
---|
| 248 | * Get the value for this element's lastWebAccess attribute.
|
---|
| 249 | *
|
---|
| 250 | * @return int The value associated with this attribute.
|
---|
| 251 | */
|
---|
| 252 | public function getLastWebAccess()
|
---|
| 253 | {
|
---|
| 254 | return $this->_lastWebAccess;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /**
|
---|
| 258 | * Set the value for this element's lastWebAccess attribute.
|
---|
| 259 | *
|
---|
| 260 | * @param int $value The desired value for this attribute.
|
---|
| 261 | * @return Zend_Gdata_YouTube_Extension_Statistics The element being
|
---|
| 262 | * modified.
|
---|
| 263 | */
|
---|
| 264 | public function setLastWebAccess($value)
|
---|
| 265 | {
|
---|
| 266 | $this->_lastWebAccess = $value;
|
---|
| 267 | return $this;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | /**
|
---|
| 271 | * Get the value for this element's favoriteCount attribute.
|
---|
| 272 | *
|
---|
| 273 | * @return int The value associated with this attribute.
|
---|
| 274 | */
|
---|
| 275 | public function getFavoriteCount()
|
---|
| 276 | {
|
---|
| 277 | return $this->_favoriteCount;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | /**
|
---|
| 281 | * Set the value for this element's favoriteCount attribute.
|
---|
| 282 | *
|
---|
| 283 | * @param int $value The desired value for this attribute.
|
---|
| 284 | * @return Zend_Gdata_YouTube_Extension_Statistics The element being
|
---|
| 285 | * modified.
|
---|
| 286 | */
|
---|
| 287 | public function setFavoriteCount($value)
|
---|
| 288 | {
|
---|
| 289 | $this->_favoriteCount = $value;
|
---|
| 290 | return $this;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | /**
|
---|
| 294 | * Magic toString method allows using this directly via echo
|
---|
| 295 | * Works best in PHP >= 4.2.0
|
---|
| 296 | *
|
---|
| 297 | * @return string
|
---|
| 298 | */
|
---|
| 299 | public function __toString()
|
---|
| 300 | {
|
---|
| 301 | return 'View Count=' . $this->_viewCount .
|
---|
| 302 | ' VideoWatchCount=' . $this->_videoWatchCount .
|
---|
| 303 | ' SubscriberCount=' . $this->_subscriberCount .
|
---|
| 304 | ' LastWebAccess=' . $this->_lastWebAccess .
|
---|
| 305 | ' FavoriteCount=' . $this->_favoriteCount;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | }
|
---|