summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-01-29 16:41:43 +0000
committerxue <>2006-01-29 16:41:43 +0000
commitd1eaf452f7627a8425f551250cb07fe55658c7c4 (patch)
tree54e4c7811f42c04988b5cd875bdc86c2e345286f
parentf5c23c03d83fad290841df0fba45ec9d83c8a3a6 (diff)
Modified TRepeater, TDataList and TTemplateColumn to make use of the new template parsing logic.
-rw-r--r--framework/Exceptions/messages.txt6
-rw-r--r--framework/Web/UI/WebControls/TDataList.php177
-rw-r--r--framework/Web/UI/WebControls/TRepeater.php140
-rw-r--r--framework/Web/UI/WebControls/TTemplateColumn.php102
4 files changed, 187 insertions, 238 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index 602efcdd..69015d48 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -185,4 +185,8 @@ basevalidator_associatedcontrolid_unsupported = TBaseValidator.AssociatedControl
basevalidator_controltovalidate_invalid = TBaseValidator.ControlToValidate is empty or contains an invalid control ID path.
basevalidator_validatable_required = TBaseValidator.ControlToValidate must point to a control implementing IValidatable interface.
-comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path. \ No newline at end of file
+comparevalidator_controltocompare_invalid = TCompareValidator.ControlToCompare contains an invalid control ID path.
+
+repeater_template_required = TRepeater.%s requires a template instance implementing ITemplate interface.
+datalist_template_required = TDataList.%s requires a template instance implementing ITemplate interface.
+templatecolumn_template_required = TTemplateColumn.%s requires a template instance implementing ITemplate interface. \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php
index 38045f77..c0d74974 100644
--- a/framework/Web/UI/WebControls/TDataList.php
+++ b/framework/Web/UI/WebControls/TDataList.php
@@ -94,27 +94,19 @@ Prado::using('System.Web.UI.WebControls.TRepeatInfo');
class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUser
{
/**
- * 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 TDataListItemCollection item list
*/
private $_items=null;
/**
- * @var string Various item templates
+ * @var Itemplate various item templates
*/
- private $_itemTemplate='';
- private $_alternatingItemTemplate='';
- private $_selectedItemTemplate='';
- private $_editItemTemplate='';
- private $_headerTemplate='';
- private $_footerTemplate='';
- private $_separatorTemplate='';
+ private $_itemTemplate=null;
+ private $_alternatingItemTemplate=null;
+ private $_selectedItemTemplate=null;
+ private $_editItemTemplate=null;
+ private $_headerTemplate=null;
+ private $_footerTemplate=null;
+ private $_separatorTemplate=null;
/**
* @var TDatListItem header item
*/
@@ -143,7 +135,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return string the template for item
+ * @return ITemplate the template for item
*/
public function getItemTemplate()
{
@@ -151,11 +143,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the template for item
+ * @param ITemplate the template for item
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setItemTemplate($value)
{
- $this->_itemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','ItemTemplate');
}
/**
@@ -172,7 +168,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return string the template for each alternating item
+ * @return ITemplate the template for each alternating item
*/
public function getAlternatingItemTemplate()
{
@@ -180,11 +176,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the template for each alternating item
+ * @param ITemplate the template for each alternating item
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setAlternatingItemTemplate($value)
{
- $this->_alternatingItemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_alternatingItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','AlternatingItemType');
}
/**
@@ -201,7 +201,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return TTableItemStyle the selected item template string
+ * @return ITemplate the selected item template
*/
public function getSelectedItemTemplate()
{
@@ -209,11 +209,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the selected item template
+ * @param ITemplate the selected item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setSelectedItemTemplate($value)
{
- $this->_selectedItemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_selectedItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','SelectedItemTemplate');
}
/**
@@ -230,7 +234,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return string the edit item template string
+ * @return ITemplate the edit item template
*/
public function getEditItemTemplate()
{
@@ -238,11 +242,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the edit item template
+ * @param ITemplate the edit item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setEditItemTemplate($value)
{
- $this->_editItemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_editItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','EditItemTemplate');
}
/**
@@ -259,7 +267,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return string the header template string
+ * @return ITemplate the header template
*/
public function getHeaderTemplate()
{
@@ -267,11 +275,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the header template
+ * @param ITemplate the header template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setHeaderTemplate($value)
{
- $this->_headerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','HeaderTemplate');
}
/**
@@ -296,7 +308,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return string the footer template string
+ * @return ITemplate the footer template
*/
public function getFooterTemplate()
{
@@ -304,11 +316,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the footer template
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setFooterTemplate($value)
{
- $this->_footerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','FooterTemplate');
}
/**
@@ -333,7 +349,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @return TTableItemStyle the separator template string
+ * @return ITemplate the separator template
*/
public function getSeparatorTemplate()
{
@@ -341,11 +357,15 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
}
/**
- * @param string the separator template
+ * @param ITemplate the separator template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setSeparatorTemplate($value)
{
- $this->_separatorTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_separatorTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('datalist_template_required','SeparatorTemplate');
}
/**
@@ -742,7 +762,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
*/
public function getHasHeader()
{
- return ($this->getShowHeader() && $this->_headerTemplate!=='');
+ return ($this->getShowHeader() && $this->_headerTemplate!==null);
}
/**
@@ -752,7 +772,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
*/
public function getHasFooter()
{
- return ($this->getShowFooter() && $this->_footerTemplate!=='');
+ return ($this->getShowFooter() && $this->_footerTemplate!==null);
}
/**
@@ -762,7 +782,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
*/
public function getHasSeparators()
{
- return $this->_separatorTemplate!=='';
+ return $this->_separatorTemplate!==null;
}
/**
@@ -815,9 +835,9 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
return $this->getItems()->itemAt($index);
case 'Separator':
$i=$index+$index+1;
- if($this->_headerTemplate!=='')
+ if($this->_headerTemplate!==null)
$i++;
- return $this->getControls->itemAt($i);
+ return $this->getControls()->itemAt($i);
}
return null;
}
@@ -949,74 +969,45 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
*/
protected function initializeItem($item)
{
- $tplContent='';
+ $template=null;
switch($item->getItemType())
{
case 'Header':
- $tplContent=$this->_headerTemplate;
+ $template=$this->_headerTemplate;
break;
case 'Footer':
- $tplContent=$this->_footerTemplate;
+ $template=$this->_footerTemplate;
break;
case 'Item':
- $tplContent=$this->_itemTemplate;
+ $template=$this->_itemTemplate;
break;
case 'AlternatingItem':
- if(($tplContent=$this->_alternatingItemTemplate)==='')
- $tplContent=$this->_itemTemplate;
+ if(($template=$this->_alternatingItemTemplate)===null)
+ $template=$this->_itemTemplate;
break;
case 'Separator':
- $tplContent=$this->_separatorTemplate;
+ $template=$this->_separatorTemplate;
break;
case 'SelectedItem':
- if(($tplContent=$this->_selectedItemTemplate)==='')
+ if(($template=$this->_selectedItemTemplate)===null)
{
- if(!($item->getItemIndex()%2) || ($tplContent=$this->_alternatingItemTemplate)==='')
- $tplContent=$this->_itemTemplate;
+ if(!($item->getItemIndex()%2) || ($template=$this->_alternatingItemTemplate)===null)
+ $template=$this->_itemTemplate;
}
break;
case 'EditItem':
- if(($tplContent=$this->_editItemTemplate)==='')
+ if(($template=$this->_editItemTemplate)===null)
{
- if($item->getItemIndex()!==$this->getSelectedItemIndex() || ($tplContent=$this->_selectedItemTemplate)==='')
- if(!($item->getItemIndex()%2) || ($tplContent=$this->_alternatingItemTemplate)==='')
- $tplContent=$this->_itemTemplate;
+ if($item->getItemIndex()!==$this->getSelectedItemIndex() || ($template=$this->_selectedItemTemplate)===null)
+ if(!($item->getItemIndex()%2) || ($template=$this->_alternatingItemTemplate)===null)
+ $template=$this->_itemTemplate;
}
break;
default:
break;
}
- if($tplContent!=='')
- $this->createTemplate($tplContent)->instantiateIn($item);
- }
-
- /**
- * Parses item template.
- * This method uses caching technique to accelerate template parsing.
- * @param string template string
- * @return ITemplate parsed template object
- */
- protected function createTemplate($str)
- {
- $key=md5($str);
- if(isset(self::$_templates[$key]))
- return self::$_templates[$key];
- else
- {
- $contextPath=$this->getTemplateControl()->getTemplate()->getContextPath();
- if(($cache=$this->getApplication()->getCache())!==null)
- {
- if(($template=$cache->get($key))===null)
- {
- $template=new TTemplate($str,$contextPath);
- $cache->set($key,$template,self::CACHE_EXPIRY);
- }
- }
- else
- $template=new TTemplate($str,$contextPath);
- self::$_templates[$key]=$template;
- return $template;
- }
+ if($template!==null)
+ $template->instantiateIn($item);
}
/**
@@ -1066,9 +1057,9 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$items=$this->getItems();
$selectedIndex=$this->getSelectedItemIndex();
$editIndex=$this->getEditItemIndex();
- if($this->_headerTemplate!=='')
+ if($this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,'Header',false,null);
- $hasSeparator=$this->_separatorTemplate!=='';
+ $hasSeparator=$this->_separatorTemplate!==null;
for($i=0;$i<$itemCount;++$i)
{
if($hasSeparator && $i>0)
@@ -1081,7 +1072,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$itemType=$i%2?'AlternatingItem':'Item';
$items->add($this->createItemInternal($i,$itemType,false,null));
}
- if($this->_footerTemplate!=='')
+ if($this->_footerTemplate!==null)
$this->_footer=$this->createItemInternal(-1,'Footer',false,null);
}
$this->clearChildState();
@@ -1101,14 +1092,14 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$keyField=$this->getDataKeyField();
$itemIndex=0;
$items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!=='';
+ $hasSeparator=$this->_separatorTemplate!==null;
$selectedIndex=$this->getSelectedItemIndex();
$editIndex=$this->getEditItemIndex();
foreach($data as $dataItem)
{
if($keyField!=='')
$keys->add($this->getDataFieldValue($dataItem,$keyField));
- if($itemIndex===0 && $this->_headerTemplate!=='')
+ if($itemIndex===0 && $this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,'Header',true,null);
if($hasSeparator && $itemIndex>0)
$this->createItemInternal($itemIndex-1,'Separator',true,null);
@@ -1121,7 +1112,7 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
$itemIndex++;
}
- if($itemIndex>0 && $this->_footerTemplate!=='')
+ if($itemIndex>0 && $this->_footerTemplate!==null)
$this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 92d87b64..6aa6b461 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -57,33 +57,25 @@ Prado::using('System.Web.UI.WebControls.TDataBoundControl');
class TRepeater extends TDataBoundControl implements INamingContainer
{
/**
- * Number of seconds that a cached template will expire after
+ * @var ITemplate template for repeater items
*/
- const CACHE_EXPIRY=18000;
+ private $_itemTemplate=null;
/**
- * @var array in-memory cache of parsed templates
+ * @var ITemplate template for each alternating item
*/
- private static $_templates=array();
+ private $_alternatingItemTemplate=null;
/**
- * @var string template for each item
+ * @var ITemplate template for header
*/
- private $_itemTemplate='';
+ private $_headerTemplate=null;
/**
- * @var string template for each alternating item
+ * @var ITemplate template for footer
*/
- private $_alternatingItemTemplate='';
+ private $_footerTemplate=null;
/**
- * @var string template for header
+ * @var ITemplate template for separator
*/
- private $_headerTemplate='';
- /**
- * @var string template for footer
- */
- private $_footerTemplate='';
- /**
- * @var string template for separator
- */
- private $_separatorTemplate='';
+ private $_separatorTemplate=null;
/**
* @var TRepeaterItemCollection list of repeater items
*/
@@ -107,7 +99,7 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * @return string the template string for the item
+ * @return ITemplate the template for repeater items
*/
public function getItemTemplate()
{
@@ -115,16 +107,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Sets the template string for the item
- * @param string the item template
+ * @param ITemplate the template for repeater items
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setItemTemplate($value)
{
- $this->_itemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','ItemTemplate');
}
/**
- * @return string the alternative template string for the item
+ * @return ITemplate the alternative template string for the item
*/
public function getAlternatingItemTemplate()
{
@@ -132,16 +127,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Sets the alternative template string for the item
- * @param string the alternative item template
+ * @param ITemplate the alternative item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setAlternatingItemTemplate($value)
{
- $this->_alternatingItemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_alternatingItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','AlternatingItemTemplate');
}
/**
- * @return string the header template string
+ * @return ITemplate the header template
*/
public function getHeaderTemplate()
{
@@ -149,16 +147,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Sets the header template.
- * @param string the header template
+ * @param ITemplate the header template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setHeaderTemplate($value)
{
- $this->_headerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','HeaderTemplate');
}
/**
- * @return string the footer template string
+ * @return ITemplate the footer template
*/
public function getFooterTemplate()
{
@@ -166,16 +167,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Sets the footer template.
- * @param string the footer template
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setFooterTemplate($value)
{
- $this->_footerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','FooterTemplate');
}
/**
- * @return string the separator template string
+ * @return ITemplate the separator template
*/
public function getSeparatorTemplate()
{
@@ -183,12 +187,15 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Sets the separator template string
- * @param string the separator template
+ * @param ITemplate the separator template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setSeparatorTemplate($value)
{
- $this->_separatorTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_separatorTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('repeater_template_required','SeparatorTemplate');
}
/**
@@ -267,50 +274,21 @@ class TRepeater extends TDataBoundControl implements INamingContainer
*/
protected function initializeItem($item)
{
- $tplContent='';
+ $template=null;
switch($item->getItemType())
{
- case 'Header': $tplContent=$this->_headerTemplate; break;
- case 'Footer': $tplContent=$this->_footerTemplate; break;
- case 'Item': $tplContent=$this->_itemTemplate; break;
- case 'Separator': $tplContent=$this->_separatorTemplate; break;
- case 'AlternatingItem': $tplContent=$this->_alternatingItemTemplate==='' ? $this->_itemTemplate : $this->_alternatingItemTemplate; break;
+ case 'Header': $template=$this->_headerTemplate; break;
+ case 'Footer': $template=$this->_footerTemplate; break;
+ case 'Item': $template=$this->_itemTemplate; break;
+ case 'Separator': $template=$this->_separatorTemplate; break;
+ case 'AlternatingItem': $template=$this->_alternatingItemTemplate===null ? $this->_itemTemplate : $this->_alternatingItemTemplate; break;
case 'SelectedItem':
case 'EditItem':
default:
break;
}
- if($tplContent!=='')
- $this->createTemplate($tplContent)->instantiateIn($item);
- }
-
- /**
- * Parses item template.
- * This method uses caching technique to accelerate template parsing.
- * @param string template string
- * @return ITemplate parsed template object
- */
- protected function createTemplate($str)
- {
- $key=md5($str);
- if(isset(self::$_templates[$key]))
- return self::$_templates[$key];
- else
- {
- $contextPath=$this->getTemplateControl()->getTemplate()->getContextPath();
- if(($cache=$this->getApplication()->getCache())!==null)
- {
- if(($template=$cache->get($key))===null)
- {
- $template=new TTemplate($str,$contextPath);
- $cache->set($key,$template,self::CACHE_EXPIRY);
- }
- }
- else
- $template=new TTemplate($str,$contextPath);
- self::$_templates[$key]=$template;
- return $template;
- }
+ if($template!==null)
+ $template->instantiateIn($item);
}
/**
@@ -369,8 +347,8 @@ class TRepeater extends TDataBoundControl implements INamingContainer
if(($itemCount=$this->getViewState('ItemCount',0))>0)
{
$items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!=='';
- if($this->_headerTemplate!=='')
+ $hasSeparator=$this->_separatorTemplate!==null;
+ if($this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,'Header',false,null);
for($i=0;$i<$itemCount;++$i)
{
@@ -379,7 +357,7 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$itemType=$i%2==0?'Item':'AlternatingItem';
$items->add($this->createItemInternal($i,$itemType,false,null));
}
- if($this->_footerTemplate!=='')
+ if($this->_footerTemplate!==null)
$this->_footer=$this->createItemInternal(-1,'Footer',false,null);
}
$this->clearChildState();
@@ -396,10 +374,10 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->reset();
$itemIndex=0;
$items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!=='';
+ $hasSeparator=$this->_separatorTemplate!==null;
foreach($data as $dataItem)
{
- if($itemIndex===0 && $this->_headerTemplate!=='')
+ if($itemIndex===0 && $this->_headerTemplate!==null)
$this->_header=$this->createItemInternal(-1,'Header',true,null);
if($hasSeparator && $itemIndex>0)
$this->createItemInternal($itemIndex-1,'Separator',true,null);
@@ -407,7 +385,7 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
$itemIndex++;
}
- if($itemIndex>0 && $this->_footerTemplate!=='')
+ if($itemIndex>0 && $this->_footerTemplate!==null)
$this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}
diff --git a/framework/Web/UI/WebControls/TTemplateColumn.php b/framework/Web/UI/WebControls/TTemplateColumn.php
index ec4f191d..9c386543 100644
--- a/framework/Web/UI/WebControls/TTemplateColumn.php
+++ b/framework/Web/UI/WebControls/TTemplateColumn.php
@@ -31,21 +31,16 @@ Prado::using('System.Web.UI.WebControls.TDataGridColumn');
class TTemplateColumn extends TDataGridColumn
{
/**
- * Number of seconds that a cached template will expire after
- */
- const CACHE_EXPIRY=18000;
- /**
* Various item templates
* @var string
*/
- private $_itemTemplate='';
- private $_editItemTemplate='';
- private $_headerTemplate='';
- private $_footerTemplate='';
- private static $_templates=array();
+ private $_itemTemplate=null;
+ private $_editItemTemplate=null;
+ private $_headerTemplate=null;
+ private $_footerTemplate=null;
/**
- * @return string the edit item template string
+ * @return ITemplate the edit item template
*/
public function getEditItemTemplate()
{
@@ -53,16 +48,19 @@ class TTemplateColumn extends TDataGridColumn
}
/**
- * Sets the edit item template string
- * @param string the edit item template
+ * @param ITemplate the edit item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setEditItemTemplate($value)
{
- $this->_editItemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_editItemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','EditItemTemplate');
}
/**
- * @return string the template string for the item
+ * @return ITemplate the item template
*/
public function getItemTemplate()
{
@@ -70,16 +68,19 @@ class TTemplateColumn extends TDataGridColumn
}
/**
- * Sets the template string for the item
- * @param string the item template
+ * @param ITemplate the item template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setItemTemplate($value)
{
- $this->_itemTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_itemTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','ItemTemplate');
}
/**
- * @return string the header template string
+ * @return ITemplate the header template
*/
public function getHeaderTemplate()
{
@@ -87,17 +88,19 @@ class TTemplateColumn extends TDataGridColumn
}
/**
- * Sets the header template.
- * The template will be parsed immediately.
- * @param string the header template
+ * @param ITemplate the header template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setHeaderTemplate($value)
{
- $this->_headerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_headerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','HeaderTemplate');
}
/**
- * @return string the footer template string
+ * @return ITemplate the footer template
*/
public function getFooterTemplate()
{
@@ -105,13 +108,15 @@ class TTemplateColumn extends TDataGridColumn
}
/**
- * Sets the footer template.
- * The template will be parsed immediately.
- * @param string the footer template
+ * @param ITemplate the footer template
+ * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setFooterTemplate($value)
{
- $this->_footerTemplate=$value;
+ if($value instanceof ITemplate || $value===null)
+ $this->_footerTemplate=$value;
+ else
+ throw new TInvalidDataTypeException('templatecolumn_template_required','FooterTemplate');
}
/**
@@ -126,58 +131,29 @@ class TTemplateColumn extends TDataGridColumn
public function initializeCell($cell,$columnIndex,$itemType)
{
parent::initializeCell($cell,$columnIndex,$itemType);
- $tplContent='';
+ $template=null;
switch($itemType)
{
case 'Header':
- $tplContent=$this->_headerTemplate;
+ $template=$this->_headerTemplate;
break;
case 'Footer':
- $tplContent=$this->_footerTemplate;
+ $template=$this->_footerTemplate;
break;
case 'Item':
case 'AlternatingItem':
case 'SelectedItem':
- $tplContent=$this->_itemTemplate;
+ $template=$this->_itemTemplate;
break;
case 'EditItem':
- $tplContent=$this->_editItemTemplate===''?$this->_itemTemplate:$this->_editItemTemplate;
+ $template=$this->_editItemTemplate===null?$this->_itemTemplate:$this->_editItemTemplate;
break;
}
- if($tplContent!=='')
+ if($template!==null)
{
$cell->setText('');
$cell->getControls()->clear();
- $this->createTemplate($tplContent)->instantiateIn($cell);
- }
- }
-
- /**
- * Parses item template.
- * This method uses caching technique to accelerate template parsing.
- * @param string template string
- * @return ITemplate parsed template object
- */
- protected function createTemplate($str)
- {
- $key=md5($str);
- if(isset(self::$_templates[$key]))
- return self::$_templates[$key];
- else
- {
- $contextPath=$this->getOwner()->getTemplateControl()->getTemplate()->getContextPath();
- if(($cache=$this->getApplication()->getCache())!==null)
- {
- if(($template=$cache->get($key))===null)
- {
- $template=new TTemplate($str,$contextPath);
- $cache->set($key,$template,self::CACHE_EXPIRY);
- }
- }
- else
- $template=new TTemplate($str,$contextPath);
- self::$_templates[$key]=$template;
- return $template;
+ $template->instantiateIn($cell);
}
}
}