| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTModuleBase { |
| 10 |
|
| 11 |
/** |
| 12 |
* instance to cjToolbox object. |
| 13 |
* |
| 14 |
* @var cssJSToolbox |
| 15 |
*/ |
| 16 |
protected $cjToolbox = null; |
| 17 |
|
| 18 |
/** |
| 19 |
* Is this module is to extend the cssJSToolbox |
| 20 |
* object method. |
| 21 |
* |
| 22 |
* @var boolean |
| 23 |
*/ |
| 24 |
protected $extendCJToolbox = true; |
| 25 |
|
| 26 |
/** |
| 27 |
* Module info struct passed by modules::processAll method. |
| 28 |
* |
| 29 |
* @var array |
| 30 |
*/ |
| 31 |
protected $moduleInfo = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* If the method is not implemented in $this |
| 35 |
* object delegate cssJSToolbox method. |
| 36 |
* |
| 37 |
* @param string Method name. |
| 38 |
* @param array Parameters. |
| 39 |
* @return mixed. |
| 40 |
*/ |
| 41 |
public function __call($method, $parameters) { |
| 42 |
if ($this->extendCJToolbox) { |
| 43 |
return call_user_func_array(array($this->cjToolbox, $method), $parameters); |
| 44 |
} |
| 45 |
else { |
| 46 |
trigger_error("Module method '{$method}' is not found", E_USER_ERROR); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Module base constructor. |
| 52 |
* |
| 53 |
* This method should be called manually from the derivded classed |
| 54 |
* |
| 55 |
* @param array Module info. |
| 56 |
* @param boolean Is to extended cssJSToolbox object methods. |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
protected function __construct($moduleInfo, $extendCJToolbox = false) { |
| 60 |
$this->moduleInfo = $moduleInfo; |
| 61 |
$this->extendCJToolbox = $extendCJToolbox; |
| 62 |
if ($extendCJToolbox) { |
| 63 |
// Extended cssJSToolbox class functionaity. |
| 64 |
$this->cjToolbox = cssJSToolbox::$instance; |
| 65 |
cssJSToolbox::$instance = $this; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* If the property is not implemented in $this |
| 71 |
* object delegate cssJSToolbox property. |
| 72 |
* |
| 73 |
* @param string Property name. |
| 74 |
* @return mixed |
| 75 |
*/ |
| 76 |
public function __get($property) { |
| 77 |
if ($this->extendCJToolbox) { |
| 78 |
return $this->cjToolbox->$property; |
| 79 |
} |
| 80 |
else { |
| 81 |
trigger_error("Module property '{$property}' is not found", E_USER_ERROR); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* If the property is not implemented in $this |
| 87 |
* object delegate cssJSToolbox property. |
| 88 |
* |
| 89 |
* @param string Property name. |
| 90 |
* @param array Parameters. |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public function __set($property, $value) { |
| 94 |
if ($this->extendCJToolbox) { |
| 95 |
$this->cjToolbox->$property = $value; |
| 96 |
} |
| 97 |
else { |
| 98 |
trigger_error("Module property '{$property}' is not found", E_USER_ERROR); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Get CSS file URL for the module. |
| 104 |
* |
| 105 |
* @param string CSS file. |
| 106 |
* @return string CSS file URL |
| 107 |
*/ |
| 108 |
protected function getCSSFileURL($file) { |
| 109 |
return $this->getURL("public/css/{$file}"); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Get Javascript file URL for the module. |
| 114 |
* |
| 115 |
* @param string Javascript file. |
| 116 |
* @return string JS file URL |
| 117 |
*/ |
| 118 |
protected function getJSFileURL($file) { |
| 119 |
return $this->getURL("public/js/{$file}"); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Get path to module file. |
| 124 |
* |
| 125 |
* @param string |
| 126 |
* @return string File path. |
| 127 |
*/ |
| 128 |
protected function getPath($file = '') { |
| 129 |
$file = $file ? "/{$file}" : ''; |
| 130 |
$path = "{$this->moduleInfo['path']}{$file}"; |
| 131 |
return $path; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Get module file URL. |
| 136 |
* |
| 137 |
* @param |
| 138 |
* @param string File to get the URL to or module |
| 139 |
* URL if omitted. |
| 140 |
* @return string File URL. |
| 141 |
*/ |
| 142 |
protected function getURL($file = '') { |
| 143 |
$file = $file ? "/{$file}" : ''; |
| 144 |
$url = "{$this->moduleInfo['url']}{$file}"; |
| 145 |
return $url; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* put your comment there... |
| 150 |
* |
| 151 |
* @param mixed $view |
| 152 |
* @param mixed $parameters |
| 153 |
*/ |
| 154 |
public function getView($view, $parameters) { |
| 155 |
$viewPath = $this->getPath("views/{$view}.html.tmpl"); |
| 156 |
// Make parameters visible to the view. |
| 157 |
extract($parameters); |
| 158 |
// Get the content. |
| 159 |
ob_start(); |
| 160 |
require $viewPath; |
| 161 |
$content = ob_get_clean(); |
| 162 |
return $content; |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* put your comment there... |
| 167 |
* |
| 168 |
*/ |
| 169 |
public function leaveCJToolboxObject() { |
| 170 |
cssJSToolbox::$instance = $this->cjToolbox; |
| 171 |
} |
| 172 |
|
| 173 |
} // End class. |