From cba0c1b472cec22e4ffed2b3b084bea27cd26582 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Fri, 17 Feb 2006 21:14:12 +0000
Subject: Fixed #54.
---
framework/Collections/TList.php | 4 ++
framework/Exceptions/messages.txt | 8 ++++
framework/Web/UI/TControl.php | 2 +
framework/Web/UI/TTemplateControl.php | 44 +++++++++++++---------
framework/Web/UI/WebControls/TContent.php | 2 +-
.../Web/UI/WebControls/TContentPlaceHolder.php | 5 +--
.../tickets/protected/pages/Ticket54Master.tpl | 2 +-
.../tickets/tests/Ticket54TestCase.php | 2 +-
8 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php
index 7383b684..3480edc3 100644
--- a/framework/Collections/TList.php
+++ b/framework/Collections/TList.php
@@ -132,12 +132,16 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess
* The list will first search for the item.
* The first item found will be removed from the list.
* @param mixed the item to be removed.
+ * @return integer the index at which the item is being removed
* @throws TInvalidDataValueException If the item does not exist
*/
public function remove($item)
{
if(($index=$this->indexOf($item))>=0)
+ {
$this->removeAt($index);
+ return $index;
+ }
else
throw new TInvalidDataValueException('list_item_inexistent');
}
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index d5b3eb83..dc5024a7 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -147,6 +147,14 @@ control_enabletheming_unchangeable = %s.EnableTheming cannot be modified after
control_stylesheet_applied = StyleSheet skin has already been applied to %s.
control_id_nonunique = %s.ID '%s' is not unique among all controls under the same naming container.
+templatecontrol_mastercontrol_invalid = Master control must be of type TTemplateControl or a child class.
+templatecontrol_contentid_duplicated = TContent ID '%s' is duplicated.
+templatecontrol_placeholderid_duplicated= TContentPlaceHolder ID '%s' is duplicated.
+
+contentplaceholder_id_required = TContentPlaceHolder must have an ID.
+
+content_id_required = TContent must have an ID.
+
controllist_control_required = TControlList can only accept strings or TControl objects.
emptycontrollist_addition_disallowed = Child controls are not allowed.
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index d1ae189a..dbe4a233 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -1053,6 +1053,8 @@ class TControl extends TApplicationComponent
$control->_stage=self::CS_CONSTRUCTED;
if(!($control->_flags & self::IS_ID_SET))
$control->_id='';
+ else
+ unset($this->_rf[self::RF_NAMED_OBJECTS][$control->_id]);
$control->clearCachedUniqueID(true);
}
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index d6ccb825..2d6829ee 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -135,11 +135,29 @@ class TTemplateControl extends TControl implements INamingContainer
/**
* Registers a content control.
+ * @param string ID of the content
* @param TContent
*/
- public function registerContent(TContent $object)
+ public function registerContent($id,TContent $object)
{
- $this->_contents[$object->getID()]=$object;
+ if(isset($this->_contents[$id]))
+ throw new TConfigurationException('templatecontrol_contentid_duplicated',$id);
+ else
+ $this->_contents[$id]=$object;
+ }
+
+ /**
+ * Registers a content placeholder to this template control.
+ * This method should only be used by framework and control developers.
+ * @param string placeholder ID
+ * @param TContentPlaceHolder placeholder control
+ */
+ public function registerContentPlaceHolder($id,TContentPlaceHolder $object)
+ {
+ if(isset($this->_contents[$id]))
+ throw new TConfigurationException('templatecontrol_placeholderid_duplicated',$id);
+ else
+ $this->_placeholders[$id]=$object;
}
/**
@@ -166,18 +184,6 @@ class TTemplateControl extends TControl implements INamingContainer
return $this->_master;
}
- /**
- * Registers a content placeholder to this template control.
- * This method should only be used by framework and control developers.
- * @param string ID of the placeholder
- * @param TControl control that directly enloses the placeholder
- * @param integer the index in the control list of the parent control that the placeholder is at
- */
- public function registerContentPlaceHolder($id,$parent,$loc)
- {
- $this->_placeholders[$id]=array($parent,$loc);
- }
-
/**
* Injects all content controls (and their children) to the corresponding content placeholders.
* This method should only be used by framework and control developers.
@@ -188,8 +194,12 @@ class TTemplateControl extends TControl implements INamingContainer
{
if(isset($this->_placeholders[$id]))
{
- list($parent,$loc)=$this->_placeholders[$id];
- $parent->getControls()->insertAt($loc,$content);
+ $placeholder=$this->_placeholders[$id];
+ $controls=$placeholder->getParent()->getControls();
+ $loc=$controls->remove($placeholder);
+ $controls->insertAt($loc,$content);
+ //list($parent,$loc)=$this->_placeholders[$id];
+ //$parent->getControls()->insertAt($loc,$content);
}
}
@@ -208,7 +218,7 @@ class TTemplateControl extends TControl implements INamingContainer
{
$master=Prado::createComponent($this->_masterClass);
if(!($master instanceof TTemplateControl))
- throw new TInvalidDataValueException('tplcontrol_required',get_class($master));
+ throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid');
$this->_master=$master;
$this->getControls()->clear();
$this->getControls()->add($master);
diff --git a/framework/Web/UI/WebControls/TContent.php b/framework/Web/UI/WebControls/TContent.php
index f2c6f0ac..0ccc57f8 100644
--- a/framework/Web/UI/WebControls/TContent.php
+++ b/framework/Web/UI/WebControls/TContent.php
@@ -41,7 +41,7 @@ class TContent extends TControl implements INamingContainer
{
if(($id=$this->getID())==='')
throw new TConfigurationException('content_id_required');
- $this->getTemplateControl()->registerContent($this);
+ $this->getTemplateControl()->registerContent($id,$this);
}
}
diff --git a/framework/Web/UI/WebControls/TContentPlaceHolder.php b/framework/Web/UI/WebControls/TContentPlaceHolder.php
index a13e85bc..9cf5068c 100644
--- a/framework/Web/UI/WebControls/TContentPlaceHolder.php
+++ b/framework/Web/UI/WebControls/TContentPlaceHolder.php
@@ -41,9 +41,8 @@ class TContentPlaceHolder extends TControl
{
if(($id=$this->getID())==='')
throw new TConfigurationException('contentplaceholder_id_required');
- $loc=$parent->getHasControls()?$parent->getControls()->getCount():0;
- $this->getTemplateControl()->registerContentPlaceHolder($id,$parent,$loc);
- $parent->unregisterObject($id);
+ $this->getTemplateControl()->registerContentPlaceHolder($id,$this);
+ $parent->getControls()->add($this);
}
}
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket54Master.tpl b/tests/FunctionalTests/tickets/protected/pages/Ticket54Master.tpl
index af57b6c7..5838aa5b 100644
--- a/tests/FunctionalTests/tickets/protected/pages/Ticket54Master.tpl
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket54Master.tpl
@@ -1 +1 @@
-||||||
+||a||b||
diff --git a/tests/FunctionalTests/tickets/tests/Ticket54TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket54TestCase.php
index c131a67d..1698f1cb 100644
--- a/tests/FunctionalTests/tickets/tests/Ticket54TestCase.php
+++ b/tests/FunctionalTests/tickets/tests/Ticket54TestCase.php
@@ -5,7 +5,7 @@ class Ticket54TestCase extends SeleniumTestCase
function test()
{
$this->open('tickets/index.php?page=Ticket54');
- $this->verifyTextPresent("|A||B||C|", "");
+ $this->verifyTextPresent("|A|a|B|b|C|", "");
}
}
--
cgit v1.2.3