]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - Zend/Gdata/Extension/Rating.php
Release 6.5.0
[Github/sugarcrm.git] / Zend / Gdata / Extension / Rating.php
1 <?php
2
3 /**
4  * Zend Framework
5  *
6  * LICENSE
7  *
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.
15  *
16  * @category   Zend
17  * @package    Zend_Gdata
18  * @subpackage Gdata
19  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
21
22  */
23
24 /**
25  * @see Zend_Gdata_Extension
26  */
27 require_once 'Zend/Gdata/Extension.php';
28
29 /**
30  * Implements the gd:rating element
31  *
32  *
33  * @category   Zend
34  * @package    Zend_Gdata
35  * @subpackage Gdata
36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
38  */
39 class Zend_Gdata_Extension_Rating extends Zend_Gdata_Extension
40 {
41
42     protected $_rootElement = 'rating';
43     protected $_min = null;
44     protected $_max = null;
45     protected $_numRaters = null;
46     protected $_average = null;
47     protected $_value = null;
48
49     /**
50      * Constructs a new Zend_Gdata_Extension_Rating object.
51      *
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.
57      */
58     public function __construct($average = null, $min = null,
59             $max = null, $numRaters = null, $value = null)
60     {
61         parent::__construct();
62         $this->_average = $average;
63         $this->_min = $min;
64         $this->_max = $max;
65         $this->_numRaters = $numRaters;
66         $this->_value = $value;
67     }
68
69     /**
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.
74      *
75      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
76      * @return DOMElement The DOMElement representing this element and all
77      *          child properties.
78      */
79     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
80     {
81         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
82         if ($this->_min !== null) {
83             $element->setAttribute('min', $this->_min);
84         }
85         if ($this->_max !== null) {
86             $element->setAttribute('max', $this->_max);
87         }
88         if ($this->_numRaters !== null) {
89             $element->setAttribute('numRaters', $this->_numRaters);
90         }
91         if ($this->_average !== null) {
92             $element->setAttribute('average', $this->_average);
93         }
94         if ($this->_value !== null) {
95             $element->setAttribute('value', $this->_value);
96         }
97
98         return $element;
99     }
100
101     /**
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.
105      *
106      * @param DOMNode $attribute The DOMNode attribute needed to be handled
107      */
108     protected function takeAttributeFromDOM($attribute)
109     {
110         switch ($attribute->localName) {
111             case 'min':
112                 $this->_min = $attribute->nodeValue;
113                 break;
114             case 'max':
115                 $this->_max = $attribute->nodeValue;
116                 break;
117             case 'numRaters':
118                 $this->_numRaters = $attribute->nodeValue;
119                 break;
120             case 'average':
121                 $this->_average = $attribute->nodeValue;
122                 break;
123             case 'value':
124                 $this->_value = $attribute->nodeValue;
125             default:
126                 parent::takeAttributeFromDOM($attribute);
127         }
128     }
129
130     /**
131      * Get the value for this element's min attribute.
132      *
133      * @return integer The requested attribute.
134      */
135     public function getMin()
136     {
137         return $this->_min;
138     }
139
140     /**
141      * Set the value for this element's min attribute.
142      *
143      * @param bool $value The desired value for this attribute.
144      * @return Zend_Gdata_Extension_Rating The element being modified.
145      */
146     public function setMin($value)
147     {
148         $this->_min = $value;
149         return $this;
150     }
151
152     /**
153      * Get the value for this element's numRaters attribute.
154      *
155      * @return integer The requested attribute.
156      */
157     public function getNumRaters()
158     {
159         return $this->_numRaters;
160     }
161
162     /**
163      * Set the value for this element's numRaters attribute.
164      *
165      * @param bool $value The desired value for this attribute.
166      * @return Zend_Gdata_Extension_Rating The element being modified.
167      */
168     public function setNumRaters($value)
169     {
170         $this->_numRaters = $value;
171         return $this;
172     }
173
174     /**
175      * Get the value for this element's average attribute.
176      *
177      * @return integer The requested attribute.
178      */
179     public function getAverage()
180     {
181         return $this->_average;
182     }
183
184     /**
185      * Set the value for this element's average attribute.
186      *
187      * @param bool $value The desired value for this attribute.
188      * @return Zend_Gdata_Extension_Rating The element being modified.
189      */
190     public function setAverage($value)
191     {
192         $this->_average = $value;
193         return $this;
194     }
195
196     /**
197      * Get the value for this element's max attribute.
198      *
199      * @return integer The requested attribute.
200      */
201     public function getMax()
202     {
203         return $this->_max;
204     }
205
206     /**
207      * Set the value for this element's max attribute.
208      *
209      * @param bool $value The desired value for this attribute.
210      * @return Zend_Gdata_Extension_Rating The element being modified.
211      */
212     public function setMax($value)
213     {
214         $this->_max = $value;
215         return $this;
216     }
217
218     /**
219      * Get the value for this element's value attribute.
220      *
221      * @return integer The requested attribute.
222      */
223     public function getValue()
224     {
225         return $this->_value;
226     }
227
228     /**
229      * Set the value for this element's value attribute.
230      *
231      * @param bool $value The desired value for this attribute.
232      * @return Zend_Gdata_Extension_Rating The element being modified.
233      */
234     public function setValue($value)
235     {
236         $this->_value = $value;
237         return $this;
238     }
239
240 }