]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/TLiteralColumn.php
baculum: Update PRADO framework from v3.2.3 to v3.2.4
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / TLiteralColumn.php
1 <?php
2 /**
3  * TLiteralColumn class file
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * TDataGridColumn class file
14  */
15 Prado::using('System.Web.UI.WebControls.TDataGridColumn');
16
17 /**
18  * TLiteralColumn class
19  *
20  * TLiteralColumn represents a static text column that is bound to a field in a data source.
21  * The cells in the column will be displayed with static texts using the data indexed by
22  * {@link setDataField DataField}. You can customize the display by
23  * setting {@link setDataFormatString DataFormatString}.
24  *
25  * If {@link setDataField DataField} is not specified, the cells will be filled
26  * with {@link setText Text}.
27  *
28  * If {@link setEncode Encode} is true, the static texts will be HTML-encoded.
29  *
30  * @author Qiang Xue <qiang.xue@gmail.com>
31  * @package System.Web.UI.WebControls
32  * @since 3.0.5
33  */
34 class TLiteralColumn extends TDataGridColumn
35 {
36         /**
37          * @return string the field name from the data source to bind to the column
38          */
39         public function getDataField()
40         {
41                 return $this->getViewState('DataField','');
42         }
43
44         /**
45          * @param string the field name from the data source to bind to the column
46          */
47         public function setDataField($value)
48         {
49                 $this->setViewState('DataField',$value,'');
50         }
51
52         /**
53          * @return string the formatting string used to control how the bound data will be displayed.
54          */
55         public function getDataFormatString()
56         {
57                 return $this->getViewState('DataFormatString','');
58         }
59
60         /**
61          * @param string the formatting string used to control how the bound data will be displayed.
62          */
63         public function setDataFormatString($value)
64         {
65                 $this->setViewState('DataFormatString',$value,'');
66         }
67
68         /**
69          * @return string static text to be displayed in the column. Defaults to empty.
70          */
71         public function getText()
72         {
73                 return $this->getViewState('Text','');
74         }
75
76         /**
77          * @param string static text to be displayed in the column.
78          */
79         public function setText($value)
80         {
81                 $this->setViewState('Text',$value,'');
82         }
83
84         /**
85          * @return boolean whether the rendered text should be HTML-encoded. Defaults to false.
86          */
87         public function getEncode()
88         {
89                 return $this->getViewState('Encode',false);
90         }
91
92         /**
93          * @param boolean  whether the rendered text should be HTML-encoded.
94          */
95         public function setEncode($value)
96         {
97                 $this->setViewState('Encode',TPropertyValue::ensureBoolean($value),false);
98         }
99
100         /**
101          * Initializes the specified cell to its initial values.
102          * This method overrides the parent implementation.
103          * @param TTableCell the cell to be initialized.
104          * @param integer the index to the Columns property that the cell resides in.
105          * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
106          */
107         public function initializeCell($cell,$columnIndex,$itemType)
108         {
109                 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::EditItem || $itemType===TListItemType::SelectedItem)
110                 {
111                         if($this->getDataField()!=='')
112                         {
113                                 $cell->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
114                         } else {
115                                 $text=$this->getText();
116                                 if($this->getEncode())
117                                         $text=THttpUtility::htmlEncode($text);
118                                 $cell->setText($text);
119                         }
120                 }
121                 else
122                         parent::initializeCell($cell,$columnIndex,$itemType);
123         }
124
125         /**
126          * Databinds a cell in the column.
127          * This method is invoked when datagrid performs databinding.
128          * It populates the content of the cell with the relevant data from data source.
129          */
130         public function dataBindColumn($sender,$param)
131         {
132                 $item=$sender->getNamingContainer();
133                 $data=$item->getData();
134                 $formatString=$this->getDataFormatString();
135                 if(($field=$this->getDataField())!=='')
136                         $value=$this->formatDataValue($formatString,$this->getDataFieldValue($data,$field));
137                 else
138                         $value=$this->formatDataValue($formatString,$data);
139                 if($sender instanceof TTableCell)
140                 {
141                         if($this->getEncode())
142                                 $value=THttpUtility::htmlEncode($value);
143                         $sender->setText($value);
144                 }
145         }
146 }
147