Quota.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 Gapps
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata_Extension
  23. */
  24. require_once 'Zend/Gdata/Extension.php';
  25. /**
  26. * @see Zend_Gdata_Gapps
  27. */
  28. require_once 'Zend/Gdata/Gapps.php';
  29. /**
  30. * Represents the apps:quota element used by the Apps data API. This is
  31. * used to indicate the amount of storage space available to a user. Quotas
  32. * may not be able to be set, depending on the domain used. This class
  33. * is usually contained within an instance of Zend_Gdata_Gapps_UserEntry.
  34. *
  35. * @category Zend
  36. * @package Zend_Gdata
  37. * @subpackage Gapps
  38. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Gdata_Gapps_Extension_Quota extends Zend_Gdata_Extension
  42. {
  43. protected $_rootNamespace = 'apps';
  44. protected $_rootElement = 'quota';
  45. /**
  46. * The amount of storage space available to the user in megabytes.
  47. *
  48. * @var integer
  49. */
  50. protected $_limit = null;
  51. /**
  52. * Constructs a new Zend_Gdata_Gapps_Extension_Quota object.
  53. *
  54. * @param string $limit (optional) The limit, in bytes, for this quota.
  55. */
  56. public function __construct($limit = null)
  57. {
  58. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  59. parent::__construct();
  60. $this->_limit = $limit;
  61. }
  62. /**
  63. * Retrieves a DOMElement which corresponds to this element and all
  64. * child properties. This is used to build an entry back into a DOM
  65. * and eventually XML text for sending to the server upon updates, or
  66. * for application storage/persistence.
  67. *
  68. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  69. * @return DOMElement The DOMElement representing this element and all
  70. * child properties.
  71. */
  72. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  73. {
  74. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  75. if ($this->_limit !== null) {
  76. $element->setAttribute('limit', $this->_limit);
  77. }
  78. return $element;
  79. }
  80. /**
  81. * Given a DOMNode representing an attribute, tries to map the data into
  82. * instance members. If no mapping is defined, the name and value are
  83. * stored in an array.
  84. *
  85. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  86. */
  87. protected function takeAttributeFromDOM($attribute)
  88. {
  89. switch ($attribute->localName) {
  90. case 'limit':
  91. $this->_limit = $attribute->nodeValue;
  92. break;
  93. default:
  94. parent::takeAttributeFromDOM($attribute);
  95. }
  96. }
  97. /**
  98. * Get the value for this element's limit attribute.
  99. *
  100. * @see setLimit
  101. * @return string The requested attribute.
  102. */
  103. public function getLimit()
  104. {
  105. return $this->_limit;
  106. }
  107. /**
  108. * Set the value for this element's limit attribute. This is the amount
  109. * of storage space, in bytes, that should be made available to
  110. * the associated user.
  111. *
  112. * @param string $value The desired value for this attribute.
  113. * @return Zend_Gdata_Gapps_Extension_Quota Provides a fluent interface.
  114. */
  115. public function setLimit($value)
  116. {
  117. $this->_limit = $value;
  118. return $this;
  119. }
  120. /**
  121. * Magic toString method allows using this directly via echo
  122. * Works best in PHP >= 4.2.0
  123. */
  124. public function __toString()
  125. {
  126. return $this->getLimit();
  127. }
  128. }