From 2b194248b9bbd75887c1d5f991dca1f3fd441dd5 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 15 Feb 2006 01:38:39 +0000 Subject: Added SourceTemplateControl property for TControl. --- framework/Web/UI/TControl.php | 16 ++++++++++++++++ framework/Web/UI/TTemplateControl.php | 24 ++++++++++++++++++++++++ framework/Web/UI/TTemplateManager.php | 20 ++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 50648d93..6fd25f76 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -255,6 +255,22 @@ class TControl extends TComponent return $this->_tplControl; } + /** + * @return TTemplateControl the control whose template is loaded from + * some external storage, such as file, db, and whose template ultimately + * contains this control. + */ + public function getSourceTemplateControl() + { + $control=$this; + while(($control instanceof TControl) && ($control=$control->getTemplateControl())!==null) + { + if(($control instanceof TTemplateControl) && $control->getIsSourceTemplateControl()) + return $control; + } + return $this->getPage(); + } + /** * Publishes a private asset and gets its URL. * This method will publish a private asset (file or directory) diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index d7f1868b..d6ccb825 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -82,6 +82,30 @@ class TTemplateControl extends TControl implements INamingContainer $this->_localTemplate=$value; } + /** + * @return boolean whether this control is a source template control. + * A source template control loads its template from external storage, + * such as file, db, rather than from within another template. + */ + public function getIsSourceTemplateControl() + { + if(($template=$this->getTemplate())!==null) + return $template->getIsSourceTemplate(); + else + return false; + } + + /** + * @return string the directory containing the template. Empty if no template available. + */ + public function getTemplateDirectory() + { + if(($template=$this->getTemplate())!==null) + return $template->getContextPath(); + else + return ''; + } + /** * Loads the template associated with this control class. * @return ITemplate the parsed template structure diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index abeb7466..59d15698 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -194,6 +194,10 @@ class TTemplate extends TComponent implements ITemplate * @var string template content to be parsed */ private $_content; + /** + * @var boolean whether this template is a source template + */ + private $_sourceTemplate=true; /** @@ -203,9 +207,12 @@ class TTemplate extends TComponent implements ITemplate * @param string the template context directory * @param string the template file, null if no file * @param integer the line number that parsing starts from (internal use) + * @param boolean whether this template is a source template, i.e., this template is loaded from + * some external storage rather than from within another template. */ - public function __construct($template,$contextPath,$tplFile=null,$startingLine=0) + public function __construct($template,$contextPath,$tplFile=null,$startingLine=0,$sourceTemplate=true) { + $this->_sourceTemplate=$sourceTemplate; $this->_contextPath=$contextPath; $this->_tplFile=$tplFile; $this->_startingLine=$startingLine; @@ -214,6 +221,15 @@ class TTemplate extends TComponent implements ITemplate $this->_content=null; // reset to save memory } + /** + * @return boolean whether this template is a source template, i.e., this template is loaded from + * some external storage rather than from within another template. + */ + public function getIsSourceTemplate() + { + return $this->_sourceTemplate; + } + /** * @return string context directory path */ @@ -636,7 +652,7 @@ class TTemplate extends TComponent implements ITemplate protected function parseTemplateProperty($content,$offset) { $line=$this->_startingLine+count(explode("\n",substr($this->_content,0,$offset)))-1; - return array(self::CONFIG_TEMPLATE,new TTemplate($content,$this->_contextPath,$this->_tplFile,$line)); + return array(self::CONFIG_TEMPLATE,new TTemplate($content,$this->_contextPath,$this->_tplFile,$line,false)); } /** -- cgit v1.2.3