Selected.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 Calendar
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * Represents the gCal:selected element used by the Calendar data API
  28. *
  29. * @category Zend
  30. * @package Zend_Gdata
  31. * @subpackage Calendar
  32. * @copyright Copyright (c) 2005-2015 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_Calendar_Extension_Selected extends Zend_Gdata_Extension
  36. {
  37. protected $_rootNamespace = 'gCal';
  38. protected $_rootElement = 'selected';
  39. protected $_value = null;
  40. /**
  41. * Constructs a new Zend_Gdata_Calendar_Extension_Selected object.
  42. * @param bool $value (optional) The value of the element.
  43. */
  44. public function __construct($value = null)
  45. {
  46. $this->registerAllNamespaces(Zend_Gdata_Calendar::$namespaces);
  47. parent::__construct();
  48. $this->_value = $value;
  49. }
  50. /**
  51. * Retrieves a DOMElement which corresponds to this element and all
  52. * child properties. This is used to build an entry back into a DOM
  53. * and eventually XML text for sending to the server upon updates, or
  54. * for application storage/persistence.
  55. *
  56. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  57. * @return DOMElement The DOMElement representing this element and all
  58. * child properties.
  59. */
  60. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  61. {
  62. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  63. if ($this->_value !== null) {
  64. $element->setAttribute('value', ($this->_value ? "true" : "false"));
  65. }
  66. return $element;
  67. }
  68. /**
  69. * Given a DOMNode representing an attribute, tries to map the data into
  70. * instance members. If no mapping is defined, the name and value are
  71. * stored in an array.
  72. *
  73. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  74. */
  75. protected function takeAttributeFromDOM($attribute)
  76. {
  77. switch ($attribute->localName) {
  78. case 'value':
  79. if ($attribute->nodeValue == "true") {
  80. $this->_value = true;
  81. }
  82. else if ($attribute->nodeValue == "false") {
  83. $this->_value = false;
  84. }
  85. else {
  86. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  87. throw new Zend_Gdata_App_InvalidArgumentException("Expected 'true' or 'false' for gCal:selected#value.");
  88. }
  89. break;
  90. default:
  91. parent::takeAttributeFromDOM($attribute);
  92. }
  93. }
  94. /**
  95. * Get the value for this element's value attribute.
  96. *
  97. * @return bool The value associated with this attribute.
  98. */
  99. public function getValue()
  100. {
  101. return $this->_value;
  102. }
  103. /**
  104. * Set the value for this element's value attribute.
  105. *
  106. * @param bool $value The desired value for this attribute.
  107. * @return Zend_Gdata_Calendar_Extension_Selected The element being modified.
  108. */
  109. public function setValue($value)
  110. {
  111. $this->_value = $value;
  112. return $this;
  113. }
  114. /**
  115. * Magic toString method allows using this directly via echo
  116. * Works best in PHP >= 4.2.0
  117. */
  118. public function __toString()
  119. {
  120. return $this->_value;
  121. }
  122. }