[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TRadioButton class file 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TRadioButton.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Using TCheckBox parent class 15 */ 16 Prado::using('System.Web.UI.WebControls.TCheckBox'); 17 /** 18 * Using TRadioButtonList class 19 */ 20 Prado::using('System.Web.UI.WebControls.TRadioButtonList'); 21 22 /** 23 * TRadioButton class 24 * 25 * TRadioButton displays a radio button on the page. 26 * You can specify the caption to display beside the radio buttonby setting 27 * the {@link setText Text} property. The caption can appear either on the right 28 * or left of the radio button, which is determined by the {@link setTextAlign TextAlign} 29 * property. 30 * 31 * To determine whether the TRadioButton component is checked, test the {@link getChecked Checked} 32 * property. The {@link onCheckedChanged OnCheckedChanged} event is raised when 33 * the {@link getChecked Checked} state of the TRadioButton component changes 34 * between posts to the server. You can provide an event handler for 35 * the {@link onCheckedChanged OnCheckedChanged} event to to programmatically 36 * control the actions performed when the state of the TRadioButton component changes 37 * between posts to the server. 38 * 39 * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons. 40 * Once the {@link setGroupName GroupName} is set, you can use the {@link getRadioButtonsInGroup} 41 * method to get an array of TRadioButtons having the same group name. 42 * 43 * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state 44 * will cause postback action. And if {@link setCausesValidation CausesValidation} 45 * is true, validation will also be processed, which can be further restricted within 46 * a {@link setValidationGroup ValidationGroup}. 47 * 48 * Note, {@link setText Text} is rendered as is. Make sure it does not contain unwanted characters 49 * that may bring security vulnerabilities. 50 * 51 * @author Qiang Xue <qiang.xue@gmail.com> 52 * @version $Id: TRadioButton.php 1397 2006-09-07 07:55:53Z wei $ 53 * @package System.Web.UI.WebControls 54 * @since 3.0 55 */ 56 class TRadioButton extends TCheckBox 57 { 58 /** 59 * @param array list of radio buttons that are on the current page hierarchy 60 */ 61 private static $_activeButtons=array(); 62 /** 63 * @var integer number of radio buttons created 64 */ 65 private static $_buttonCount=0; 66 /** 67 * @var integer global ID of this radiobutton 68 */ 69 private $_globalID; 70 /** 71 * @var string previous UniqueID (used to calculate UniqueGroup) 72 */ 73 private $_previousUniqueID=null; 74 /** 75 * @var string the name used to fetch radiobutton post data 76 */ 77 private $_uniqueGroupName=null; 78 79 /** 80 * Constructor. 81 * Registers the radiobutton in a global radiobutton collection. 82 * If overridden, the parent implementation must be invoked first. 83 */ 84 public function __construct() 85 { 86 parent::__construct(); 87 $this->_globalID = self::$_buttonCount++; 88 } 89 90 /** 91 * Registers the radio button groupings. If overriding onInit method, 92 * ensure to call parent implemenation. 93 * @param TEventParameter event parameter to be passed to the event handlers 94 */ 95 public function onInit($param) 96 { 97 parent::onInit($param); 98 self::$_activeButtons[$this->_globalID]=$this; 99 } 100 101 /** 102 * Unregisters the radio button groupings. If overriding onInit method, 103 * ensure to call parent implemenation. 104 * @param TEventParameter event parameter to be passed to the event handlers 105 */ 106 public function onUnLoad($param) 107 { 108 unset(self::$_activeButtons[$this->_globalID]); 109 parent::onUnLoad($param); 110 } 111 112 /** 113 * Loads user input data. 114 * This method is primarly used by framework developers. 115 * @param string the key that can be used to retrieve data from the input data collection 116 * @param array the input data collection 117 * @return boolean whether the data of the control has been changed 118 */ 119 public function loadPostData($key,$values) 120 { 121 $uniqueGroupName=$this->getUniqueGroupName(); 122 $value=isset($values[$uniqueGroupName])?$values[$uniqueGroupName]:null; 123 if($value!==null && $value===$this->getValueAttribute()) 124 { 125 if(!$this->getChecked()) 126 { 127 $this->setChecked(true); 128 return true; 129 } 130 else 131 return false; 132 } 133 else if($this->getChecked()) 134 $this->setChecked(false); 135 return false; 136 } 137 138 /** 139 * @return string the name of the group that the radio button belongs to. Defaults to empty. 140 */ 141 public function getGroupName() 142 { 143 return $this->getViewState('GroupName',''); 144 } 145 146 /** 147 * Sets the name of the group that the radio button belongs to. 148 * The group is unique among the control's naming container. 149 * @param string the group name 150 * @see setUniqueGroupName 151 */ 152 public function setGroupName($value) 153 { 154 $this->setViewState('GroupName',$value,''); 155 $this->_uniqueGroupName=null; 156 } 157 158 /** 159 * @return string the name used to fetch radiobutton post data 160 */ 161 public function getUniqueGroupName() 162 { 163 if(($groupName=$this->getViewState('UniqueGroupName',''))!=='') 164 return $groupName; 165 else if(($uniqueID=$this->getUniqueID())!==$this->_previousUniqueID || $this->_uniqueGroupName===null) 166 { 167 $groupName=$this->getGroupName(); 168 $this->_previousUniqueID=$uniqueID; 169 if($uniqueID!=='') 170 { 171 if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false) 172 { 173 if($groupName!=='') 174 $groupName=substr($uniqueID,0,$pos+1).$groupName; 175 else if($this->getNamingContainer() instanceof TRadioButtonList) 176 $groupName=substr($uniqueID,0,$pos); 177 } 178 if($groupName==='') 179 $groupName=$uniqueID; 180 } 181 $this->_uniqueGroupName=$groupName; 182 } 183 return $this->_uniqueGroupName; 184 } 185 186 /** 187 * Sets the unique group name that the radio button belongs to. 188 * A unique group is a radiobutton group unique among the whole page hierarchy, 189 * while the {@link setGroupName GroupName} specifies a group that is unique 190 * among the control's naming container only. 191 * For example, each cell of a {@link TDataGrid} is a naming container. 192 * If you specify {@link setGroupName GroupName} for a radiobutton in a cell, 193 * it groups together radiobutton within a cell, but not the other, even though 194 * they have the same {@link setGroupName GroupName}. 195 * On the contratry, if {@link setUniqueGroupName UniqueGroupName} is used instead, 196 * it will group all appropriate radio buttons on the whole page hierarchy. 197 * Note, when both {@link setUniqueGroupName UniqueGroupName} and 198 * {@link setGroupName GroupName}, the former takes precedence. 199 * @param string the group name 200 * @see setGroupName 201 */ 202 public function setUniqueGroupName($value) 203 { 204 $this->setViewState('UniqueGroupName',$value,''); 205 } 206 207 /** 208 * Gets an array of radiobuttons whose group name is the same as this radiobutton's. 209 * Note, only those radiobuttons that are on the current page hierarchy may be 210 * returned in the result. 211 * @return array list of TRadioButton with the same group 212 */ 213 public function getRadioButtonsInGroup() 214 { 215 $group = $this->getUniqueGroupName(); 216 $buttons = array(); 217 foreach(self::$_activeButtons as $control) 218 { 219 if($control->getUniqueGroupName() === $group) 220 $buttons[] = $control; 221 } 222 return $buttons; 223 } 224 225 /** 226 * @return string the value attribute to be rendered 227 */ 228 protected function getValueAttribute() 229 { 230 if(($value=parent::getValueAttribute())==='') 231 return $this->getUniqueID(); 232 else 233 return $value; 234 } 235 236 /** 237 * Renders a radiobutton input element. 238 * @param THtmlWriter the writer for the rendering purpose 239 * @param string checkbox id 240 * @param string onclick js 241 */ 242 protected function renderInputTag($writer,$clientID,$onclick) 243 { 244 if($clientID!=='') 245 $writer->addAttribute('id',$clientID); 246 $writer->addAttribute('type','radio'); 247 $writer->addAttribute('name',$this->getUniqueGroupName()); 248 $writer->addAttribute('value',$this->getValueAttribute()); 249 if($onclick!=='') 250 $writer->addAttribute('onclick',$onclick); 251 if($this->getChecked()) 252 $writer->addAttribute('checked','checked'); 253 if(!$this->getEnabled(true)) 254 $writer->addAttribute('disabled','disabled'); 255 256 $page=$this->getPage(); 257 if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript()) 258 $page->getClientScript()->registerPostBackControl('Prado.WebUI.TRadioButton',$this->getPostBackOptions()); 259 260 if(($accesskey=$this->getAccessKey())!=='') 261 $writer->addAttribute('accesskey',$accesskey); 262 if(($tabindex=$this->getTabIndex())>0) 263 $writer->addAttribute('tabindex',"$tabindex"); 264 if($attributes=$this->getViewState('InputAttributes',null)) 265 $writer->addAttributes($attributes); 266 $writer->renderBeginTag('input'); 267 $writer->renderEndTag(); 268 } 269 } 270 271 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |