Viewability.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 Books
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc.
  19. * (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * @see Zend_Gdata_Extension
  24. */
  25. require_once 'Zend/Gdata/Extension.php';
  26. /**
  27. * Describes a viewability
  28. *
  29. * @category Zend
  30. * @package Zend_Gdata
  31. * @subpackage Books
  32. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc.
  33. * (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Gdata_Books_Extension_Viewability extends Zend_Gdata_Extension
  37. {
  38. protected $_rootNamespace = 'gbs';
  39. protected $_rootElement = 'viewability';
  40. protected $_value = null;
  41. /**
  42. * Constructor for Zend_Gdata_Books_Extension_Viewability which
  43. * Describes a viewability
  44. *
  45. * @param string|null $value A programmatic value representing the book's
  46. * viewability mode.
  47. */
  48. public function __construct($value = null)
  49. {
  50. $this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
  51. parent::__construct();
  52. $this->_value = $value;
  53. }
  54. /**
  55. * Retrieves DOMElement which corresponds to this element and all
  56. * child properties. This is used to build this object back into a DOM
  57. * and eventually XML text for sending to the server upon updates, or
  58. * for application storage/persistance.
  59. *
  60. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  61. * @return DOMElement The DOMElement representing this element and all
  62. * child properties.
  63. */
  64. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  65. {
  66. $element = parent::getDOM($doc);
  67. if ($this->_value !== null) {
  68. $element->setAttribute('value', $this->_value);
  69. }
  70. return $element;
  71. }
  72. /**
  73. * Extracts XML attributes from the DOM and converts them to the
  74. * appropriate object members.
  75. *
  76. * @param DOMNode $attribute The DOMNode attribute to be handled.
  77. */
  78. protected function takeAttributeFromDOM($attribute)
  79. {
  80. switch ($attribute->localName) {
  81. case 'value':
  82. $this->_value = $attribute->nodeValue;
  83. break;
  84. default:
  85. parent::takeAttributeFromDOM($attribute);
  86. }
  87. }
  88. /**
  89. * Returns the programmatic value that describes the viewability of a volume
  90. * in Google Book Search
  91. *
  92. * @return string The value
  93. */
  94. public function getValue()
  95. {
  96. return $this->_value;
  97. }
  98. /**
  99. * Sets the programmatic value that describes the viewability of a volume in
  100. * Google Book Search
  101. *
  102. * @param string $value programmatic value that describes the viewability
  103. * of a volume in Googl eBook Search
  104. * @return Zend_Gdata_Books_Extension_Viewability Provides a fluent
  105. * interface
  106. */
  107. public function setValue($value)
  108. {
  109. $this->_value = $value;
  110. return $this;
  111. }
  112. }