Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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