PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/library/Zend/Gdata/YouTube/Extension/Statistics.php

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