]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/TTemplateControlInheritable.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / TTemplateControlInheritable.php
1 <?php
2
3 /**
4  * TTemplateControlInheritable class file.
5  *
6  * @author Schlaue-Kids.net <info@schlaue-kids.net>
7  * @link http://www.schlaue-kids.net/
8  * @copyright Copyright &copy; 2010 Schlaue-Kids.net
9  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
10  * @version $Id$
11  * @package System.Web.UI
12  */
13
14 Prado::using('System.Web.UI.TTemplateControl');
15
16 /**
17  * TTemplateControlInheritable class.
18  * TTemplateControlInheritable is an extension to the base class for all controls that use templates.
19  * By default, a control template is assumed to be in a file under the same
20  * directory with the control class file. They have the same file name and
21  * different extension name. For template file, the extension name is ".tpl".
22  * If a TTemplateControlInheritable is inherited it uses the base class template unless the
23  * inheriting control defines an own.
24  *
25  * @author Schlaue-Kids.net <info@schlaue-kids.net>
26  * @author Kyle Caine
27  * @version $Id$
28  * @package System.Web.UI
29  * @since 3.1.8
30  */
31 class TTemplateControlInheritable extends TTemplateControl
32 {
33         // methods
34
35         /**
36          * Creates child controls.
37          * This method is overridden to load and instantiate control template.
38          * This method should only be used by framework and control developers.
39          * Uses the controls template if available or the base class template otherwise.
40          *
41          * @return void
42          * @throws TConfigurationException if a template control directive is invalid
43          */     
44         public function createChildControls()
45         {
46                 if(null === ($_template = $this->getTemplate())) {
47                         return $this->doCreateChildControlsFor(get_class($this));
48                 }
49
50                 foreach($_template->getDirective() as $_name => $_value) {
51                         if(!is_string($_value)) {
52                                 throw new TConfigurationException('templatecontrol_directive_invalid', get_class($this), $name);
53                         }
54                         
55                         $this->setSubProperty($_name, $_value);
56                 }
57
58                 $_template->instantiateIn($this);
59         }
60
61         /**
62          * This method creates the cild controls for the given class
63          *
64          * @param string $parentClass The class to generate the child controls for
65          * @return void
66          */
67         public function doCreateChildControlsFor($parentClass)
68         {
69                 if(false !== ($_parentClass = get_parent_class($parentClass)) && 'TTemplateControl' != $_parentClass) {
70                         $this->doCreateChildControlsFor($_parentClass);
71                 }
72
73                 $this->doTemplateForClass($parentClass);
74         }
75
76         /**
77          * This method creates the template object for the given class
78          *
79          * @param string $p_class The class to create the template from
80          * @return void
81          * @throws TConfigurationException if a template control directive is invalid
82          */
83         public function doTemplateForClass($parentClass)
84         {
85                 if(null !== ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName($parentClass))) {
86                         foreach($_template->getDirective() as $_name => $_value) {
87                                 if(!is_string($_value)) {
88                                         throw new TConfigurationException('templatecontrol_directive_invalid', get_class(this), $_name);
89                                 }
90                                 
91                                 $this->setSubProperty($_name, $_value);
92                         }
93
94                         $_template->instantiateIn($this);
95                 }
96         }
97         
98         // getter/setter
99
100         /**
101          * A source template control loads its template from external storage,
102          * such as file, db, rather than from within another template.
103          *
104          * @return boolean whether the current control is a source template control
105          */
106         public function getIsSourceTemplateControl()
107         {
108                 if(null !== ($_template = $this->getTemplate())) {
109                         return $_template->getIsSourceTemplate();
110                 }
111
112                 return ($_template = $this->getService()->getTemplateManager()->getTemplateByClassName(get_parent_class($this)))
113                         ? $_template->getIsSourceTemplate()
114                         : false;
115         }
116 }