-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
TableCell.php
216 lines (193 loc) · 5.1 KB
/
TableCell.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* OpenDocument_TableCell class
*
* This file is based on the work done by Alexander Pak <irokez@gmail.com>
* in his OpenDocument Library distributed on PEAR.
* A special thanks to him for setting the road we followed.
* This library is governed by the GNU Lesser Public License
*
* The whole library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category File Formats
* @package OpenDocument
* @author Joe Bordes, JPL TSolucio, S.L. <joe@tsolucio.com>
* Copyright 2009 JPL TSolucio, S.L. -- This file is a part of coreBOS.
*/
require_once 'Element.php';
/**
* OpenDocument_TableCell element
*
* @category File Formats
* @package OpenDocument
* @author Alexander Pak <irokez@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1
* @version 0.1.0
* @link http://pear.php.net/package/OpenDocument
* @since File available since Release 0.1.0
*/
class OpenDocument_TableCell extends OpenDocument_StyledElement {
/**
* Collection of children objects
*
* @var ArrayIterator
* @access read-only
*/
public $children;
/**
* Node namespace
*/
const nodeNS = OpenDocument::NS_TABLE;
/**
* Node amespace
*/
const nodePrefix = 'table';
/**
* Node name
*/
const nodeName = 'table-cell';
/**
* Element style name prefix
*/
const styleNamePrefix = 'T';
public $numbercolumnsspanned;
public $numberrowsspanned;
/**
* Constructor
*
* @param DOMNode $node
* @param OpenDocument $document
*/
public function __construct(DOMNode $node, OpenDocument $document, $colspan = '', $rowspan = '') {
parent::__construct($node, $document);
$this->allowedElements = array(
'OpenDocument_Table',
'OpenDocument_Paragraph',
'OpenDocument_TextElement',
'OpenDocument_Heading',
);
return true;
}
/**
* Create element instance
*
* @param mixed $object
* @param mixed $content
* @return OpenDocument_TableCell
* @throws OpenDocument_Exception
*/
public static function instance($object, $content, $colspan, $rowspan) {
if ($object instanceof OpenDocument) {
$document = $object;
$node = $object->cursor;
} elseif ($object instanceof OpenDocument_Element) {
$document = $object->getDocument();
$node = $object->getNode();
} else {
throw new OpenDocument_Exception(OpenDocument_Exception::ELEM_OR_DOC_EXPECTED);
}
$element = new OpenDocument_TableCell($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document, $colspan, $rowspan);
$node->appendChild($element->node);
if (is_scalar($content)) {
$element->createParagraph($content);
}
return $element;
}
/**
* Get style information
*
* @param array $properties
* @return array
*/
public function getStyle($properties) {
return $this->document->getStyle($this->getStyleName(), $properties);
}
/**
* Get style name
*
* @return string
*/
public function getStyleName() {
return $this->node->getAttributeNS(OpenDocument::NS_TABLE, 'style-name');
}
/**
* Get style name prefix
*
* @return string
*/
public function getStyleNamePrefix() {
return $this->styleNamePrefix;
}
/**
* Generate new style name
*
* @return string $stylename
*/
public function generateStyleName() {
self::$styleNameMaxNumber ++;
return self::styleNamePrefix . self::$styleNameMaxNumber;
}
/**
* Apply style information
*
* @param string $name
* @param mixed $value
*/
public function applyStyle($name, $value, $elemtype) {
$style_name = $this->node->getAttributeNS(OpenDocument::NS_TABLE, 'style-name');
$style_name = $this->document->applyStyle($style_name, $name, $value, $this, $elemtype);
$this->node->setAttributeNS(OpenDocument::NS_TABLE, 'style-name', $style_name);
}
/************** Elements ****************/
/**
* Create OpenDocument_Table
*
* @param string $text optional
* @return OpenDocument_Table
* @access public
*/
public function createTable($subtable = '') {
return OpenDocument_Table::instance($this, $subtable);
}
/**
* Create OpenDocument_TextElement
*
* @param string $text
* @return OpenDocument_TextElement
*/
public function createTextElement($text) {
return OpenDocument_TextElement::instance($this, $text);
}
/**
* Create OpenDocument_Paragraph
*
* @param string $text optional
* @return OpenDocument_Paragraph
* @access public
*/
public function createParagraph($text = '') {
return OpenDocument_Paragraph::instance($this, $text);
}
public function createHeading($text = '', $level = 1) {
return OpenDocument_Heading::instance($this, $text, $level);
}
/**
* Get children list
*
* @return ArrayIterator
* @access public
*/
public function getChildren() {
if (empty($this->children)) {
$this->listChildren();
}
return $this->children->getIterator();
}
}
?>