summaryrefslogtreecommitdiff
path: root/lib/prado/framework/Web/UI/WebControls/THyperLinkColumn.php
blob: 2c7590e7df497b5a9f81005f61fd287ba363035f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php
/**
 * THyperLinkColumn class file
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @package System.Web.UI.WebControls
 */

/**
 * TDataGridColumn class file
 */
Prado::using('System.Web.UI.WebControls.TDataGridColumn');
/**
 * THyperLink class file
 */
Prado::using('System.Web.UI.WebControls.THyperLink');

/**
 * THyperLinkColumn class
 *
 * THyperLinkColumn contains a hyperlink for each item in the column.
 * You can set the text and the url of the hyperlink by {@link setText Text}
 * and {@link setNavigateUrl NavigateUrl} properties, respectively.
 * You can also bind the text and url to specific data field in datasource
 * by setting {@link setDataTextField DataTextField} and
 * {@link setDataNavigateUrlField DataNavigateUrlField}.
 * Both can be formatted before rendering according to the
 * {@link setDataTextFormatString DataTextFormatString} and
 * and {@link setDataNavigateUrlFormatString DataNavigateUrlFormatString}
 * properties, respectively. If both {@link setText Text} and {@link setDataTextField DataTextField}
 * are present, the latter takes precedence.
 * The same rule applies to {@link setNavigateUrl NavigateUrl} and
 * {@link setDataNavigateUrlField DataNavigateUrlField} properties.
 *
 * The hyperlinks in the column can be accessed by one of the following two methods:
 * <code>
 * $datagridItem->HyperLinkColumnID->HyperLink
 * $datagridItem->HyperLinkColumnID->Controls[0]
 * </code>
 * The second method is possible because the hyperlink control created within the
 * datagrid cell is the first child.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package System.Web.UI.WebControls
 * @since 3.0
 */
class THyperLinkColumn extends TDataGridColumn
{
	/**
	 * @return string the text caption of the hyperlink
	 */
	public function getText()
	{
		return $this->getViewState('Text','');
	}

	/**
	 * Sets the text caption of the hyperlink.
	 * @param string the text caption to be set
	 */
	public function setText($value)
	{
		$this->setViewState('Text',$value,'');
	}

	/**
	 * @return string the field name from the data source to bind to the hyperlink caption
	 */
	public function getDataTextField()
	{
		return $this->getViewState('DataTextField','');
	}

	/**
	 * @param string the field name from the data source to bind to the hyperlink caption
	 */
	public function setDataTextField($value)
	{
		$this->setViewState('DataTextField',$value,'');
	}

	/**
	 * @return string the formatting string used to control how the hyperlink caption will be displayed.
	 */
	public function getDataTextFormatString()
	{
		return $this->getViewState('DataTextFormatString','');
	}

	/**
	 * @param string the formatting string used to control how the hyperlink caption will be displayed.
	 */
	public function setDataTextFormatString($value)
	{
		$this->setViewState('DataTextFormatString',$value,'');
	}

	/**
	 * @return string height of the image in the THyperLink
	 */
	public function getImageHeight()
	{
		return $this->getViewState('ImageHeight','');
	}

	/**
	 * @param string height of the image in the THyperLink
	 */
	public function setImageHeight($value)
	{
		$this->setViewState('ImageHeight',$value,'');
	}

	/**
	 * @return string url of the image in the THyperLink
	 */
	public function getImageUrl()
	{
		return $this->getViewState('ImageUrl','');
	}

	/**
	 * @param string url of the image in the THyperLink
	 */
	public function setImageUrl($value)
	{
		$this->setViewState('ImageUrl',$value,'');
	}

	/**
	 * @return string width of the image in the THyperLink
	 */
	public function getImageWidth()
	{
		return $this->getViewState('ImageWidth','');
	}

	/**
	 * @param string width of the image in the THyperLink
	 */
	public function setImageWidth($value)
	{
		$this->setViewState('ImageWidth',$value,'');
	}

	/**
	 * @return string the URL to link to when the hyperlink is clicked.
	 */
	public function getNavigateUrl()
	{
		return $this->getViewState('NavigateUrl','');
	}

	/**
	 * Sets the URL to link to when the hyperlink is clicked.
	 * @param string the URL
	 */
	public function setNavigateUrl($value)
	{
		$this->setViewState('NavigateUrl',$value,'');
	}

	/**
	 * @return string the field name from the data source to bind to the navigate url of hyperlink
	 */
	public function getDataNavigateUrlField()
	{
		return $this->getViewState('DataNavigateUrlField','');
	}

	/**
	 * @param string the field name from the data source to bind to the navigate url of hyperlink
	 */
	public function setDataNavigateUrlField($value)
	{
		$this->setViewState('DataNavigateUrlField',$value,'');
	}

	/**
	 * @return string the formatting string used to control how the navigate url of hyperlink will be displayed.
	 */
	public function getDataNavigateUrlFormatString()
	{
		return $this->getViewState('DataNavigateUrlFormatString','');
	}

	/**
	 * @param string the formatting string used to control how the navigate url of hyperlink will be displayed.
	 */
	public function setDataNavigateUrlFormatString($value)
	{
		$this->setViewState('DataNavigateUrlFormatString',$value,'');
	}

	/**
	 * @return string the target window or frame to display the Web page content linked to when the hyperlink is clicked.
	 */
	public function getTarget()
	{
		return $this->getViewState('Target','');
	}

	/**
	 * Sets the target window or frame to display the Web page content linked to when the hyperlink is clicked.
	 * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
	 */
	public function setTarget($value)
	{
		$this->setViewState('Target',$value,'');
	}

	/**
	 * Initializes the specified cell to its initial values.
	 * This method overrides the parent implementation.
	 * It creates a hyperlink within the cell.
	 * @param TTableCell the cell to be initialized.
	 * @param integer the index to the Columns property that the cell resides in.
	 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
	 */
	public function initializeCell($cell,$columnIndex,$itemType)
	{
		if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
		{
			$link=new THyperLink;
			if(($url = $this->getImageUrl())!=='')
			{
				$link->setImageUrl($url);
				if(($width=$this->getImageWidth())!=='')
					$link->setImageWidth($width);
				if(($height=$this->getImageHeight())!=='')
					$link->setImageHeight($height);
			}
			$link->setText($this->getText());
			$link->setNavigateUrl($this->getNavigateUrl());
			$link->setTarget($this->getTarget());
			if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='')
				$link->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
			$cell->getControls()->add($link);
			$cell->registerObject('HyperLink',$link);
		}
		else
			parent::initializeCell($cell,$columnIndex,$itemType);
	}

	/**
	 * Databinds a cell in the column.
	 * This method is invoked when datagrid performs databinding.
	 * It populates the content of the cell with the relevant data from data source.
	 */
	public function dataBindColumn($sender,$param)
	{
		$item=$sender->getNamingContainer();
		$data=$item->getData();
		if(($field=$this->getDataTextField())!=='')
		{
			$value=$this->getDataFieldValue($data,$field);
			$text=$this->formatDataValue($this->getDataTextFormatString(),$value);
			$sender->setText($text);
		}
		if(($field=$this->getDataNavigateUrlField())!=='')
		{
			$value=$this->getDataFieldValue($data,$field);
			$url=$this->formatDataValue($this->getDataNavigateUrlFormatString(),$value);
			$sender->setNavigateUrl($url);
		}
	}
}