From 7609a77f09db93f488141018af8473db9c3e0c3e Mon Sep 17 00:00:00 2001 From: rojaro <> Date: Sat, 11 Dec 2010 17:21:04 +0000 Subject: added new TTemplateControlInheritable class --- .gitattributes | 1 + framework/Web/UI/TTemplateControlInheritable.php | 116 +++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 framework/Web/UI/TTemplateControlInheritable.php diff --git a/.gitattributes b/.gitattributes index 375869ee..8fdd8cd5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2885,6 +2885,7 @@ framework/Web/UI/TPage.php -text framework/Web/UI/TPageStatePersister.php -text framework/Web/UI/TSessionPageStatePersister.php -text framework/Web/UI/TTemplateControl.php -text +framework/Web/UI/TTemplateControlInheritable.php -text framework/Web/UI/TTemplateManager.php -text framework/Web/UI/TThemeManager.php -text framework/Web/UI/WebControls/TBaseDataList.php -text diff --git a/framework/Web/UI/TTemplateControlInheritable.php b/framework/Web/UI/TTemplateControlInheritable.php new file mode 100644 index 00000000..1a62740a --- /dev/null +++ b/framework/Web/UI/TTemplateControlInheritable.php @@ -0,0 +1,116 @@ + + * @link http://www.schlaue-kids.net/ + * @copyright Copyright © 2010 Schlaue-Kids.net + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Web.UI + */ + +Prado::using('System.Web.UI.TTemplateControl'); + +/** + * TTemplateControlInheritable class. + * TTemplateControlInheritable is an extension to the base class for all controls that use templates. + * By default, a control template is assumed to be in a file under the same + * directory with the control class file. They have the same file name and + * different extension name. For template file, the extension name is ".tpl". + * If a TTemplateControlInheritable is inherited it uses the base class template unless the + * inheriting control defines an own. + * + * @author Schlaue-Kids.net + * @author Kyle Caine + * @version $Id$ + * @package System.Web.UI + * @since 3.1.8 + */ +class TTemplateControlInheritable extends TTemplateControl +{ + // methods + + /** + * Creates child controls. + * This method is overridden to load and instantiate control template. + * This method should only be used by framework and control developers. + * Uses the controls template if available or the base class template otherwise. + * + * @return void + * @throws TConfigurationException if a template control directive is invalid + */ + public function createChildControls() + { + if(null === ($_template = $this->getTemplate())) { + return $this->doCreateChildControlsFor(get_class($this)); + } + + foreach($_template->getDirective() as $_name => $_value) { + if(!is_string($_value)) { + throw new TConfigurationException('templatecontrol_directive_invalid', get_class($this), $name); + } + + $this->setSubProperty($_name, $_value); + } + + $_template->instantiateIn($this); + } + + /** + * This method creates the cild controls for the given class + * + * @param string $parentClass The class to generate the child controls for + * @return void + */ + public function doCreateChildControlsFor($parentClass) + { + if(false !== ($_parentClass = get_parent_class($parentClass)) && 'TTemplateControl' != $_parentClass) { + $this->doCreateChildControlsFor($_parentClass); + } + + $this->doTemplateForClass($parentClass); + } + + /** + * This method creates the template object for the given class + * + * @param string $p_class The class to create the template from + * @return void + * @throws TConfigurationException if a template control directive is invalid + */ + public function doTemplateForClass($parentClass) + { + if(null !== ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName($parentClass))) { + foreach($_template->getDirective() as $_name => $_value) { + if(!is_string($_value)) { + throw new TConfigurationException('templatecontrol_directive_invalid', get_class(this), $_name); + } + + $this->setSubProperty($_name, $_value); + } + + $_template->instantiateIn($this); + } + } + + // getter/setter + + /** + * A source template control loads its template from external storage, + * such as file, db, rather than from within another template. + * + * @return boolean whether the current control is a source template control + */ + public function getIsSourceTemplateControl() + { + if(null !== ($_template = $this->getTemplate())) { + return $_template->getIsSourceTemplate(); + } + + return ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName(get_parent_class($this))) + ? $this->_template->getIsSourceTemplate() + : false; + } +} \ No newline at end of file -- cgit v1.2.3