From 5a63c2c1989ed9fdcf8fbe00ec8161934768daf3 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Sat, 14 Jan 2006 03:30:53 +0000
Subject: Added TBaseDataList (nearly completed).
---
framework/Web/UI/WebControls/TRepeater.php | 89 +++++++++++++++---------------
1 file changed, 46 insertions(+), 43 deletions(-)
(limited to 'framework/Web/UI/WebControls/TRepeater.php')
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index d0d513b0..664faa68 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -48,6 +48,10 @@ class TRepeater extends TDataBoundControl implements INamingContainer
* Number of seconds that a cached template will expire after
*/
const CACHE_EXPIRY=18000;
+ /**
+ * @var array in-memory cache of parsed templates
+ */
+ private static $_templates=array();
/**
* @var string template for each item
*/
@@ -80,10 +84,6 @@ class TRepeater extends TDataBoundControl implements INamingContainer
* @var TRepeaterItem footer item
*/
private $_footer=null;
- /**
- * @var array in-memory cache of parsed templates
- */
- private static $_templates=array();
/**
* No body content should be added to repeater.
@@ -268,29 +268,32 @@ class TRepeater extends TDataBoundControl implements INamingContainer
break;
}
if($tplContent!=='')
+ $this->createTemplate($tplContent)->instantiateIn($item);
+ }
+
+ protected function createTemplate($str)
+ {
+ $key=md5($str);
+ $contextPath=$this->getTemplateControl()->getTemplate()->getContextPath();
+ if(($cache=$this->getApplication()->getCache())!==null)
{
- $key=md5($tplContent);
- $contextPath=$this->getTemplateControl()->getTemplate()->getContextPath();
- if(($cache=$this->getApplication()->getCache())!==null)
+ if(($template=$cache->get($key))===null)
{
- if(($template=$cache->get($key))===null)
- {
- $template=new TTemplate($tplContent,$contextPath);
- $cache->set($key,$template,self::CACHE_EXPIRY);
- }
+ $template=new TTemplate($str,$contextPath);
+ $cache->set($key,$template,self::CACHE_EXPIRY);
}
+ }
+ else
+ {
+ if(isset(self::$_templates[$key]))
+ $template=self::$_templates[$key];
else
{
- if(isset(self::$_templates[$key]))
- $template=self::$_templates[$key];
- else
- {
- $template=new TTemplate($tplContent,$contextPath);
- self::$_templates[$key]=$template;
- }
+ $template=new TTemplate($str,$contextPath);
+ self::$_templates[$key]=$template;
}
- $template->instantiateIn($item);
}
+ return $template;
}
/**
@@ -386,14 +389,35 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->setViewState('ItemCount',$itemIndex,0);
}
+ /**
+ * Handles BubbleEvent.
+ * This method overrides parent's implementation to handle
+ * {@link onItemCommand ItemCommand} event which is bubbled from
+ * {@link TRepeaterItem} child controls.
+ * This method should only be used by control developers.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ protected function onBubbleEvent($sender,$param)
+ {
+ if($param instanceof TRepeaterCommandEventParameter)
+ {
+ $this->onItemCommand($param);
+ return true;
+ }
+ else
+ return false;
+ }
+
/**
* Raises ItemCreated event.
* This method is invoked after a repeater item is created and instantiated with
* template, but before added to the page hierarchy.
* The {@link TRepeaterItem} control responsible for the event
+ * can be determined from the event parameter.
* If you override this method, be sure to call parent's implementation
* so that event handlers have chance to respond to the event.
- * can be determined from the event parameter.
* @param TRepeaterItemEventParameter event parameter
*/
protected function onItemCreated($param)
@@ -405,9 +429,9 @@ class TRepeater extends TDataBoundControl implements INamingContainer
* Raises ItemDataBound event.
* This method is invoked right after an item is data bound.
* The {@link TRepeaterItem} control responsible for the event
+ * can be determined from the event parameter.
* If you override this method, be sure to call parent's implementation
* so that event handlers have chance to respond to the event.
- * can be determined from the event parameter.
* @param TRepeaterItemEventParameter event parameter
*/
protected function onItemDataBound($param)
@@ -415,27 +439,6 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->raiseEvent('ItemDataBound',$this,$param);
}
- /**
- * Handles BubbleEvent.
- * This method overrides parent's implementation to handle
- * {@link onItemCommand ItemCommand} event which is bubbled from
- * {@link TRepeaterItem} child controls.
- * This method should only be used by control developers.
- * @param TControl the sender of the event
- * @param TEventParameter event parameter
- * @return boolean whether the event bubbling should stop here.
- */
- protected function onBubbleEvent($sender,$param)
- {
- if($param instanceof TRepeaterCommandEventParameter)
- {
- $this->onItemCommand($param);
- return true;
- }
- else
- return false;
- }
-
/**
* Raises ItemCommand event.
* This method is invoked after a button control in
--
cgit v1.2.3