File indexing completed on 2024-06-23 05:55:21

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 Calendar
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  * Represents the gCal:selected element used by the Calendar data API
0031  *
0032  * @category   Zend
0033  * @package    Zend_Gdata
0034  * @subpackage Calendar
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  */
0038 class Zend_Gdata_Calendar_Extension_Selected extends Zend_Gdata_Extension
0039 {
0040 
0041     protected $_rootNamespace = 'gCal';
0042     protected $_rootElement = 'selected';
0043     protected $_value = null;
0044 
0045     /**
0046      * Constructs a new Zend_Gdata_Calendar_Extension_Selected object.
0047      * @param bool $value (optional) The value of the element.
0048      */
0049     public function __construct($value = null)
0050     {
0051         $this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
0052         parent::__construct();
0053         $this->_value = $value;
0054     }
0055 
0056     /**
0057      * Retrieves a DOMElement which corresponds to this element and all
0058      * child properties.  This is used to build an entry back into a DOM
0059      * and eventually XML text for sending to the server upon updates, or
0060      * for application storage/persistence.
0061      *
0062      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
0063      * @return DOMElement The DOMElement representing this element and all
0064      * child properties.
0065      */
0066     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0067     {
0068         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0069         if ($this->_value !== null) {
0070             $element->setAttribute('value', ($this->_value ? "true" : "false"));
0071         }
0072         return $element;
0073     }
0074 
0075     /**
0076      * Given a DOMNode representing an attribute, tries to map the data into
0077      * instance members.  If no mapping is defined, the name and value are
0078      * stored in an array.
0079      *
0080      * @param DOMNode $attribute The DOMNode attribute needed to be handled
0081      */
0082     protected function takeAttributeFromDOM($attribute)
0083     {
0084         switch ($attribute->localName) {
0085         case 'value':
0086             if ($attribute->nodeValue == "true") {
0087                 $this->_value = true;
0088             }
0089             else if ($attribute->nodeValue == "false") {
0090                 $this->_value = false;
0091             }
0092             else {
0093                 // require_once 'Zend/Gdata/App/InvalidArgumentException.php';
0094                 throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
0095             }
0096             break;
0097         default:
0098             parent::takeAttributeFromDOM($attribute);
0099         }
0100     }
0101 
0102     /**
0103      * Get the value for this element's value attribute.
0104      *
0105      * @return bool The value associated with this attribute.
0106      */
0107     public function getValue()
0108     {
0109         return $this->_value;
0110     }
0111 
0112     /**
0113      * Set the value for this element's value attribute.
0114      *
0115      * @param bool $value The desired value for this attribute.
0116      * @return Zend_Gdata_Calendar_Extension_Selected The element being modified.
0117      */
0118     public function setValue($value)
0119     {
0120         $this->_value = $value;
0121         return $this;
0122     }
0123 
0124     /**
0125      * Magic toString method allows using this directly via echo
0126      * Works best in PHP >= 4.2.0
0127      */
0128     public function __toString()
0129     {
0130         return $this->_value;
0131     }
0132 
0133 }