File indexing completed on 2025-03-02 05:29:27

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Gdata
0018  * @subpackage Gdata
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 /**
0025  * @see Zend_Gdata_Extension
0026  */
0027 // require_once 'Zend/Gdata/Extension.php';
0028 
0029 /**
0030  * Implements the gd:rating element
0031  *
0032  *
0033  * @category   Zend
0034  * @package    Zend_Gdata
0035  * @subpackage Gdata
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Gdata_Extension_Rating extends Zend_Gdata_Extension
0040 {
0041 
0042     protected $_rootElement = 'rating';
0043     protected $_min = null;
0044     protected $_max = null;
0045     protected $_numRaters = null;
0046     protected $_average = null;
0047     protected $_value = null;
0048 
0049     /**
0050      * Constructs a new Zend_Gdata_Extension_Rating object.
0051      *
0052      * @param integer $average (optional) Average rating.
0053      * @param integer $min (optional) Minimum rating.
0054      * @param integer $max (optional) Maximum rating.
0055      * @param integer $numRaters (optional) Number of raters.
0056      * @param integer $value (optional) The value of the rating.
0057      */
0058     public function __construct($average = null, $min = null,
0059             $max = null, $numRaters = null, $value = null)
0060     {
0061         parent::__construct();
0062         $this->_average = $average;
0063         $this->_min = $min;
0064         $this->_max = $max;
0065         $this->_numRaters = $numRaters;
0066         $this->_value = $value;
0067     }
0068 
0069     /**
0070      * Retrieves a DOMElement which corresponds to this element and all
0071      * child properties.  This is used to build an entry back into a DOM
0072      * and eventually XML text for sending to the server upon updates, or
0073      * for application storage/persistence.
0074      *
0075      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
0076      * @return DOMElement The DOMElement representing this element and all
0077      *          child properties.
0078      */
0079     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0080     {
0081         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0082         if ($this->_min !== null) {
0083             $element->setAttribute('min', $this->_min);
0084         }
0085         if ($this->_max !== null) {
0086             $element->setAttribute('max', $this->_max);
0087         }
0088         if ($this->_numRaters !== null) {
0089             $element->setAttribute('numRaters', $this->_numRaters);
0090         }
0091         if ($this->_average !== null) {
0092             $element->setAttribute('average', $this->_average);
0093         }
0094         if ($this->_value !== null) {
0095             $element->setAttribute('value', $this->_value);
0096         }
0097 
0098         return $element;
0099     }
0100 
0101     /**
0102      * Given a DOMNode representing an attribute, tries to map the data into
0103      * instance members.  If no mapping is defined, the name and value are
0104      * stored in an array.
0105      *
0106      * @param DOMNode $attribute The DOMNode attribute needed to be handled
0107      */
0108     protected function takeAttributeFromDOM($attribute)
0109     {
0110         switch ($attribute->localName) {
0111             case 'min':
0112                 $this->_min = $attribute->nodeValue;
0113                 break;
0114             case 'max':
0115                 $this->_max = $attribute->nodeValue;
0116                 break;
0117             case 'numRaters':
0118                 $this->_numRaters = $attribute->nodeValue;
0119                 break;
0120             case 'average':
0121                 $this->_average = $attribute->nodeValue;
0122                 break;
0123             case 'value':
0124                 $this->_value = $attribute->nodeValue;
0125             default:
0126                 parent::takeAttributeFromDOM($attribute);
0127         }
0128     }
0129 
0130     /**
0131      * Get the value for this element's min attribute.
0132      *
0133      * @return integer The requested attribute.
0134      */
0135     public function getMin()
0136     {
0137         return $this->_min;
0138     }
0139 
0140     /**
0141      * Set the value for this element's min attribute.
0142      *
0143      * @param bool $value The desired value for this attribute.
0144      * @return Zend_Gdata_Extension_Rating The element being modified.
0145      */
0146     public function setMin($value)
0147     {
0148         $this->_min = $value;
0149         return $this;
0150     }
0151 
0152     /**
0153      * Get the value for this element's numRaters attribute.
0154      *
0155      * @return integer The requested attribute.
0156      */
0157     public function getNumRaters()
0158     {
0159         return $this->_numRaters;
0160     }
0161 
0162     /**
0163      * Set the value for this element's numRaters attribute.
0164      *
0165      * @param bool $value The desired value for this attribute.
0166      * @return Zend_Gdata_Extension_Rating The element being modified.
0167      */
0168     public function setNumRaters($value)
0169     {
0170         $this->_numRaters = $value;
0171         return $this;
0172     }
0173 
0174     /**
0175      * Get the value for this element's average attribute.
0176      *
0177      * @return integer The requested attribute.
0178      */
0179     public function getAverage()
0180     {
0181         return $this->_average;
0182     }
0183 
0184     /**
0185      * Set the value for this element's average attribute.
0186      *
0187      * @param bool $value The desired value for this attribute.
0188      * @return Zend_Gdata_Extension_Rating The element being modified.
0189      */
0190     public function setAverage($value)
0191     {
0192         $this->_average = $value;
0193         return $this;
0194     }
0195 
0196     /**
0197      * Get the value for this element's max attribute.
0198      *
0199      * @return integer The requested attribute.
0200      */
0201     public function getMax()
0202     {
0203         return $this->_max;
0204     }
0205 
0206     /**
0207      * Set the value for this element's max attribute.
0208      *
0209      * @param bool $value The desired value for this attribute.
0210      * @return Zend_Gdata_Extension_Rating The element being modified.
0211      */
0212     public function setMax($value)
0213     {
0214         $this->_max = $value;
0215         return $this;
0216     }
0217 
0218     /**
0219      * Get the value for this element's value attribute.
0220      *
0221      * @return integer The requested attribute.
0222      */
0223     public function getValue()
0224     {
0225         return $this->_value;
0226     }
0227 
0228     /**
0229      * Set the value for this element's value attribute.
0230      *
0231      * @param bool $value The desired value for this attribute.
0232      * @return Zend_Gdata_Extension_Rating The element being modified.
0233      */
0234     public function setValue($value)
0235     {
0236         $this->_value = $value;
0237         return $this;
0238     }
0239 
0240 }