Statistics.php 9.5 KB

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