MediaRating.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 Media
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * Represents the media:rating element specific to YouTube.
  28. *
  29. * @category Zend
  30. * @package Zend_Gdata
  31. * @subpackage YouTube
  32. * @copyright Copyright (c) 2005-2015 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_MediaRating extends Zend_Gdata_Extension
  36. {
  37. protected $_rootElement = 'rating';
  38. protected $_rootNamespace = 'media';
  39. /**
  40. * @var string
  41. */
  42. protected $_scheme = null;
  43. /**
  44. * @var string
  45. */
  46. protected $_country = null;
  47. /**
  48. * Constructs a new MediaRating element
  49. *
  50. * @param string $text
  51. * @param string $scheme
  52. * @param string $country
  53. */
  54. public function __construct($text = null, $scheme = null, $country = null)
  55. {
  56. $this->registerAllNamespaces(Zend_Gdata_Media::$namespaces);
  57. parent::__construct();
  58. $this->_scheme = $scheme;
  59. $this->_country = $country;
  60. $this->_text = $text;
  61. }
  62. /**
  63. * Retrieves a DOMElement which corresponds to this element and all
  64. * child properties. This is used to build an entry back into a DOM
  65. * and eventually XML text for sending to the server upon updates, or
  66. * for application storage/persistence.
  67. *
  68. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  69. * @return DOMElement The DOMElement representing this element and all
  70. * child properties.
  71. */
  72. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  73. {
  74. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  75. if ($this->_scheme !== null) {
  76. $element->setAttribute('scheme', $this->_scheme);
  77. }
  78. if ($this->_country != null) {
  79. $element->setAttribute('country', $this->_country);
  80. }
  81. return $element;
  82. }
  83. /**
  84. * Given a DOMNode representing an attribute, tries to map the data into
  85. * instance members. If no mapping is defined, the name and value are
  86. * stored in an array.
  87. *
  88. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  89. */
  90. protected function takeAttributeFromDOM($attribute)
  91. {
  92. switch ($attribute->localName) {
  93. case 'scheme':
  94. $this->_scheme = $attribute->nodeValue;
  95. break;
  96. case 'country':
  97. $this->_country = $attribute->nodeValue;
  98. break;
  99. default:
  100. parent::takeAttributeFromDOM($attribute);
  101. }
  102. }
  103. /**
  104. * @return string
  105. */
  106. public function getScheme()
  107. {
  108. return $this->_scheme;
  109. }
  110. /**
  111. * @param string $value
  112. * @return Zend_Gdata_YouTube_Extension_MediaRating Provides a fluent interface
  113. */
  114. public function setScheme($value)
  115. {
  116. $this->_scheme = $value;
  117. return $this;
  118. }
  119. /**
  120. * @return string
  121. */
  122. public function getCountry()
  123. {
  124. return $this->_country;
  125. }
  126. /**
  127. * @param string $value
  128. * @return Zend_Gdata_YouTube_Extension_MediaRating Provides a fluent interface
  129. */
  130. public function setCountry($value)
  131. {
  132. $this->_country = $value;
  133. return $this;
  134. }
  135. }