11 public $enableCustomize =
true;
17 public $cacheTime = 60;
21 public $mainMailTemplate = null;
23 public function init(){
27 $this->setLanguageFromSession();
31 private function importFiles(){
33 $importList = array();
34 $moduleId = $this->getId();
35 $importList = array();
36 if($this->enableCustomize){
37 $importList = $this->getCustomizedModelsImportList();
39 $importList[] =
"$moduleId.models.*";
41 $importList[] =
"$moduleId.components.*";
42 $this->setImport($importList);
45 private function getCustomizedModelsImportList(){
47 $moduleId = $this->getId();
49 $pathModule = $this->getBasePath();
50 $pathCommonModels = $pathModule.DIRECTORY_SEPARATOR.
"models".DIRECTORY_SEPARATOR;
51 $pathCustomModels = $pathModule.DIRECTORY_SEPARATOR.
"..".DIRECTORY_SEPARATOR.
"..".DIRECTORY_SEPARATOR.
".."
52 .DIRECTORY_SEPARATOR.
"custom".DIRECTORY_SEPARATOR.
"modules".DIRECTORY_SEPARATOR
53 .$moduleId.DIRECTORY_SEPARATOR.
"models".DIRECTORY_SEPARATOR;
54 $pathCustomModelsBasic = $pathCustomModels.
"basic".DIRECTORY_SEPARATOR;
56 $modelAlias = array();
57 $cacheId =
'custom_models_';
58 if(file_exists($pathCustomModels) && is_dir($pathCustomModels)){
60 $commonModels = scandir($pathCommonModels);
61 $customModels = scandir($pathCustomModels);
63 foreach($customModels as $file){
65 if(is_file($pathCustomModels.$file) && $touchTime = filemtime($pathCustomModels.$file)){
66 $cacheId .= $touchTime;
69 $cacheId = md5($cacheId);
71 if(!$modelAlias = Yii::app()->cache->get($cacheId)){
72 function leftFilesOnly(&$dirContent){
73 foreach($dirContent as $i => &$file){
74 if(substr($file,-4) !=
'.php'){
75 unset($dirContent[$i]);
80 leftFilesOnly($commonModels);
81 leftFilesOnly($customModels);
83 foreach($commonModels as $model){
85 $modelName = explode(
'.',$model);
86 if(in_array($model, $customModels)){
88 if(file_exists($pathCustomModelsBasic) && is_dir($pathCustomModelsBasic)){
89 if(substr(decoct(fileperms($pathCustomModelsBasic)),2) != 777){
90 @chmod($pathCustomModelsBasic, 0777);
93 mkdir($pathCustomModelsBasic);
94 @chmod($pathCustomModelsBasic, 0777);
96 $basicModelPath = $pathCustomModelsBasic.$modelName[0].
"Basic.".$modelName[1];
97 if(!file_exists($basicModelPath)){
99 copy($pathCommonModels.$model, $basicModelPath);
101 $basic_model_code=file( $basicModelPath );
102 foreach($basic_model_code as $line=>$content){
104 if(preg_match(
"/^class ([a-zA-Z0-9_]+) extends CActiveRecord/",$content) !== 0 && !strpos ($content,
"Basic")){
105 $basic_model_code[$line] = preg_replace(
106 "/^class ([a-zA-Z0-9_]+) extends CActiveRecord/",
107 "class \${1}Basic extends CActiveRecord",
112 file_put_contents( $basicModelPath , $basic_model_code );
115 $modelAlias[] =
"site.$location.modules.shoppingcart.models.basic.$modelName[0]Basic";
117 $modelAlias[] =
"site.$location.modules.shoppingcart.models.$modelName[0]";
119 Yii::app()->cache->set($cacheId, $modelAlias);
122 if(!count($modelAlias)){
123 $modelAlias[] =
"shoppingcart.models.*";
128 private function setLanguageFromSession(){
130 if(Yii::app()->user->getState(
'lang') != null){
131 Yii::app()->language = Yii::app()->user->getState(
'lang');
144 public static function t($str =
'', $params = array(), $dic =
'core')
146 return Yii::t(get_called_class() .
"." . $dic, $str, $params);
156 $moduleId = $this->getId();
158 if ($this->_assetsUrl === null) {
159 $assetsPath = Yii::getPathOfAlias(
"$moduleId.assets");
160 $this->_assetsUrl = Yii::app()->getAssetManager()->publish($assetsPath,
true, -1, YII_DEBUG);
163 return $this->_assetsUrl;