summaryrefslogtreecommitdiff
path: root/framework/Web/UI/TTemplateControlInheritable.php
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2011-06-01 09:39:26 +0000
committerctrlaltca@gmail.com <>2011-06-01 09:39:26 +0000
commit5c0a31f2407037665e8640e486c36d6c71c5ca90 (patch)
tree5b6db25c8992e3767f57dd3301464642fd6ae145 /framework/Web/UI/TTemplateControlInheritable.php
parent3abc397e9b53623dd373746e8ab9bd5dd455cd0c (diff)
backported active data controls + some other goodies from trunk/ ; updated docs
Diffstat (limited to 'framework/Web/UI/TTemplateControlInheritable.php')
-rw-r--r--framework/Web/UI/TTemplateControlInheritable.php116
1 files changed, 116 insertions, 0 deletions
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 @@
+<?php
+
+/**
+ * TTemplateControlInheritable class file.
+ *
+ * @author Schlaue-Kids.net <info@schlaue-kids.net>
+ * @link http://www.schlaue-kids.net/
+ * @copyright Copyright &copy; 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 <info@schlaue-kids.net>
+ * @author Kyle Caine <http://www.pradosoft.com/forum/index.php?action=profile;u=1752>
+ * @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