Entry.php 4.6 KB

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