1 | <?php
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Zend Framework
|
---|
5 | *
|
---|
6 | * LICENSE
|
---|
7 | *
|
---|
8 | * This source file is subject to the new BSD license that is bundled
|
---|
9 | * with this package in the file LICENSE.txt.
|
---|
10 | * It is also available through the world-wide-web at this URL:
|
---|
11 | * http://framework.zend.com/license/new-bsd
|
---|
12 | * If you did not receive a copy of the license and are unable to
|
---|
13 | * obtain it through the world-wide-web, please send an email
|
---|
14 | * to license@zend.com so we can send you a copy immediately.
|
---|
15 | *
|
---|
16 | * @category Zend
|
---|
17 | * @package Zend_Gdata
|
---|
18 | * @subpackage Gbase
|
---|
19 | * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
20 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
21 | */
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * @see Zend_Gdata_Entry
|
---|
25 | */
|
---|
26 | require_once 'Zend/Gdata/Entry.php';
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * @see Zend_Gdata_Gbase_Extension_BaseAttribute
|
---|
30 | */
|
---|
31 | require_once 'Zend/Gdata/Gbase/Extension/BaseAttribute.php';
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Base class for working with Google Base entries.
|
---|
35 | *
|
---|
36 | * @link http://code.google.com/apis/base/
|
---|
37 | *
|
---|
38 | * @category Zend
|
---|
39 | * @package Zend_Gdata
|
---|
40 | * @subpackage Gbase
|
---|
41 | * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
42 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
43 | */
|
---|
44 | class Zend_Gdata_Gbase_Entry extends Zend_Gdata_Entry
|
---|
45 | {
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Name of the base class for Google Base entries
|
---|
49 | *
|
---|
50 | * var @string
|
---|
51 | */
|
---|
52 | protected $_entryClassName = 'Zend_Gdata_Gbase_Entry';
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Google Base attribute elements in the 'g' namespace
|
---|
56 | *
|
---|
57 | * @var array
|
---|
58 | */
|
---|
59 | protected $_baseAttributes = array();
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Constructs a new Zend_Gdata_Gbase_ItemEntry object.
|
---|
63 | * @param DOMElement $element (optional) The DOMElement on which to base this object.
|
---|
64 | */
|
---|
65 | public function __construct($element = null)
|
---|
66 | {
|
---|
67 | $this->registerAllNamespaces(Zend_Gdata_Gbase::$namespaces);
|
---|
68 | parent::__construct($element);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Retrieves a DOMElement which corresponds to this element and all
|
---|
73 | * child properties. This is used to build an entry back into a DOM
|
---|
74 | * and eventually XML text for application storage/persistence.
|
---|
75 | *
|
---|
76 | * @param DOMDocument $doc The DOMDocument used to construct DOMElements
|
---|
77 | * @return DOMElement The DOMElement representing this element and all
|
---|
78 | * child properties.
|
---|
79 | */
|
---|
80 | public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
---|
81 | {
|
---|
82 | $element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
---|
83 | foreach ($this->_baseAttributes as $baseAttribute) {
|
---|
84 | $element->appendChild($baseAttribute->getDOM($element->ownerDocument));
|
---|
85 | }
|
---|
86 | return $element;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Creates individual Entry objects of the appropriate type and
|
---|
91 | * stores them as members of this entry based upon DOM data.
|
---|
92 | *
|
---|
93 | * @param DOMNode $child The DOMNode to process
|
---|
94 | */
|
---|
95 | protected function takeChildFromDOM($child)
|
---|
96 | {
|
---|
97 | $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
---|
98 |
|
---|
99 | if (strstr($absoluteNodeName, $this->lookupNamespace('g') . ':')) {
|
---|
100 | $baseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute();
|
---|
101 | $baseAttribute->transferFromDOM($child);
|
---|
102 | $this->_baseAttributes[] = $baseAttribute;
|
---|
103 | } else {
|
---|
104 | parent::takeChildFromDOM($child);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Get the value of the itme_type
|
---|
110 | *
|
---|
111 | * @return Zend_Gdata_Gbase_Extension_ItemType The requested object.
|
---|
112 | */
|
---|
113 | public function getItemType()
|
---|
114 | {
|
---|
115 | $itemType = $this->getGbaseAttribute('item_type');
|
---|
116 | if (is_object($itemType[0])) {
|
---|
117 | return $itemType[0];
|
---|
118 | } else {
|
---|
119 | return null;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Return all the Base attributes
|
---|
125 | * @return Zend_Gdata_Gbase_Extension_BaseAttribute
|
---|
126 | */
|
---|
127 | public function getGbaseAttributes() {
|
---|
128 | return $this->_baseAttributes;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Return an array of Base attributes that match the given attribute name
|
---|
133 | *
|
---|
134 | * @param string $name The name of the Base attribute to look for
|
---|
135 | * @return array $matches Array that contains the matching list of Base attributes
|
---|
136 | */
|
---|
137 | public function getGbaseAttribute($name)
|
---|
138 | {
|
---|
139 | $matches = array();
|
---|
140 | for ($i = 0; $i < count($this->_baseAttributes); $i++) {
|
---|
141 | $baseAttribute = $this->_baseAttributes[$i];
|
---|
142 | if ($baseAttribute->rootElement == $name &&
|
---|
143 | $baseAttribute->rootNamespaceURI == $this->lookupNamespace('g')) {
|
---|
144 | $matches[] = &$this->_baseAttributes[$i];
|
---|
145 | }
|
---|
146 | }
|
---|
147 | return $matches;
|
---|
148 | }
|
---|
149 |
|
---|
150 | }
|
---|