]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/TTableCell.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / TTableCell.php
1 <?php
2 /**
3  * TTableCell class file
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * TTableCell class.
14  *
15  * TTableCell displays a table cell on a Web page. Content of the table cell
16  * is specified by the {@link setText Text} property. If {@link setText Text}
17  * is empty, the body contents enclosed by the table cell component tag are rendered.
18  * Note, {@link setText Text} is not HTML-encoded when displayed. So make sure
19  * it does not contain dangerous characters.
20  *
21  * The horizontal and vertical alignments of the contents in the cell
22  * are specified via {@link setHorizontalAlign HorizontalAlign} and
23  * {@link setVerticalAlign VerticalAlign} properties, respectively.
24  *
25  * The colspan and rowspan of the cell are specified via {@link setColumnSpan ColumnSpan}
26  * and {@link setRowSpan RowSpan} properties. And the {@link setWrap Wrap} property
27  * indicates whether the contents in the cell should be wrapped.
28  *
29  * @author Qiang Xue <qiang.xue@gmail.com>
30  * @package System.Web.UI.WebControls
31  * @since 3.0
32  */
33 class TTableCell extends TWebControl implements IDataRenderer
34 {
35         /**
36          * @return string tag name for the table cell
37          */
38         protected function getTagName()
39         {
40                 return 'td';
41         }
42
43         /**
44          * Creates a style object for the control.
45          * This method creates a {@link TTableItemStyle} to be used by the table cell.
46          * @return TStyle control style to be used
47          */
48         protected function createStyle()
49         {
50                 return new TTableItemStyle;
51         }
52
53         /**
54          * @return string the horizontal alignment of the contents within the table item, defaults to 'NotSet'.
55          */
56         public function getHorizontalAlign()
57         {
58                 if($this->getHasStyle())
59                         return $this->getStyle()->getHorizontalAlign();
60                 else
61                         return 'NotSet';
62         }
63
64         /**
65          * Sets the horizontal alignment of the contents within the table item.
66      * Valid values include 'NotSet', 'Justify', 'Left', 'Right', 'Center'
67          * @param string the horizontal alignment
68          */
69         public function setHorizontalAlign($value)
70         {
71                 $this->getStyle()->setHorizontalAlign($value);
72         }
73
74         /**
75          * @return string the vertical alignment of the contents within the table item, defaults to 'NotSet'.
76          */
77         public function getVerticalAlign()
78         {
79                 if($this->getHasStyle())
80                         return $this->getStyle()->getVerticalAlign();
81                 else
82                         return 'NotSet';
83         }
84
85         /**
86          * Sets the vertical alignment of the contents within the table item.
87      * Valid values include 'NotSet','Top','Bottom','Middle'
88          * @param string the horizontal alignment
89          */
90         public function setVerticalAlign($value)
91         {
92                 $this->getStyle()->setVerticalAlign($value);
93         }
94
95         /**
96          * @return integer the columnspan for the table cell, 0 if not set.
97          */
98         public function getColumnSpan()
99         {
100                 return $this->getViewState('ColumnSpan', 0);
101         }
102
103         /**
104          * Sets the columnspan for the table cell.
105          * @param integer the columnspan for the table cell, 0 if not set.
106          */
107         public function setColumnSpan($value)
108         {
109                 $this->setViewState('ColumnSpan', TPropertyValue::ensureInteger($value), 0);
110         }
111
112         /**
113          * @return integer the rowspan for the table cell, 0 if not set.
114          */
115         public function getRowSpan()
116         {
117                 return $this->getViewState('RowSpan', 0);
118         }
119
120         /**
121          * Sets the rowspan for the table cell.
122          * @param integer the rowspan for the table cell, 0 if not set.
123          */
124         public function setRowSpan($value)
125         {
126                 $this->setViewState('RowSpan', TPropertyValue::ensureInteger($value), 0);
127         }
128
129         /**
130          * @return boolean whether the text content wraps within a table cell. Defaults to true.
131          */
132         public function getWrap()
133         {
134                 if($this->getHasStyle())
135                         return $this->getStyle()->getWrap();
136                 else
137                         return true;
138         }
139
140         /**
141          * Sets the value indicating whether the text content wraps within a table cell.
142          * @param boolean whether the text content wraps within a table cell.
143          */
144         public function setWrap($value)
145         {
146                 $this->getStyle()->setWrap($value);
147         }
148
149         /**
150          * @return string the text content of the table cell.
151          */
152         public function getText()
153         {
154                 return $this->getViewState('Text','');
155         }
156
157         /**
158          * Sets the text content of the table cell.
159          * If the text content is empty, body content (child controls) of the cell will be rendered.
160          * @param string the text content
161          */
162         public function setText($value)
163         {
164                 $this->setViewState('Text',$value,'');
165         }
166
167         /**
168          * Returns the text content of the table cell.
169          * This method is required by {@link IDataRenderer}.
170          * It is the same as {@link getText()}.
171          * @return string the text content of the table cell.
172          * @see getText
173          * @since 3.1.0
174          */
175         public function getData()
176         {
177                 return $this->getText();
178         }
179
180         /**
181          * Sets the text content of the table cell.
182          * This method is required by {@link IDataRenderer}.
183          * It is the same as {@link setText()}.
184          * @param string the text content of the table cell.
185          * @see setText
186          * @since 3.1.0
187          */
188         public function setData($value)
189         {
190                 $this->setText($value);
191         }
192
193         /**
194          * Adds attributes to renderer.
195          * @param THtmlWriter the renderer
196          */
197         protected function addAttributesToRender($writer)
198         {
199                 parent::addAttributesToRender($writer);
200                 if(($colspan=$this->getColumnSpan())>0)
201                         $writer->addAttribute('colspan',"$colspan");
202                 if(($rowspan=$this->getRowSpan())>0)
203                         $writer->addAttribute('rowspan',"$rowspan");
204         }
205
206         /**
207          * Renders body contents of the table cell.
208          * @param THtmlWriter the writer used for the rendering purpose.
209          */
210         public function renderContents($writer)
211         {
212                 if(($text=$this->getText())!=='')
213                         $writer->write($text);
214                 else if($this->getHasControls())
215                         parent::renderContents($writer);
216                 else
217                         $writer->write('&nbsp;');
218         }
219 }
220