]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/THyperLink.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / THyperLink.php
1 <?php
2 /**
3  * THyperLink class file.
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link http://www.xisc.com/
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * THyperLink class
14  *
15  * THyperLink displays a hyperlink on a page. The hyperlink URL is specified
16  * via the {@link setNavigateUrl NavigateUrl} property, and link text is via
17  * the {@link setText Text} property. It is also possible to display an image
18  * by setting the {@link setImageUrl ImageUrl} property. In this case,
19  * the alignment of the image displayed is set by the
20  * {@link setImageAlign ImageAlign} property and {@link getText Text} is
21  * displayed as the alternate text of the image.
22  *
23  * The link target is specified via the {@link setTarget Target} property.
24  * If both {@link getImageUrl ImageUrl} and {@link getText Text} are empty,
25  * the content enclosed within the control tag will be rendered.
26  *
27  * @author Qiang Xue <qiang.xue@gmail.com>
28  * @package System.Web.UI.WebControls
29  * @since 3.0
30  */
31 class THyperLink extends TWebControl implements IDataRenderer
32 {
33         /**
34          * @return string tag name of the hyperlink
35          */
36         protected function getTagName()
37         {
38                 return 'a';
39         }
40
41         /**
42          * Adds attributes related to a hyperlink element to renderer.
43          * @param THtmlWriter the writer used for the rendering purpose
44          */
45         protected function addAttributesToRender($writer)
46         {
47                 $isEnabled=$this->getEnabled(true);
48                 if($this->getEnabled() && !$isEnabled)
49                         $writer->addAttribute('disabled','disabled');
50                 parent::addAttributesToRender($writer);
51                 if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
52                         $writer->addAttribute('href',$url);
53                 if(($target=$this->getTarget())!=='')
54                         $writer->addAttribute('target',$target);
55         }
56
57         /**
58          * Renders the body content of the hyperlink.
59          * @param THtmlWriter the writer for rendering
60          */
61         public function renderContents($writer)
62         {
63                 if(($imageUrl=$this->getImageUrl())==='')
64                 {
65                         if(($text=$this->getText())!=='')
66                                 $writer->write(THttpUtility::htmlEncode($text));
67                         else if($this->getHasControls())
68                                 parent::renderContents($writer);
69                         else
70                                 $writer->write(THttpUtility::htmlEncode($this->getNavigateUrl()));
71                 }
72                 else
73                 {
74                         $this->createImage($imageUrl)->renderControl($writer);
75                 }
76         }
77
78         /**
79          * Gets the TImage for rendering the ImageUrl property. This is not for
80          * creating dynamic images.
81          * @param string image url.
82          * @return TImage image control for rendering.
83          */
84         protected function createImage($imageUrl)
85         {
86                 $image=Prado::createComponent('System.Web.UI.WebControls.TImage');
87                 $image->setImageUrl($imageUrl);
88                 if(($width=$this->getImageWidth())!=='')
89                         $image->setWidth($width);
90                 if(($height=$this->getImageHeight())!=='')
91                         $image->setHeight($height);
92                 if(($toolTip=$this->getToolTip())!=='')
93                         $image->setToolTip($toolTip);
94                 if(($text=$this->getText())!=='')
95                         $image->setAlternateText($text);
96                 if(($align=$this->getImageAlign())!=='')
97                         $image->setImageAlign($align);
98                 $image->setBorderWidth('0');
99                 return $image;
100         }
101
102         /**
103          * @return string the text caption of the THyperLink
104          */
105         public function getText()
106         {
107                 return $this->getViewState('Text','');
108         }
109
110         /**
111          * Sets the text caption of the THyperLink.
112          * @param string the text caption to be set
113          */
114         public function setText($value)
115         {
116                 $this->setViewState('Text',$value,'');
117         }
118
119         /**
120          * @return string the alignment of the image with respective to other elements on the page, defaults to empty.
121          */
122         public function getImageAlign()
123         {
124                 return $this->getViewState('ImageAlign','');
125         }
126
127         /**
128          * Sets the alignment of the image with respective to other elements on the page.
129          * Possible values include: absbottom, absmiddle, baseline, bottom, left,
130          * middle, right, texttop, and top. If an empty string is passed in,
131          * imagealign attribute will not be rendered.
132          * @param string the alignment of the image
133          */
134         public function setImageAlign($value)
135         {
136                 $this->setViewState('ImageAlign',$value,'');
137         }
138
139         /**
140          * @return string height of the image in the THyperLink
141          */
142         public function getImageHeight()
143         {
144                 return $this->getViewState('ImageHeight','');
145         }
146
147         /**
148          * Sets the height of the image in the THyperLink
149          * @param string height of the image in the THyperLink
150          */
151         public function setImageHeight($value)
152         {
153                 $this->setViewSTate('ImageHeight',$value,'');
154         }
155
156         /**
157          * @return string the location of the image file for the THyperLink
158          */
159         public function getImageUrl()
160         {
161                 return $this->getViewState('ImageUrl','');
162         }
163
164         /**
165          * Sets the location of image file of the THyperLink.
166          * @param string the image file location
167          */
168         public function setImageUrl($value)
169         {
170                 $this->setViewState('ImageUrl',$value,'');
171         }
172
173         /**
174          * @return string width of the image in the THyperLink
175          */
176         public function getImageWidth()
177         {
178                 return $this->getViewState('ImageWidth','');
179         }
180
181         /**
182          * Sets the width of the image in the THyperLink
183          * @param string width of the image
184          */
185         public function setImageWidth($value)
186         {
187                 $this->setViewState('ImageWidth',$value,'');
188         }
189
190         /**
191          * @return string the URL to link to when the THyperLink component is clicked.
192          */
193         public function getNavigateUrl()
194         {
195                 return $this->getViewState('NavigateUrl','');
196         }
197
198         /**
199          * Sets the URL to link to when the THyperLink component is clicked.
200          * @param string the URL
201          */
202         public function setNavigateUrl($value)
203         {
204                 $this->setViewState('NavigateUrl',$value,'');
205         }
206
207         /**
208          * Returns the URL to link to when the THyperLink component is clicked.
209          * This method is required by {@link IDataRenderer}.
210          * It is the same as {@link getText()}.
211          * @return string the text caption
212          * @see getText
213          * @since 3.1.0
214          */
215         public function getData()
216         {
217                 return $this->getText();
218         }
219
220         /**
221          * Sets the URL to link to when the THyperLink component is clicked.
222          * This method is required by {@link IDataRenderer}.
223          * It is the same as {@link setText()}.
224          * @param string the text caption to be set
225          * @see setText
226          * @since 3.1.0
227          */
228         public function setData($value)
229         {
230                 $this->setText($value);
231         }
232
233         /**
234          * @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
235          */
236         public function getTarget()
237         {
238                 return $this->getViewState('Target','');
239         }
240
241         /**
242          * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
243          * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
244          */
245         public function setTarget($value)
246         {
247                 $this->setViewState('Target',$value,'');
248         }
249 }
250