From a494b2151b0d9f11f0f16fd4ed8b5340d6735324 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 16 Jul 2006 01:46:08 +0000 Subject: Fixed #277. --- framework/Web/UI/TControl.php | 22 +++++++++ framework/Web/UI/WebControls/TRadioButton.php | 66 +++++++++++---------------- 2 files changed, 48 insertions(+), 40 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 583b5f77..ff4a85ea 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -451,6 +451,28 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable $this->_flags |= self::IS_DISABLE_THEMING; } + /** + * Returns custom data associated with this control. + * A control may be associated with some custom data for various purposes. + * For example, a button may be associated with a string to identify itself + * in a generic OnClick event handler. + * @return mixed custom data associated with this control. Defaults to null. + */ + public function getCustomData() + { + return $this->getViewState('CustomData',null); + } + + /** + * Associates custom data with this control. + * Note, the custom data must be serializable and unserializable. + * @param mixed custom data + */ + public function setCustomData($value) + { + $this->getViewState('CustomData',$value,null); + } + /** * @return boolean whether the control has child controls */ diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index 99e822cf..7096647b 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -56,39 +56,44 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList'); class TRadioButton extends TCheckBox { /** - * @param array list of radio buttons registered. + * @param array list of radio buttons that are on the current page hierarchy */ - private static $_radiobuttons=array(); + private static $_activeButtons=array(); /** - * @var string the name used to fetch radiobutton post data + * @var integer number of radio buttons created */ - private $_uniqueGroupName=null; + private static $_buttonCount=0; /** - * @var int number radio buttons created + * @var integer global ID of this radiobutton */ - private static $_counter=0; + private $_globalID; /** - * @var int unique unmutable radio button id + * @var string the name used to fetch radiobutton post data */ - private $_radioUid; + private $_uniqueGroupName=null; + /** + * Constructor. + * Registers the radiobutton in a global radiobutton collection. + * If overridden, the parent implementation must be invoked first. + */ public function __construct() { parent::__construct(); - $this->_radioUid = self::$_counter++; + $this->_globalID = self::$_buttonCount++; } - + /** - * Registers the radio button groupings. If overriding onInit method, + * Registers the radio button groupings. If overriding onInit method, * ensure to call parent implemenation. * @param TEventParameter event parameter to be passed to the event handlers */ public function onInit($param) { parent::onInit($param); - $this->registerRadioButton($this); + self::$_activeButtons[$this->_globalID]=$this; } - + /** * Unregisters the radio button groupings. If overriding onInit method, * ensure to call parent implemenation. @@ -96,10 +101,10 @@ class TRadioButton extends TCheckBox */ public function onUnLoad($param) { + unset(self::$_activeButtons[$this->_globalID]); parent::onUnLoad($param); - $this->unregisterRadioButton($this); } - + /** * Loads user input data. * This method is primarly used by framework developers. @@ -142,42 +147,23 @@ class TRadioButton extends TCheckBox { $this->setViewState('GroupName',$value,''); } - - /** - * Register radio button control grouping. - * @param TRadioButton control to add - */ - protected function registerRadioButton(TRadioButton $control) - { - if(!isset(self::$_radiobuttons[$control->_radioUid])) - self::$_radiobuttons[$control->_radioUid] = $control; - } - + /** - * Unregister radio button control for grouping - * @param TRadioButton control to unregister. - */ - protected function unregisterRadioButton(TRadioButton $control) - { - if(isset(self::$_radiobuttons[$control->_radioUid])) - unset(self::$_radiobuttons[$control->_radioUid]); - } - - /** - * Gets an array of RadioButtons with same group name. This method will - * always return at least the current radio button in the array. + * Gets an array of radiobuttons whose group name is the same as this radiobutton's. + * Note, only those radiobuttons that are on the current page hierarchy may be + * returned in the result. * @return array list of TRadioButton with the same group */ public function getRadioButtonsInGroup() { $group = $this->getUniqueGroupName(); $buttons = array(); - foreach(self::$_radiobuttons as $control) + foreach(self::$_activeButtons as $control) { if($control->getUniqueGroupName() === $group) $buttons[] = $control; } - return count($buttons) > 0 ? $buttons : array($this); + return $buttons; } /** -- cgit v1.2.3