Ejemplo n.º 1
0
 /**
  * Returns an array of moduleId and the their states (enabled, disabled, force enabled)
  * for given space id. If space id is 0 or empty, the default states will be returned.
  * 
  * @param int $spaceId 
  * @return array State of Module Ids
  */
 public static function getStates($spaceId = 0)
 {
     if (isset(self::$_states[$spaceId])) {
         return self::$_states[$spaceId];
     }
     $states = Yii::app()->cache->get(self::STATES_CACHE_ID_PREFIX . $spaceId);
     if ($states === false) {
         $states = array();
         foreach (SpaceApplicationModule::model()->findAllByAttributes(array('space_id' => $spaceId)) as $spaceModule) {
             $states[$spaceModule->module_id] = $spaceModule->state;
         }
         Yii::app()->cache->set(self::STATES_CACHE_ID_PREFIX . $spaceId, $states);
     }
     self::$_states[$spaceId] = $states;
     return self::$_states[$spaceId];
 }
Ejemplo n.º 2
0
 /**
  * Disables a module
  *
  * Which means delete all (user-) data created by the module.
  *
  */
 public function disable()
 {
     if (!$this->isEnabled() || $this->isCoreModule) {
         return false;
     }
     // Check this module is a SpaceModule
     if ($this->isSpaceModule()) {
         foreach ($this->getSpaceModuleSpaces() as $space) {
             $space->disableModule($this->getId());
         }
     }
     // Check this module is a UserModule
     if ($this->isUserModule()) {
         foreach ($this->getUserModuleUsers() as $user) {
             $user->disableModule($this->getId());
         }
     }
     // Disable module in database
     $moduleEnabled = ModuleEnabled::model()->findByPk($this->getId());
     if ($moduleEnabled != null) {
         $moduleEnabled->delete();
     }
     HSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId()));
     SpaceSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId()));
     UserSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId()));
     // Delete also records with disabled state from SpaceApplicationModule Table
     foreach (SpaceApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $sam) {
         $sam->delete();
     }
     // Delete also records with disabled state from UserApplicationModule Table
     foreach (UserApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $uam) {
         $uam->delete();
     }
     ModuleManager::flushCache();
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Sets default enabled/disabled on User or/and Space Modules
  *
  * @throws CHttpException
  */
 public function actionSetAsDefault()
 {
     $moduleId = Yii::app()->request->getQuery('moduleId');
     $module = Yii::app()->moduleManager->getModule($moduleId);
     if ($module == null) {
         throw new CHttpException(500, Yii::t('AdminModule.controllers_ModuleController', 'Could not find requested module!'));
     }
     $model = new ModuleSetAsDefaultForm();
     $spaceDefaultModule = null;
     if ($module->isSpaceModule()) {
         $spaceDefaultModule = SpaceApplicationModule::model()->findByAttributes(array('space_id' => 0, 'module_id' => $moduleId));
         if ($spaceDefaultModule === null) {
             $spaceDefaultModule = new SpaceApplicationModule();
             $spaceDefaultModule->module_id = $moduleId;
             $spaceDefaultModule->space_id = 0;
             $spaceDefaultModule->state = SpaceApplicationModule::STATE_DISABLED;
         }
         $model->spaceDefaultState = $spaceDefaultModule->state;
     }
     $userDefaultModule = null;
     if ($module->isUserModule()) {
         $userDefaultModule = UserApplicationModule::model()->findByAttributes(array('user_id' => 0, 'module_id' => $moduleId));
         if ($userDefaultModule === null) {
             $userDefaultModule = new UserApplicationModule();
             $userDefaultModule->module_id = $moduleId;
             $userDefaultModule->user_id = 0;
             $userDefaultModule->state = UserApplicationModule::STATE_DISABLED;
         }
         $model->userDefaultState = $userDefaultModule->state;
     }
     if (isset($_POST['ModuleSetAsDefaultForm'])) {
         $_POST['ModuleSetAsDefaultForm'] = Yii::app()->input->stripClean($_POST['ModuleSetAsDefaultForm']);
         $model->attributes = $_POST['ModuleSetAsDefaultForm'];
         if ($model->validate()) {
             if ($module->isSpaceModule()) {
                 $spaceDefaultModule->state = $model->spaceDefaultState;
                 $spaceDefaultModule->save();
             }
             if ($module->isUserModule()) {
                 $userDefaultModule->state = $model->userDefaultState;
                 $userDefaultModule->save();
             }
             // close modal
             $this->renderModalClose();
         }
     }
     $this->renderPartial('setAsDefault', array('module' => $module, 'model' => $model), false, true);
 }
 /**
  * Uninstalls a Module
  */
 public function disableModule($moduleId)
 {
     // Not enabled globally
     if (!array_key_exists($moduleId, $this->getAvailableModules())) {
         return false;
     }
     // Already enabled module
     if (!$this->isModuleEnabled($moduleId)) {
         Yii::log("Space->disableModule(" . $moduleId . ") module is not enabled");
         return false;
     }
     // New Way: Handle it directly in module class
     $module = Yii::app()->moduleManager->getModule($moduleId);
     $module->disableSpaceModule($this->getOwner());
     $spaceModule = SpaceApplicationModule::model()->findByAttributes(array('space_id' => $this->getOwner()->id, 'module_id' => $moduleId));
     if ($spaceModule == null) {
         $spaceModule = new SpaceApplicationModule();
         $spaceModule->space_id = $this->getOwner()->id;
         $spaceModule->module_id = $moduleId;
     }
     $spaceModule->state = SpaceApplicationModule::STATE_DISABLED;
     $spaceModule->save();
     return true;
 }