Entry.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_Entry
  23. */
  24. require_once 'Zend/Gdata/Entry.php';
  25. /**
  26. * @see Zend_Gdata_Gbase_Extension_BaseAttribute
  27. */
  28. require_once 'Zend/Gdata/Gbase/Extension/BaseAttribute.php';
  29. /**
  30. * Base class for working with Google Base entries.
  31. *
  32. * @link http://code.google.com/apis/base/
  33. *
  34. * @category Zend
  35. * @package Zend_Gdata
  36. * @subpackage Gbase
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Gdata_Gbase_Entry extends Zend_Gdata_Entry
  41. {
  42. /**
  43. * Name of the base class for Google Base entries
  44. *
  45. * var @string
  46. */
  47. protected $_entryClassName = 'Zend_Gdata_Gbase_Entry';
  48. /**
  49. * Google Base attribute elements in the 'g' namespace
  50. *
  51. * @var array
  52. */
  53. protected $_baseAttributes = array();
  54. /**
  55. * Constructs a new Zend_Gdata_Gbase_ItemEntry object.
  56. * @param DOMElement $element (optional) The DOMElement on which to base this object.
  57. */
  58. public function __construct($element = null)
  59. {
  60. $this->registerAllNamespaces(Zend_Gdata_Gbase::$namespaces);
  61. parent::__construct($element);
  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 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. foreach ($this->_baseAttributes as $baseAttribute) {
  76. $element->appendChild($baseAttribute->getDOM($element->ownerDocument));
  77. }
  78. return $element;
  79. }
  80. /**
  81. * Creates individual Entry objects of the appropriate type and
  82. * stores them as members of this entry based upon DOM data.
  83. *
  84. * @param DOMNode $child The DOMNode to process
  85. */
  86. protected function takeChildFromDOM($child)
  87. {
  88. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  89. if (strstr($absoluteNodeName, $this->lookupNamespace('g') . ':')) {
  90. $baseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute();
  91. $baseAttribute->transferFromDOM($child);
  92. $this->_baseAttributes[] = $baseAttribute;
  93. } else {
  94. parent::takeChildFromDOM($child);
  95. }
  96. }
  97. /**
  98. * Get the value of the itme_type
  99. *
  100. * @return Zend_Gdata_Gbase_Extension_ItemType The requested object.
  101. */
  102. public function getItemType()
  103. {
  104. $itemType = $this->getGbaseAttribute('item_type');
  105. if (is_object($itemType[0])) {
  106. return $itemType[0];
  107. } else {
  108. return null;
  109. }
  110. }
  111. /**
  112. * Return all the Base attributes
  113. * @return Zend_Gdata_Gbase_Extension_BaseAttribute
  114. */
  115. public function getGbaseAttributes() {
  116. return $this->_baseAttributes;
  117. }
  118. /**
  119. * Return an array of Base attributes that match the given attribute name
  120. *
  121. * @param string $name The name of the Base attribute to look for
  122. * @return array $matches Array that contains the matching list of Base attributes
  123. */
  124. public function getGbaseAttribute($name)
  125. {
  126. $matches = array();
  127. for ($i = 0; $i < count($this->_baseAttributes); $i++) {
  128. $baseAttribute = $this->_baseAttributes[$i];
  129. if ($baseAttribute->rootElement == $name &&
  130. $baseAttribute->rootNamespaceURI == $this->lookupNamespace('g')) {
  131. $matches[] = &$this->_baseAttributes[$i];
  132. }
  133. }
  134. return $matches;
  135. }
  136. }