Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TCheckBoxColumn 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: TCheckBoxColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * TDataGridColumn class file
15
 */
16
Prado::using('System.Web.UI.WebControls.TDataGridColumn');
17
/**
18
 * TCheckBox class file
19
 */
20
Prado::using('System.Web.UI.WebControls.TCheckBox');
21
 
22
/**
23
 * TCheckBoxColumn class
24
 *
25
 * TCheckBoxColumn represents a checkbox column that is bound to a field in a data source.
26
 * The checked state of the checkboxes are determiend by the bound data at
27
 * {@link setDataField DataField}. If {@link setReadOnly ReadOnly} is false,
28
 * TCheckBoxColumn will display an enabled checkbox provided the cells are
29
 * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting.
30
 *
31
 * The checkbox control in the TCheckBoxColumn can be accessed by one of
32
 * the following two methods:
33
 * <code>
34
 * $datagridItem->CheckBoxColumnID->CheckBox
35
 * $datagridItem->CheckBoxColumnID->Controls[0]
36
 * </code>
37
 * The second method is possible because the checkbox control created within the
38
 * datagrid cell is the first child.
39
 *
40
 * @author Qiang Xue <qiang.xue@gmail.com>
41
 * @version $Id: TCheckBoxColumn.php 2541 2008-10-21 15:05:13Z qiang.xue $
42
 * @package System.Web.UI.WebControls
43
 * @since 3.0
44
 */
45
class TCheckBoxColumn extends TDataGridColumn
46
{
47
	/**
48
	 * @return string the field name from the data source to bind to the column
49
	 */
50
	public function getDataField()
51
	{
52
		return $this->getViewState('DataField','');
53
	}
54
 
55
	/**
56
	 * @param string the field name from the data source to bind to the column
57
	 */
58
	public function setDataField($value)
59
	{
60
		$this->setViewState('DataField',$value,'');
61
	}
62
 
63
	/**
64
	 * @return boolean whether the items in the column can be edited. Defaults to false.
65
	 */
66
	public function getReadOnly()
67
	{
68
		return $this->getViewState('ReadOnly',false);
69
	}
70
 
71
	/**
72
	 * @param boolean whether the items in the column can be edited
73
	 */
74
	public function setReadOnly($value)
75
	{
76
		$this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
77
	}
78
 
79
	/**
80
	 * Initializes the specified cell to its initial values.
81
	 * This method overrides the parent implementation.
82
	 * It creates a checkbox inside the cell.
83
	 * If the column is read-only or if the item is not in edit mode,
84
	 * the checkbox will be set disabled.
85
	 * @param TTableCell the cell to be initialized.
86
	 * @param integer the index to the Columns property that the cell resides in.
87
	 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
88
	 */
89
	public function initializeCell($cell,$columnIndex,$itemType)
90
	{
91
		if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
92
		{
93
			$checkBox=new TCheckBox;
94
			if($this->getReadOnly() || $itemType!==TListItemType::EditItem)
95
				$checkBox->setEnabled(false);
96
			$cell->setHorizontalAlign('Center');
97
			$cell->getControls()->add($checkBox);
98
			$cell->registerObject('CheckBox',$checkBox);
99
			if($this->getDataField()!=='')
100
				$checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
101
		}
102
		else
103
			parent::initializeCell($cell,$columnIndex,$itemType);
104
	}
105
 
106
	/**
107
	 * Databinds a cell in the column.
108
	 * This method is invoked when datagrid performs databinding.
109
	 * It populates the content of the cell with the relevant data from data source.
110
	 */
111
	public function dataBindColumn($sender,$param)
112
	{
113
		$item=$sender->getNamingContainer();
114
		$data=$item->getData();
115
		if(($field=$this->getDataField())!=='')
116
			$value=TPropertyValue::ensureBoolean($this->getDataFieldValue($data,$field));
117
		else
118
			$value=TPropertyValue::ensureBoolean($data);
119
		if($sender instanceof TCheckBox)
120
			$sender->setChecked($value);
121
	}
122
}
123