| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TTable and TTableRowCollection class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TTable.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Includes TTableRow class
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.WebControls.TTableRow');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* TTable class
|
|
|
20 |
*
|
|
|
21 |
* TTable displays an HTML table on a Web page.
|
|
|
22 |
*
|
|
|
23 |
* A table may have {@link setCaption Caption}, whose alignment is specified
|
|
|
24 |
* via {@link setCaptionAlign CaptionAlign}. The table cellpadding and cellspacing
|
|
|
25 |
* are specified via {@link setCellPadding CellPadding} and {@link setCellSpacing CellSpacing}
|
|
|
26 |
* properties, respectively. The {@link setGridLines GridLines} specifies how
|
|
|
27 |
* the table should display its borders. The horizontal alignment of the table
|
|
|
28 |
* content can be specified via {@link setHorizontalAlign HorizontalAlign},
|
|
|
29 |
* and {@link setBackImageUrl BackImageUrl} can assign a background image to the table.
|
|
|
30 |
*
|
|
|
31 |
* A TTable maintains a list of {@link TTableRow} controls in its
|
|
|
32 |
* {@link getRows Rows} property. Each {@link TTableRow} represents
|
|
|
33 |
* an HTML table row.
|
|
|
34 |
*
|
|
|
35 |
* To populate the table {@link getRows Rows}, you may either use control template
|
|
|
36 |
* or dynamically create {@link TTableRow} in code.
|
|
|
37 |
* In template, do as follows to create the table rows and cells,
|
|
|
38 |
* <code>
|
|
|
39 |
* <com:TTable>
|
|
|
40 |
* <com:TTableRow>
|
|
|
41 |
* <com:TTableCell Text="content" />
|
|
|
42 |
* <com:TTableCell Text="content" />
|
|
|
43 |
* </com:TTableRow>
|
|
|
44 |
* <com:TTableRow>
|
|
|
45 |
* <com:TTableCell Text="content" />
|
|
|
46 |
* <com:TTableCell Text="content" />
|
|
|
47 |
* </com:TTableRow>
|
|
|
48 |
* </com:TTable>
|
|
|
49 |
* </code>
|
|
|
50 |
* The above can also be accomplished in code as follows,
|
|
|
51 |
* <code>
|
|
|
52 |
* $table=new TTable;
|
|
|
53 |
* $row=new TTableRow;
|
|
|
54 |
* $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
|
|
|
55 |
* $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
|
|
|
56 |
* $table->Rows->add($row);
|
|
|
57 |
* $row=new TTableRow;
|
|
|
58 |
* $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
|
|
|
59 |
* $cell=new TTableCell; $cell->Text="content"; $row->Cells->add($cell);
|
|
|
60 |
* $table->Rows->add($row);
|
|
|
61 |
* </code>
|
|
|
62 |
*
|
|
|
63 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
64 |
* @version $Id: TTable.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
65 |
* @package System.Web.UI.WebControls
|
|
|
66 |
* @since 3.0
|
|
|
67 |
*/
|
|
|
68 |
class TTable extends TWebControl
|
|
|
69 |
{
|
|
|
70 |
/**
|
|
|
71 |
* @return string tag name for the table
|
|
|
72 |
*/
|
|
|
73 |
protected function getTagName()
|
|
|
74 |
{
|
|
|
75 |
return 'table';
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Adds object parsed from template to the control.
|
|
|
80 |
* This method adds only {@link TTableRow} objects into the {@link getRows Rows} collection.
|
|
|
81 |
* All other objects are ignored.
|
|
|
82 |
* @param mixed object parsed from template
|
|
|
83 |
*/
|
|
|
84 |
public function addParsedObject($object)
|
|
|
85 |
{
|
|
|
86 |
if($object instanceof TTableRow)
|
|
|
87 |
$this->getRows()->add($object);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Creates a style object for the control.
|
|
|
92 |
* This method creates a {@link TTableStyle} to be used by the table.
|
|
|
93 |
* @return TTableStyle control style to be used
|
|
|
94 |
*/
|
|
|
95 |
protected function createStyle()
|
|
|
96 |
{
|
|
|
97 |
return new TTableStyle;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Adds attributes to renderer.
|
|
|
102 |
* @param THtmlWriter the renderer
|
|
|
103 |
*/
|
|
|
104 |
protected function addAttributesToRender($writer)
|
|
|
105 |
{
|
|
|
106 |
parent::addAttributesToRender($writer);
|
|
|
107 |
$border=0;
|
|
|
108 |
if($this->getHasStyle())
|
|
|
109 |
{
|
|
|
110 |
if($this->getGridLines()!==TTableGridLines::None)
|
|
|
111 |
{
|
|
|
112 |
if(($border=$this->getBorderWidth())==='')
|
|
|
113 |
$border=1;
|
|
|
114 |
else
|
|
|
115 |
$border=(int)$border;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
$writer->addAttribute('border',"$border");
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Creates a control collection object that is to be used to hold child controls
|
|
|
123 |
* @return TTableRowCollection control collection
|
|
|
124 |
* @see getControls
|
|
|
125 |
*/
|
|
|
126 |
protected function createControlCollection()
|
|
|
127 |
{
|
|
|
128 |
return new TTableRowCollection($this);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* @return TTableRowCollection list of {@link TTableRow} controls
|
|
|
133 |
*/
|
|
|
134 |
public function getRows()
|
|
|
135 |
{
|
|
|
136 |
return $this->getControls();
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* @return string table caption
|
|
|
141 |
*/
|
|
|
142 |
public function getCaption()
|
|
|
143 |
{
|
|
|
144 |
return $this->getViewState('Caption','');
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* @param string table caption
|
|
|
149 |
*/
|
|
|
150 |
public function setCaption($value)
|
|
|
151 |
{
|
|
|
152 |
$this->setViewState('Caption',$value,'');
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* @return TTableCaptionAlign table caption alignment. Defaults to TTableCaptionAlign::NotSet.
|
|
|
157 |
*/
|
|
|
158 |
public function getCaptionAlign()
|
|
|
159 |
{
|
|
|
160 |
return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* @param TTableCaptionAlign table caption alignment.
|
|
|
165 |
*/
|
|
|
166 |
public function setCaptionAlign($value)
|
|
|
167 |
{
|
|
|
168 |
$this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
/**
|
|
|
172 |
* @return integer the cellspacing for the table. Defaults to -1, meaning not set.
|
|
|
173 |
*/
|
|
|
174 |
public function getCellSpacing()
|
|
|
175 |
{
|
|
|
176 |
if($this->getHasStyle())
|
|
|
177 |
return $this->getStyle()->getCellSpacing();
|
|
|
178 |
else
|
|
|
179 |
return -1;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
/**
|
|
|
183 |
* @param integer the cellspacing for the table. Defaults to -1, meaning not set.
|
|
|
184 |
*/
|
|
|
185 |
public function setCellSpacing($value)
|
|
|
186 |
{
|
|
|
187 |
$this->getStyle()->setCellSpacing($value);
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
* @return integer the cellpadding for the table. Defaults to -1, meaning not set.
|
|
|
192 |
*/
|
|
|
193 |
public function getCellPadding()
|
|
|
194 |
{
|
|
|
195 |
if($this->getHasStyle())
|
|
|
196 |
return $this->getStyle()->getCellPadding();
|
|
|
197 |
else
|
|
|
198 |
return -1;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/**
|
|
|
202 |
* @param integer the cellpadding for the table. Defaults to -1, meaning not set.
|
|
|
203 |
*/
|
|
|
204 |
public function setCellPadding($value)
|
|
|
205 |
{
|
|
|
206 |
$this->getStyle()->setCellPadding($value);
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* @return THorizontalAlign the horizontal alignment of the table content. Defaults to THorizontalAlign::NotSet.
|
|
|
211 |
*/
|
|
|
212 |
public function getHorizontalAlign()
|
|
|
213 |
{
|
|
|
214 |
if($this->getHasStyle())
|
|
|
215 |
return $this->getStyle()->getHorizontalAlign();
|
|
|
216 |
else
|
|
|
217 |
return THorizontalAlign::NotSet;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
/**
|
|
|
221 |
* @param THorizontalAlign the horizontal alignment of the table content.
|
|
|
222 |
*/
|
|
|
223 |
public function setHorizontalAlign($value)
|
|
|
224 |
{
|
|
|
225 |
$this->getStyle()->setHorizontalAlign($value);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* @return TTableGridLines the grid line setting of the table. Defaults to TTableGridLines::None.
|
|
|
230 |
*/
|
|
|
231 |
public function getGridLines()
|
|
|
232 |
{
|
|
|
233 |
if($this->getHasStyle())
|
|
|
234 |
return $this->getStyle()->getGridLines();
|
|
|
235 |
else
|
|
|
236 |
return TTableGridLines::None;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
/**
|
|
|
240 |
* @param TTableGridLines the grid line setting of the table
|
|
|
241 |
*/
|
|
|
242 |
public function setGridLines($value)
|
|
|
243 |
{
|
|
|
244 |
$this->getStyle()->setGridLines($value);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
/**
|
|
|
248 |
* @return string the URL of the background image for the table
|
|
|
249 |
*/
|
|
|
250 |
public function getBackImageUrl()
|
|
|
251 |
{
|
|
|
252 |
if($this->getHasStyle())
|
|
|
253 |
return $this->getStyle()->getBackImageUrl();
|
|
|
254 |
else
|
|
|
255 |
return '';
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
/**
|
|
|
259 |
* Sets the URL of the background image for the table
|
|
|
260 |
* @param string the URL
|
|
|
261 |
*/
|
|
|
262 |
public function setBackImageUrl($value)
|
|
|
263 |
{
|
|
|
264 |
$this->getStyle()->setBackImageUrl($value);
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
* Renders the openning tag for the table control which will render table caption if present.
|
|
|
269 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
270 |
*/
|
|
|
271 |
public function renderBeginTag($writer)
|
|
|
272 |
{
|
|
|
273 |
parent::renderBeginTag($writer);
|
|
|
274 |
if(($caption=$this->getCaption())!=='')
|
|
|
275 |
{
|
|
|
276 |
if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
|
|
|
277 |
$writer->addAttribute('align',strtolower($align));
|
|
|
278 |
$writer->renderBeginTag('caption');
|
|
|
279 |
$writer->write($caption);
|
|
|
280 |
$writer->renderEndTag();
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
/**
|
|
|
285 |
* Renders body contents of the table.
|
|
|
286 |
* @param THtmlWriter the writer used for the rendering purpose.
|
|
|
287 |
*/
|
|
|
288 |
public function renderContents($writer)
|
|
|
289 |
{
|
|
|
290 |
if($this->getHasControls())
|
|
|
291 |
{
|
|
|
292 |
$renderTableSection=false;
|
|
|
293 |
foreach($this->getControls() as $row)
|
|
|
294 |
{
|
|
|
295 |
if($row->getTableSection()!==TTableRowSection::Body)
|
|
|
296 |
{
|
|
|
297 |
$renderTableSection=true;
|
|
|
298 |
break;
|
|
|
299 |
}
|
|
|
300 |
}
|
|
|
301 |
if($renderTableSection)
|
|
|
302 |
{
|
|
|
303 |
$currentSection=TTableRowSection::Header;
|
|
|
304 |
$writer->writeLine();
|
|
|
305 |
foreach($this->getControls() as $index=>$row)
|
|
|
306 |
{
|
|
|
307 |
if(($section=$row->getTableSection())===$currentSection)
|
|
|
308 |
{
|
|
|
309 |
if($index===0 && $currentSection===TTableRowSection::Header)
|
|
|
310 |
$writer->renderBeginTag('thead');
|
|
|
311 |
}
|
|
|
312 |
else
|
|
|
313 |
{
|
|
|
314 |
if($currentSection===TTableRowSection::Header)
|
|
|
315 |
{
|
|
|
316 |
if($index>0)
|
|
|
317 |
$writer->renderEndTag();
|
|
|
318 |
if($section===TTableRowSection::Body)
|
|
|
319 |
$writer->renderBeginTag('tbody');
|
|
|
320 |
else
|
|
|
321 |
$writer->renderBeginTag('tfoot');
|
|
|
322 |
$currentSection=$section;
|
|
|
323 |
}
|
|
|
324 |
else if($currentSection===TTableRowSection::Body)
|
|
|
325 |
{
|
|
|
326 |
$writer->renderEndTag();
|
|
|
327 |
if($section===TTableRowSection::Footer)
|
|
|
328 |
$writer->renderBeginTag('tfoot');
|
|
|
329 |
else
|
|
|
330 |
throw new TConfigurationException('table_tablesection_outoforder');
|
|
|
331 |
$currentSection=$section;
|
|
|
332 |
}
|
|
|
333 |
else // Footer
|
|
|
334 |
throw new TConfigurationException('table_tablesection_outoforder');
|
|
|
335 |
}
|
|
|
336 |
$row->renderControl($writer);
|
|
|
337 |
$writer->writeLine();
|
|
|
338 |
}
|
|
|
339 |
$writer->renderEndTag();
|
|
|
340 |
}
|
|
|
341 |
else
|
|
|
342 |
{
|
|
|
343 |
$writer->writeLine();
|
|
|
344 |
foreach($this->getControls() as $row)
|
|
|
345 |
{
|
|
|
346 |
$row->renderControl($writer);
|
|
|
347 |
$writer->writeLine();
|
|
|
348 |
}
|
|
|
349 |
}
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
/**
|
|
|
356 |
* TTableRowCollection class.
|
|
|
357 |
*
|
|
|
358 |
* TTableRowCollection is used to maintain a list of rows belong to a table.
|
|
|
359 |
*
|
|
|
360 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
361 |
* @version $Id: TTable.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
362 |
* @package System.Web.UI.WebControls
|
|
|
363 |
* @since 3.0
|
|
|
364 |
*/
|
|
|
365 |
class TTableRowCollection extends TControlCollection
|
|
|
366 |
{
|
|
|
367 |
/**
|
|
|
368 |
* Inserts an item at the specified position.
|
|
|
369 |
* This overrides the parent implementation by performing additional
|
|
|
370 |
* operations for each newly added table row.
|
|
|
371 |
* @param integer the speicified position.
|
|
|
372 |
* @param mixed new item
|
|
|
373 |
* @throws TInvalidDataTypeException if the item to be inserted is not a TTableRow object.
|
|
|
374 |
*/
|
|
|
375 |
public function insertAt($index,$item)
|
|
|
376 |
{
|
|
|
377 |
if($item instanceof TTableRow)
|
|
|
378 |
parent::insertAt($index,$item);
|
|
|
379 |
else
|
|
|
380 |
throw new TInvalidDataTypeException('tablerowcollection_tablerow_required');
|
|
|
381 |
}
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
|
|
|
385 |
/**
|
|
|
386 |
* TTableCaptionAlign class.
|
|
|
387 |
* TTableCaptionAlign defines the enumerable type for the possible alignments
|
|
|
388 |
* that a table caption can take.
|
|
|
389 |
*
|
|
|
390 |
* The following enumerable values are defined:
|
|
|
391 |
* - NotSet: alignment not specified
|
|
|
392 |
* - Top: top aligned
|
|
|
393 |
* - Bottom: bottom aligned
|
|
|
394 |
* - Left: left aligned
|
|
|
395 |
* - Right: right aligned
|
|
|
396 |
*
|
|
|
397 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
398 |
* @version $Id: TTable.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
399 |
* @package System.Web.UI.WebControls
|
|
|
400 |
* @since 3.0.4
|
|
|
401 |
*/
|
|
|
402 |
class TTableCaptionAlign extends TEnumerable
|
|
|
403 |
{
|
|
|
404 |
const NotSet='NotSet';
|
|
|
405 |
const Top='Top';
|
|
|
406 |
const Bottom='Bottom';
|
|
|
407 |
const Left='Left';
|
|
|
408 |
const Right='Right';
|
|
|
409 |
}
|
|
|
410 |
|