Rating.php 6.7 KB

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