ItemEntry.php 5.6 KB

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