public function getAllModules()
 {
     $ret = [];
     $allModules = Modularity::find()->indexBy('id')->all();
     //数据库中的模块
     $modules = $this->loadAllModules();
     //文件路径中已存在的模块
     foreach ($modules as $m) {
         $moduleId = $m['id'];
         $ret[$moduleId] = $m;
         if (array_key_exists($moduleId, $allModules)) {
             $exitModule = $allModules[$moduleId];
             if ($ret[$moduleId]['hasAdmin']) {
                 $ret[$moduleId]['canActiveAdmin'] = !$exitModule['enable_admin'] ? true : false;
             }
             if ($ret[$moduleId]['hasHome']) {
                 $ret[$moduleId]['canActiveHome'] = !$exitModule['enable_home'] ? true : false;
             }
             $ret[$moduleId]['canInstall'] = false;
             $ret[$moduleId]['canUninstall'] = $ret[$moduleId]['hasAdmin'] && $exitModule['enable_admin'] || $ret[$moduleId]['hasHome'] && $exitModule['enable_home'] ? false : true;
             $ret[$moduleId]['instance']->is_system = $exitModule['is_system'];
             $ret[$moduleId]['instance']->is_content = $exitModule['is_content'];
         }
     }
     return $ret;
 }
 public function getAllModules()
 {
     $ret = [];
     
     $allModules = Modularity::find()->indexBy('id')->all();
     
     $modules = $this->loadAllModules();
     foreach ($modules as $m)
     {
         $moduleId = $m['id'];
         
         $ret[$moduleId] = $m;
         if (array_key_exists($moduleId, $allModules))
         {
             $exitModule = $allModules[$moduleId];
            
             if($ret[$moduleId]['has_admin'])
             {
                 $ret[$moduleId]['can_active_admin'] = ($exitModule['enable_admin'] === null || $exitModule['enable_admin'] === 0) ? true : false;
             }
             if($ret[$moduleId]['has_home'])
             {
                 $ret[$moduleId]['can_active_home'] = ($exitModule['enable_home'] === null || $exitModule['enable_home'] === 0) ? true : false;
             }
             
             $ret[$moduleId]['can_install'] = false;
             $ret[$moduleId]['can_uninstall'] = ( $ret[$moduleId]['has_admin'] && $exitModule['enable_admin'] ||  $ret[$moduleId]['has_home'] && $exitModule['enable_home']) ? false : true;
         }
     }
     return $ret;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Modularity::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['is_system' => $this->is_system, 'is_content' => $this->is_content, 'enable_admin' => $this->enable_admin, 'enable_home' => $this->enable_home]);
     $query->andFilterWhere(['like', 'id', $this->id]);
     return $dataProvider;
 }
 public function actionDeactive($id, $is_admin = null)
 {
     $field = $is_admin === null ? 'enable_home' : 'enable_admin';
     Modularity::updateAll([$field => 0], ['id' => $id]);
     $modules = $this->modularityService->getAllModules();
     if (isset($modules[$id]) && $modules[$id]['instance'] !== null) {
         if ($is_admin === null) {
             $modules[$id]['instance']->deactiveHome();
         } else {
             $modules[$id]['instance']->deactiveAdmin();
         }
     }
     return $this->redirect(['index']);
 }
 /**
  * 卸载
  * 'canInstall' => true
  * 'canUninstall' => true
  * 'hasAdmin' => true
  * 'hasHome' => true
  * 'canActiveAdmin' => false
  * 'canActiveHome' => false
  * @param type $id
  * @return type
  */
 public function actionUninstall($id)
 {
     $lastBreadcrumb = "Uninstall Modularity";
     $this->setMenus(12, $lastBreadcrumb);
     Modularity::deleteAll(['id' => $id]);
     $modules = $this->modularityService->getAllModules();
     if (isset($modules[$id]) && $modules[$id]['instance'] !== null) {
         $modules[$id]['instance']->uninstall();
     }
     return $this->redirect(['index', 'message' => \Yii::t('yii', '{attribute} Success', ['attribute' => LsYii::gT($lastBreadcrumb)])]);
 }