Quota.php 4.1 KB

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