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-2008 Zend Technologies USA Inc. (http://www.zend.com)
20
* @license http://framework.zend.com/license/new-bsd New BSD License
24
* @see Zend_Gdata_Extension
26
require_once 'Zend/Gdata/Extension.php';
29
* Represents the yt:statistics element used by the YouTube data API
33
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
34
* @license http://framework.zend.com/license/new-bsd New BSD License
36
class Zend_Gdata_YouTube_Extension_Statistics extends Zend_Gdata_Extension
39
protected $_rootNamespace = 'yt';
40
protected $_rootElement = 'statistics';
41
protected $_viewCount = null;
42
protected $_watchCount = null;
45
* Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
46
* @param string $viewCount(optional) The viewCount value
47
* @param string $watchCount(optional) The watchCount value
49
public function __construct($viewCount = null, $watchCount = null)
51
foreach (Zend_Gdata_YouTube::$namespaces as $nsPrefix => $nsUri) {
52
$this->registerNamespace($nsPrefix, $nsUri);
54
parent::__construct();
55
$this->_viewCount = $viewCount;
56
$this->_watchCount = $watchCount;
60
* Retrieves a DOMElement which corresponds to this element and all
61
* child properties. This is used to build an entry back into a DOM
62
* and eventually XML text for sending to the server upon updates, or
63
* for application storage/persistence.
65
* @param DOMDocument $doc The DOMDocument used to construct DOMElements
66
* @return DOMElement The DOMElement representing this element and all
69
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
71
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
72
if ($this->_viewCount !== null) {
73
$element->setAttribute('viewCount', $this->_viewCount);
75
if ($this->_watchCount !== null) {
76
$element->setAttribute('watchCount', $this->_watchCount);
82
* Given a DOMNode representing an attribute, tries to map the data into
83
* instance members. If no mapping is defined, the name and valueare
85
* TODO: Convert attributes to proper types
87
* @param DOMNode $attribute The DOMNode attribute needed to be handled
89
protected function takeAttributeFromDOM($attribute)
91
switch ($attribute->localName) {
93
$this->_viewCount = $attribute->nodeValue;
96
$this->_watchCount = $attribute->nodeValue;
99
parent::takeAttributeFromDOM($attribute);
104
* Get the value for this element's viewCount attribute.
106
* @return int The value associated with this attribute.
108
public function getViewCount()
110
return $this->_viewCount;
114
* Set the value for this element's viewCount attribute.
116
* @param int $value The desired value for this attribute.
117
* @return Zend_Gdata_YouTube_Extension_Statistics The element being modified.
119
public function setViewCount($value)
121
$this->_viewCount = $value;
126
* Get the value for this element's watchCount attribute.
128
* @return int The value associated with this attribute.
130
public function getWatchCount()
132
return $this->_watchCount;
136
* Set the value for this element's watchCount attribute.
138
* @param int $value The desired value for this attribute.
139
* @return Zend_Gdata_YouTube_Extension_Statistics The element being modified.
141
public function setWatchCount($value)
143
$this->_watchCount = $value;
148
* Magic toString method allows using this directly via echo
149
* Works best in PHP >= 4.2.0
153
public function __toString()
155
return 'View Count=' . $this->_viewCount;