Rating.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 Gdata
  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. * Implements the gd:rating element
  28. *
  29. *
  30. * @category Zend
  31. * @package Zend_Gdata
  32. * @subpackage Gdata
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Gdata_Extension_Rating extends Zend_Gdata_Extension
  37. {
  38. protected $_rootElement = 'rating';
  39. protected $_min = null;
  40. protected $_max = null;
  41. protected $_numRaters = null;
  42. protected $_average = null;
  43. protected $_value = null;
  44. /**
  45. * Constructs a new Zend_Gdata_Extension_Rating object.
  46. *
  47. * @param integer $average (optional) Average rating.
  48. * @param integer $min (optional) Minimum rating.
  49. * @param integer $max (optional) Maximum rating.
  50. * @param integer $numRaters (optional) Number of raters.
  51. * @param integer $value (optional) The value of the rating.
  52. */
  53. public function __construct($average = null, $min = null,
  54. $max = null, $numRaters = null, $value = null)
  55. {
  56. parent::__construct();
  57. $this->_average = $average;
  58. $this->_min = $min;
  59. $this->_max = $max;
  60. $this->_numRaters = $numRaters;
  61. $this->_value = $value;
  62. }
  63. /**
  64. * Retrieves a DOMElement which corresponds to this element and all
  65. * child properties. This is used to build an entry back into a DOM
  66. * and eventually XML text for sending to the server upon updates, or
  67. * for application storage/persistence.
  68. *
  69. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  70. * @return DOMElement The DOMElement representing this element and all
  71. * child properties.
  72. */
  73. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  74. {
  75. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  76. if ($this->_min !== null) {
  77. $element->setAttribute('min', $this->_min);
  78. }
  79. if ($this->_max !== null) {
  80. $element->setAttribute('max', $this->_max);
  81. }
  82. if ($this->_numRaters !== null) {
  83. $element->setAttribute('numRaters', $this->_numRaters);
  84. }
  85. if ($this->_average !== null) {
  86. $element->setAttribute('average', $this->_average);
  87. }
  88. if ($this->_value !== null) {
  89. $element->setAttribute('value', $this->_value);
  90. }
  91. return $element;
  92. }
  93. /**
  94. * Given a DOMNode representing an attribute, tries to map the data into
  95. * instance members. If no mapping is defined, the name and value are
  96. * stored in an array.
  97. *
  98. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  99. */
  100. protected function takeAttributeFromDOM($attribute)
  101. {
  102. switch ($attribute->localName) {
  103. case 'min':
  104. $this->_min = $attribute->nodeValue;
  105. break;
  106. case 'max':
  107. $this->_max = $attribute->nodeValue;
  108. break;
  109. case 'numRaters':
  110. $this->_numRaters = $attribute->nodeValue;
  111. break;
  112. case 'average':
  113. $this->_average = $attribute->nodeValue;
  114. break;
  115. case 'value':
  116. $this->_value = $attribute->nodeValue;
  117. default:
  118. parent::takeAttributeFromDOM($attribute);
  119. }
  120. }
  121. /**
  122. * Get the value for this element's min attribute.
  123. *
  124. * @return integer The requested attribute.
  125. */
  126. public function getMin()
  127. {
  128. return $this->_min;
  129. }
  130. /**
  131. * Set the value for this element's min attribute.
  132. *
  133. * @param bool $value The desired value for this attribute.
  134. * @return Zend_Gdata_Extension_Rating The element being modified.
  135. */
  136. public function setMin($value)
  137. {
  138. $this->_min = $value;
  139. return $this;
  140. }
  141. /**
  142. * Get the value for this element's numRaters attribute.
  143. *
  144. * @return integer The requested attribute.
  145. */
  146. public function getNumRaters()
  147. {
  148. return $this->_numRaters;
  149. }
  150. /**
  151. * Set the value for this element's numRaters attribute.
  152. *
  153. * @param bool $value The desired value for this attribute.
  154. * @return Zend_Gdata_Extension_Rating The element being modified.
  155. */
  156. public function setNumRaters($value)
  157. {
  158. $this->_numRaters = $value;
  159. return $this;
  160. }
  161. /**
  162. * Get the value for this element's average attribute.
  163. *
  164. * @return integer The requested attribute.
  165. */
  166. public function getAverage()
  167. {
  168. return $this->_average;
  169. }
  170. /**
  171. * Set the value for this element's average attribute.
  172. *
  173. * @param bool $value The desired value for this attribute.
  174. * @return Zend_Gdata_Extension_Rating The element being modified.
  175. */
  176. public function setAverage($value)
  177. {
  178. $this->_average = $value;
  179. return $this;
  180. }
  181. /**
  182. * Get the value for this element's max attribute.
  183. *
  184. * @return integer The requested attribute.
  185. */
  186. public function getMax()
  187. {
  188. return $this->_max;
  189. }
  190. /**
  191. * Set the value for this element's max attribute.
  192. *
  193. * @param bool $value The desired value for this attribute.
  194. * @return Zend_Gdata_Extension_Rating The element being modified.
  195. */
  196. public function setMax($value)
  197. {
  198. $this->_max = $value;
  199. return $this;
  200. }
  201. /**
  202. * Get the value for this element's value attribute.
  203. *
  204. * @return integer The requested attribute.
  205. */
  206. public function getValue()
  207. {
  208. return $this->_value;
  209. }
  210. /**
  211. * Set the value for this element's value attribute.
  212. *
  213. * @param bool $value The desired value for this attribute.
  214. * @return Zend_Gdata_Extension_Rating The element being modified.
  215. */
  216. public function setValue($value)
  217. {
  218. $this->_value = $value;
  219. return $this;
  220. }
  221. }