summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2006-07-16 01:46:08 +0000
committerxue <>2006-07-16 01:46:08 +0000
commita494b2151b0d9f11f0f16fd4ed8b5340d6735324 (patch)
tree05f4601db44f7ac82c8713094199970d018bfcaf /framework
parent26c3775697fc94086269d54099576679137e5eda (diff)
Fixed #277.
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/UI/TControl.php22
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php66
2 files changed, 48 insertions, 40 deletions
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
@@ -452,6 +452,28 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable
}
/**
+ * 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
*/
public function getHasControls()
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;
}
/**