2
0

InboxEntry.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_Media_Entry
  23. */
  24. require_once 'Zend/Gdata/Media/Entry.php';
  25. /**
  26. * @see Zend_Gdata_Extension_Rating
  27. */
  28. require_once 'Zend/Gdata/Extension/Rating.php';
  29. /**
  30. * @see Zend_Gdata_Extension_Comments
  31. */
  32. require_once 'Zend/Gdata/Extension/Comments.php';
  33. /**
  34. * @see Zend_Gdata_YouTube_Extension_Statistics
  35. */
  36. require_once 'Zend/Gdata/YouTube/Extension/Statistics.php';
  37. /**
  38. * @see Zend_Gdata_YouTube_Extension_Description
  39. */
  40. require_once 'Zend/Gdata/YouTube/Extension/Description.php';
  41. /**
  42. * Represents the YouTube message flavor of an Atom entry
  43. *
  44. * @category Zend
  45. * @package Zend_Gdata
  46. * @subpackage YouTube
  47. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. */
  50. class Zend_Gdata_YouTube_InboxEntry extends Zend_Gdata_Media_Entry
  51. {
  52. protected $_entryClassName = 'Zend_Gdata_YouTube_InboxEntry';
  53. /**
  54. * The gd:comments element of this entry.
  55. *
  56. * @var Zend_Gdata_Extension_Comments
  57. */
  58. protected $_comments = null;
  59. /**
  60. * The gd:rating element of this entry.
  61. *
  62. * @var Zend_Gdata_Extension_Rating
  63. */
  64. protected $_rating = null;
  65. /**
  66. * The yt:statistics element of this entry.
  67. *
  68. * @var Zend_Gdata_YouTube_Extension_Statistics
  69. */
  70. protected $_statistics = null;
  71. /**
  72. * The yt:description element of this entry.
  73. *
  74. * @var Zend_Gdata_YouTube_Extension_Description
  75. */
  76. protected $_description = null;
  77. /**
  78. * Creates a subscription entry, representing an individual subscription
  79. * in a list of subscriptions, usually associated with an individual user.
  80. *
  81. * @param DOMElement $element (optional) DOMElement from which this
  82. * object should be constructed.
  83. */
  84. public function __construct($element = null)
  85. {
  86. $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
  87. parent::__construct($element);
  88. }
  89. /**
  90. * Retrieves a DOMElement which corresponds to this element and all
  91. * child properties. This is used to build an entry back into a DOM
  92. * and eventually XML text for sending to the server upon updates, or
  93. * for application storage/persistence.
  94. *
  95. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  96. * @return DOMElement The DOMElement representing this element and all
  97. * child properties.
  98. */
  99. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  100. {
  101. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  102. if ($this->_description != null) {
  103. $element->appendChild(
  104. $this->_description->getDOM($element->ownerDocument));
  105. }
  106. if ($this->_rating != null) {
  107. $element->appendChild(
  108. $this->_rating->getDOM($element->ownerDocument));
  109. }
  110. if ($this->_statistics != null) {
  111. $element->appendChild(
  112. $this->_statistics->getDOM($element->ownerDocument));
  113. }
  114. if ($this->_comments != null) {
  115. $element->appendChild(
  116. $this->_comments->getDOM($element->ownerDocument));
  117. }
  118. return $element;
  119. }
  120. /**
  121. * Creates individual Entry objects of the appropriate type and
  122. * stores them in the $_entry array based upon DOM data.
  123. *
  124. * @param DOMNode $child The DOMNode to process
  125. */
  126. protected function takeChildFromDOM($child)
  127. {
  128. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  129. switch ($absoluteNodeName) {
  130. case $this->lookupNamespace('gd') . ':' . 'comments':
  131. $comments = new Zend_Gdata_Extension_Comments();
  132. $comments->transferFromDOM($child);
  133. $this->_comments = $comments;
  134. break;
  135. case $this->lookupNamespace('gd') . ':' . 'rating':
  136. $rating = new Zend_Gdata_Extension_Rating();
  137. $rating->transferFromDOM($child);
  138. $this->_rating = $rating;
  139. break;
  140. case $this->lookupNamespace('yt') . ':' . 'description':
  141. $description = new Zend_Gdata_YouTube_Extension_Description();
  142. $description->transferFromDOM($child);
  143. $this->_description = $description;
  144. break;
  145. case $this->lookupNamespace('yt') . ':' . 'statistics':
  146. $statistics = new Zend_Gdata_YouTube_Extension_Statistics();
  147. $statistics->transferFromDOM($child);
  148. $this->_statistics = $statistics;
  149. break;
  150. default:
  151. parent::takeChildFromDOM($child);
  152. break;
  153. }
  154. }
  155. /**
  156. * Get the yt:description
  157. *
  158. * @throws Zend_Gdata_App_VersionException
  159. * @return Zend_Gdata_YouTube_Extension_Description|null
  160. */
  161. public function getDescription()
  162. {
  163. if ($this->getMajorProtocolVersion() == 2) {
  164. require_once 'Zend/Gdata/App/VersionException.php';
  165. throw new Zend_Gdata_App_VersionException('The getDescription ' .
  166. ' method is only supported in version 1 of the YouTube ' .
  167. 'API.');
  168. } else {
  169. return $this->_description;
  170. }
  171. }
  172. /**
  173. * Sets the yt:description element for a new inbox entry.
  174. *
  175. * @param Zend_Gdata_YouTube_Extension_Description $description The
  176. * description.
  177. * @throws Zend_Gdata_App_VersionException
  178. * @return Zend_Gdata_YouTube_InboxEntry Provides a fluent interface
  179. */
  180. public function setDescription($description = null)
  181. {
  182. if ($this->getMajorProtocolVersion() == 2) {
  183. require_once 'Zend/Gdata/App/VersionException.php';
  184. throw new Zend_Gdata_App_VersionException('The setDescription ' .
  185. ' method is only supported in version 1 of the YouTube ' .
  186. 'API.');
  187. } else {
  188. $this->_description = $description;
  189. return $this;
  190. }
  191. }
  192. /**
  193. * Get the gd:rating element for the inbox entry
  194. *
  195. * @return Zend_Gdata_Extension_Rating|null
  196. */
  197. public function getRating()
  198. {
  199. return $this->_rating;
  200. }
  201. /**
  202. * Sets the gd:rating element for the inbox entry
  203. *
  204. * @param Zend_Gdata_Extension_Rating $rating The rating for the video in
  205. * the message
  206. * @return Zend_Gdata_YouTube_InboxEntry Provides a fluent interface
  207. */
  208. public function setRating($rating = null)
  209. {
  210. $this->_rating = $rating;
  211. return $this;
  212. }
  213. /**
  214. * Get the gd:comments element of the inbox entry.
  215. *
  216. * @return Zend_Gdata_Extension_Comments|null
  217. */
  218. public function getComments()
  219. {
  220. return $this->_comments;
  221. }
  222. /**
  223. * Sets the gd:comments element for the inbox entry
  224. *
  225. * @param Zend_Gdata_Extension_Comments $comments The comments feed link
  226. * @return Zend_Gdata_YouTube_InboxEntry Provides a fluent interface
  227. */
  228. public function setComments($comments = null)
  229. {
  230. $this->_comments = $comments;
  231. return $this;
  232. }
  233. /**
  234. * Get the yt:statistics element for the inbox entry
  235. *
  236. * @return Zend_Gdata_YouTube_Extension_Statistics|null
  237. */
  238. public function getStatistics()
  239. {
  240. return $this->_statistics;
  241. }
  242. /**
  243. * Sets the yt:statistics element for the inbox entry
  244. *
  245. * @param Zend_Gdata_YouTube_Extension_Statistics $statistics The
  246. * statistics element for the video in the message
  247. * @return Zend_Gdata_YouTube_InboxEntry Provides a fluent interface
  248. */
  249. public function setStatistics($statistics = null)
  250. {
  251. $this->_statistics = $statistics;
  252. return $this;
  253. }
  254. }