ItemEntry.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 Gbase
  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_Gbase_Entry
  23. */
  24. require_once 'Zend/Gdata/Gbase/Entry.php';
  25. /**
  26. * Concrete class for working with Item entries.
  27. *
  28. * @link http://code.google.com/apis/base/
  29. *
  30. * @category Zend
  31. * @package Zend_Gdata
  32. * @subpackage Gbase
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Gdata_Gbase_ItemEntry extends Zend_Gdata_Gbase_Entry
  37. {
  38. /**
  39. * The classname for individual item entry elements.
  40. *
  41. * @var string
  42. */
  43. protected $_entryClassName = 'Zend_Gdata_Gbase_ItemEntry';
  44. /**
  45. * Set the value of the itme_type
  46. *
  47. * @param Zend_Gdata_Gbase_Extension_ItemType $value The desired value for the item_type
  48. * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
  49. */
  50. public function setItemType($value)
  51. {
  52. $this->addGbaseAttribute('item_type', $value, 'text');
  53. return $this;
  54. }
  55. /**
  56. * Adds a custom attribute to the entry in the following format:
  57. * &lt;g:[$name] type='[$type]'&gt;[$value]&lt;/g:[$name]&gt;
  58. *
  59. * @param string $name The name of the attribute
  60. * @param string $value The text value of the attribute
  61. * @param string $type (optional) The type of the attribute.
  62. * e.g.: 'text', 'number', 'floatUnit'
  63. * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
  64. */
  65. public function addGbaseAttribute($name, $text, $type = null) {
  66. $newBaseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute($name, $text, $type);
  67. $this->_baseAttributes[] = $newBaseAttribute;
  68. return $this;
  69. }
  70. /**
  71. * Removes a Base attribute from the current list of Base attributes
  72. *
  73. * @param Zend_Gdata_Gbase_Extension_BaseAttribute $baseAttribute The attribute to be removed
  74. * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
  75. */
  76. public function removeGbaseAttribute($baseAttribute) {
  77. $baseAttributes = $this->_baseAttributes;
  78. for ($i = 0; $i < count($this->_baseAttributes); $i++) {
  79. if ($this->_baseAttributes[$i] == $baseAttribute) {
  80. array_splice($baseAttributes, $i, 1);
  81. break;
  82. }
  83. }
  84. $this->_baseAttributes = $baseAttributes;
  85. return $this;
  86. }
  87. /**
  88. * Uploads changes in this entry to the server using Zend_Gdata_App
  89. *
  90. * @param boolean $dryRun Whether the transaction is dry run or not.
  91. * @param string|null $uri The URI to send requests to, or null if $data
  92. * contains the URI.
  93. * @param string|null $className The name of the class that should we
  94. * deserializing the server response. If null, then
  95. * 'Zend_Gdata_App_Entry' will be used.
  96. * @param array $extraHeaders Extra headers to add to the request, as an
  97. * array of string-based key/value pairs.
  98. * @return Zend_Gdata_App_Entry The updated entry
  99. * @throws Zend_Gdata_App_Exception
  100. */
  101. public function save($dryRun = false,
  102. $uri = null,
  103. $className = null,
  104. $extraHeaders = array())
  105. {
  106. if ($dryRun == true) {
  107. $editLink = $this->getEditLink();
  108. if ($uri == null && $editLink !== null) {
  109. $uri = $editLink->getHref() . '?dry-run=true';
  110. }
  111. if ($uri === null) {
  112. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  113. throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
  114. }
  115. $service = new Zend_Gdata_App($this->getHttpClient());
  116. return $service->updateEntry($this,
  117. $uri,
  118. $className,
  119. $extraHeaders);
  120. } else {
  121. parent::save($uri, $className, $extraHeaders);
  122. }
  123. }
  124. /**
  125. * Deletes this entry to the server using the referenced
  126. * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
  127. * entry's link collection.
  128. *
  129. * @param boolean $dyrRun Whether the transaction is dry run or not
  130. * @return void
  131. * @throws Zend_Gdata_App_Exception
  132. */
  133. public function delete($dryRun = false)
  134. {
  135. $uri = null;
  136. if ($dryRun == true) {
  137. $editLink = $this->getEditLink();
  138. if ($editLink !== null) {
  139. $uri = $editLink->getHref() . '?dry-run=true';
  140. }
  141. if ($uri === null) {
  142. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  143. throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
  144. }
  145. parent::delete($uri);
  146. } else {
  147. parent::delete();
  148. }
  149. }
  150. }