~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Gdata/Spreadsheets/ListEntry.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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   Spreadsheets
 
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_Spreadsheets_Extension_Custom
 
30
 */
 
31
require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
 
32
 
 
33
/**
 
34
 * Concrete class for working with List entries.
 
35
 *
 
36
 * @category     Zend
 
37
 * @package        Zend_Gdata
 
38
 * @copyright    Copyright (c) 2005-2008 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_Spreadsheets_ListEntry extends Zend_Gdata_Entry
 
42
{
 
43
 
 
44
    protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
 
45
 
 
46
    /**
 
47
     * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
 
48
     * indexed by order added to this entry.
 
49
     * @var array
 
50
     */
 
51
    protected $_custom = array();
 
52
    
 
53
    /**
 
54
     * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
 
55
     * indexed by element name.
 
56
     * @var array
 
57
     */
 
58
    protected $_customByName = array();
 
59
 
 
60
    /**
 
61
     * Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
 
62
     * @param DOMElement $element An existing XML element on which to base this new object.
 
63
     */
 
64
    public function __construct($element = null)
 
65
    {
 
66
        foreach (Zend_Gdata_Spreadsheets::$namespaces as $nsPrefix => $nsUri) {
 
67
            $this->registerNamespace($nsPrefix, $nsUri);
 
68
        }
 
69
        parent::__construct($element);
 
70
    }
 
71
 
 
72
    public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
 
73
    {
 
74
        $element = parent::getDOM($doc, $majorVersion, $minorVersion);
 
75
        if (!empty($this->_custom)) {
 
76
            foreach ($this->_custom as $custom) {
 
77
                $element->appendChild($custom->getDOM($element->ownerDocument));
 
78
            }
 
79
        }
 
80
        return $element;
 
81
    }
 
82
 
 
83
    protected function takeChildFromDOM($child)
 
84
    {
 
85
        switch ($child->namespaceURI) {
 
86
        case $this->lookupNamespace('gsx');
 
87
            $custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName);
 
88
            $custom->transferFromDOM($child);
 
89
            $this->addCustom($custom);
 
90
            break;
 
91
        default:
 
92
            parent::takeChildFromDOM($child);
 
93
            break;
 
94
        }
 
95
    }
 
96
 
 
97
    /**
 
98
     * Gets the row elements contained by this list entry.
 
99
     * @return array The custom row elements in this list entry
 
100
     */
 
101
    public function getCustom()
 
102
    {
 
103
        return $this->_custom;
 
104
    }
 
105
 
 
106
    /**
 
107
     * Gets a single row element contained by this list entry using its name.
 
108
     * @param string $name The name of a custom element to return. If null
 
109
     *          or not defined, an array containing all custom elements
 
110
     *          indexed by name will be returned.
 
111
     * @return mixed If a name is specified, the
 
112
     *          Zend_Gdata_Spreadsheets_Extension_Custom element requested,
 
113
     *          is returned or null if not found. Otherwise, an array of all
 
114
     *          Zend_Gdata_Spreadsheets_Extension_Custom elements is returned
 
115
     *          indexed by name.
 
116
     */
 
117
    public function getCustomByName($name = null)
 
118
    {
 
119
        if ($name === null) {
 
120
            return $this->_customByName;
 
121
        } else {
 
122
            if (array_key_exists($name, $this->customByName)) {
 
123
                return $this->_customByName[$name];
 
124
            } else {
 
125
                return null;
 
126
            }
 
127
        }
 
128
    }
 
129
 
 
130
    /**
 
131
     * Sets the row elements contained by this list entry. If any 
 
132
     * custom row elements were previously stored, they will be overwritten.
 
133
     * @param array $custom The custom row elements to be contained in this
 
134
     *          list entry.
 
135
     * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
 
136
     */
 
137
    public function setCustom($custom)
 
138
    {
 
139
        $this->_custom = array();
 
140
        foreach ($custom as $c) {
 
141
            $this->addCustom($c);
 
142
        }
 
143
        return $this;
 
144
    }
 
145
 
 
146
    /**
 
147
     * Add an individual custom row element to this list entry.
 
148
     * @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom
 
149
     *             element to be added.
 
150
     * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
 
151
     */
 
152
    public function addCustom($custom)
 
153
    {
 
154
        $this->_custom[] = $custom;
 
155
        $this->_customByName[$custom->getColumnName()] = $custom;
 
156
        return $this;
 
157
    }
 
158
 
 
159
    /**
 
160
     * Remove an individual row element from this list entry by index. This
 
161
     * will cause the array to be re-indexed.
 
162
     * @param int $index The index of the custom element to be deleted.
 
163
     * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
 
164
     * @throws Zend_Gdata_App_InvalidArgumentException
 
165
     */
 
166
    public function removeCustom($index)
 
167
    {
 
168
        if (array_key_exists($index, $this->_custom)) {
 
169
            $element = $this->_custom[$index];
 
170
            // Remove element
 
171
            unset($this->_custom[$index]);
 
172
            // Re-index the array
 
173
            $this->_custom = array_values($this->_custom);
 
174
            // Be sure to delete form both arrays!
 
175
            $key = array_search($element, $this->_customByName);
 
176
            unset($this->_customByName[$key]);
 
177
        } else {
 
178
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
 
179
            throw new Zend_Gdata_App_InvalidArgumentException(
 
180
                'Element does not exist.');
 
181
        }
 
182
        return $this;
 
183
    }
 
184
 
 
185
    /**
 
186
     * Remove an individual row element from this list entry by name.
 
187
     * @param string $name The name of the custom element to be deleted.
 
188
     * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
 
189
     * @throws Zend_Gdata_App_InvalidArgumentException
 
190
     */
 
191
    public function removeCustomByName($name)
 
192
    {
 
193
        if (array_key_exists($name, $this->_customByName)) {
 
194
            $element = $this->_customByName[$name];
 
195
            // Remove element
 
196
            unset($this->_customByName[$name]);
 
197
            // Be sure to delete from both arrays!
 
198
            $key = array_search($element, $this->_custom);
 
199
            unset($this->_custom[$key]);
 
200
        } else {
 
201
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
 
202
            throw new Zend_Gdata_App_InvalidArgumentException(
 
203
                'Element does not exist.');
 
204
        }
 
205
        return $this;
 
206
    }
 
207
 
 
208
}