8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 * @version $Id: Rating.php 16971 2009-07-22 18:05:45Z mikaelkael $
25 * @see Zend_Gdata_Extension
27 require_once 'Zend/Gdata/Extension.php';
30 * Implements the gd:rating element
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_Gdata_Extension_Rating
extends Zend_Gdata_Extension
42 protected $_rootElement = 'rating';
43 protected $_min = null;
44 protected $_max = null;
45 protected $_numRaters = null;
46 protected $_average = null;
47 protected $_value = null;
50 * Constructs a new Zend_Gdata_Extension_Rating object.
52 * @param integer $average (optional) Average rating.
53 * @param integer $min (optional) Minimum rating.
54 * @param integer $max (optional) Maximum rating.
55 * @param integer $numRaters (optional) Number of raters.
56 * @param integer $value (optional) The value of the rating.
58 public function __construct($average = null, $min = null,
59 $max = null, $numRaters = null, $value = null)
61 parent
::__construct();
62 $this->_average
= $average;
65 $this->_numRaters
= $numRaters;
66 $this->_value
= $value;
70 * Retrieves a DOMElement which corresponds to this element and all
71 * child properties. This is used to build an entry back into a DOM
72 * and eventually XML text for sending to the server upon updates, or
73 * for application storage/persistence.
75 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
76 * @return DOMElement The DOMElement representing this element and all
79 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
81 $element = parent
::getDOM($doc, $majorVersion, $minorVersion);
82 if ($this->_min
!== null) {
83 $element->setAttribute('min', $this->_min
);
85 if ($this->_max
!== null) {
86 $element->setAttribute('max', $this->_max
);
88 if ($this->_numRaters
!== null) {
89 $element->setAttribute('numRaters', $this->_numRaters
);
91 if ($this->_average
!== null) {
92 $element->setAttribute('average', $this->_average
);
94 if ($this->_value
!== null) {
95 $element->setAttribute('value', $this->_value
);
102 * Given a DOMNode representing an attribute, tries to map the data into
103 * instance members. If no mapping is defined, the name and value are
104 * stored in an array.
106 * @param DOMNode $attribute The DOMNode attribute needed to be handled
108 protected function takeAttributeFromDOM($attribute)
110 switch ($attribute->localName
) {
112 $this->_min
= $attribute->nodeValue
;
115 $this->_max
= $attribute->nodeValue
;
118 $this->_numRaters
= $attribute->nodeValue
;
121 $this->_average
= $attribute->nodeValue
;
124 $this->_value
= $attribute->nodeValue
;
126 parent
::takeAttributeFromDOM($attribute);
131 * Get the value for this element's min attribute.
133 * @return integer The requested attribute.
135 public function getMin()
141 * Set the value for this element's min attribute.
143 * @param bool $value The desired value for this attribute.
144 * @return Zend_Gdata_Extension_Rating The element being modified.
146 public function setMin($value)
148 $this->_min
= $value;
153 * Get the value for this element's numRaters attribute.
155 * @return integer The requested attribute.
157 public function getNumRaters()
159 return $this->_numRaters
;
163 * Set the value for this element's numRaters attribute.
165 * @param bool $value The desired value for this attribute.
166 * @return Zend_Gdata_Extension_Rating The element being modified.
168 public function setNumRaters($value)
170 $this->_numRaters
= $value;
175 * Get the value for this element's average attribute.
177 * @return integer The requested attribute.
179 public function getAverage()
181 return $this->_average
;
185 * Set the value for this element's average attribute.
187 * @param bool $value The desired value for this attribute.
188 * @return Zend_Gdata_Extension_Rating The element being modified.
190 public function setAverage($value)
192 $this->_average
= $value;
197 * Get the value for this element's max attribute.
199 * @return integer The requested attribute.
201 public function getMax()
207 * Set the value for this element's max attribute.
209 * @param bool $value The desired value for this attribute.
210 * @return Zend_Gdata_Extension_Rating The element being modified.
212 public function setMax($value)
214 $this->_max
= $value;
219 * Get the value for this element's value attribute.
221 * @return integer The requested attribute.
223 public function getValue()
225 return $this->_value
;
229 * Set the value for this element's value attribute.
231 * @param bool $value The desired value for this attribute.
232 * @return Zend_Gdata_Extension_Rating The element being modified.
234 public function setValue($value)
236 $this->_value
= $value;