public function actionDelete(array $ids) { foreach ($ids as $id) { $model = SettingParam::model()->findByPk($id); /** * TODO: Check related data if this User is deletable * This can be done in onBeforeDelete or here or in extensions * * if (Related::model()->count("UserId = {$id}") > 0) * $this->result->fail(ERROR_VIOLATING_BUSINESS_RULES, Yii::t('XUser.User',"Cannot delete User ID={$id} as it has related class data.")); * else */ try { $module = $model->module; if ($model->delete()) { //remove user custom setting if (!$model->customizable) { UserSetting::model()->deleteAllByAttributes(array('param_name' => $model->name)); } //rebuild cache Constant Settings class Yii::app()->XService->run('Xpress.Settings.db2php', array('module' => $module)); } } catch (CException $ex) { errorHandler()->log(new XException($ex->getMessage(), $ex->getCode())); } } }
public static function userConfig($uid, $type = '') { $dataProvider = UserSetting::model()->findAllByAttributes(array('uid' => $uid)); $settings = CHtml::listData($dataProvider, 'stype', 'svalue'); if (!empty($type)) { if (!isset($settings[$type]) or empty($settings[$type])) { return 1; } else { if ($settings[$type] == '0') { return false; } else { return true; } } } else { return $settings; } }
/** * 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; }
/** * Before Delete of a User * */ public function beforeDelete() { // We don't allow deletion of users who owns a space - validate that foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) { if ($workspace->isSpaceOwner($this->id)) { throw new Exception("Tried to delete a user which is owner of a space!"); } } UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); // Delete Profile Image $this->getProfileImage()->delete(); // Delete all pending invites UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('user_id' => $this->id)); Follow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id)); // Delete all group admin assignments GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id)); // Delete wall entries WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id)); // Deletes all content created by this user foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) { $content->delete(); } foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) { $content->delete(); } // Delete all passwords foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) { $password->delete(); } return parent::beforeDelete(); }
public function actionSettings() { array_pop($_POST); $arr = $_POST; if (Yii::app()->user->isGuest) { $this->message(0, Yii::t('default', 'loginfirst'), Yii::app()->createUrl('site/login'), 1); } $uid = zmf::uid(); foreach ($arr as $key => $val) { $_k = zmf::filterInput($key, 't', 1); $_v = zmf::filterInput($val, 't', 1); $sinfo = UserSetting::model()->findByAttributes(array('stype' => $_k), "uid='{$uid}'"); $model = new UserSetting(); if (!$sinfo) { $_input = array('uid' => $uid, 'stype' => $_k, 'svalue' => $_v); $model->attributes = $_input; if ($model->validate()) { $model->save(); } } elseif ($sinfo->svalue != $_v) { $model->updateByPk($sinfo->id, array('svalue' => $_v)); } } zmf::setFCache("userSettings{$uid}", $arr); $this->redirect(array('users/config')); }
/** * Lists all models. */ public function actionIndex() { $url = parse_url(app()->request->getHostInfo(), PHP_URL_HOST); $currentWorkflow = $this->api('Cms.Workflow.getByUrl', array('url' => $url)); $workflowId = 0; $workflows = array(); $workflow = $this->getWorkflow(); if (is_object($workflow)) { $workflowId = $workflow->id; } else { $workflow = $currentWorkflow; //get workflow by url if (is_object($currentWorkflow)) { $workflowId = $currentWorkflow->id; } } //find all workflows if (is_object($workflow)) { //init setting params for current workflow $this->api('Xpress.Settings.sync', array('workflowId' => $workflow->id)); $workflows = Workflow::model()->findAll('site_id=:site_id', array(':site_id' => $workflow->site_id)); if (count($workflows)) { $workflows = CHtml::listData($workflows, 'id', 'name'); } } $model = new SettingParam('search'); $model->unsetAttributes(); // clear any default values if (isset($_POST['SettingParam'])) { $model->attributes = $_POST['SettingParam']; } elseif (isset($_GET['module'])) { $model->module = $_GET['module']; if (in_array($model->module, array('Xpress', 'Admin'))) { $model->module = 'System'; } } else { $model->module = 'System'; } $model->visible = 1; $model->workflow_id = $workflowId; $dataProvider = $model->search(); $dataProvider->pagination = false; $modules = $model->getModules(); $data = $dataProvider->getData(); //override setting use user_setting $customizable = array(); if (count($data)) { foreach ($data as $i => $row) { /** var CActiveRecord $row */ if ($row->customizable) { //load data from user_setting $custom = UserSetting::model()->findByAttributes(array('param_name' => $row->name, 'user_id' => Yii::app()->user->id)); if (is_object($custom)) { $data[$i]->value = $custom->value; } else { $custom = new UserSetting(); $custom->user_id = Yii::app()->user->id; $custom->param_name = $row->name; } $customizable[] = $custom; } } } $paramForm = $this->createWidget('Admin.components.ParamForm', array('params' => $data, 'config' => null)); //TODO: load module param definitions into $config // save new values if (Yii::app()->request->IsPostRequest) { //save User Settings to user_setting if (is_array($customizable) && count($customizable)) { foreach ($customizable as $custom) { if ($custom instanceof UserSetting && isset($_POST[$custom->param_name])) { $custom->value = $_POST[$custom->param_name]; if (!$custom->save()) { Yii::log(CVarDumper::dumpAsString($custom->getErrors()), CLogger::LEVEL_ERROR, 'Admin.Setting'); } //force not save global setting unset($_POST[$custom->param_name]); } } } $paramForm->saveParams($_POST, ParamForm::TO_SETTING_TABLE); //update Settings Class if ($currentWorkflow->id == $workflowId && isset($_POST['SettingParam'], $_POST['SettingParam']['module'])) { $module = $_POST['SettingParam']['module']; if ($module == 'module_system') { $module = ''; } $this->api('Xpress.Settings.db2php', array('module' => $module)); } //update parameters to global and other workflows foreach ($paramForm->params as $param) { if (isset($_POST['sync_global'])) { $this->api('Xpress.SettingParam.syncValue', array('attrs' => $param->attributes)); //update cache file global $this->api('Xpress.Settings.db2php', array('module' => $param->module, 'path' => cachePath(true))); } if (isset($_POST['sync_other'])) { $this->api('Xpress.SettingParam.syncValueToOther', array('attrs' => $param->attributes)); } } //TODO: need fix validate in ParamForm //errorHandler()->getErrorMessages(); } $this->render('index', array('modules' => $modules, 'module' => $model->module, 'form' => $paramForm, 'workflowId' => $workflowId, 'workflows' => $workflows)); }
/** * Returns a settings record by Name and Module Id * The result is cached. * * @param type $userId * @param type $name * @param type $moduleId * @return \HSetting */ private static function GetRecord($userId, $name, $moduleId = "core") { if ($moduleId == "") { $moduleId = "core"; } $cacheId = 'UserSetting_' . $userId . '_' . $name . '_' . $moduleId; // Check if stored in Runtime Cache if (RuntimeCache::Get($cacheId) !== false) { return RuntimeCache::Get($cacheId); } // Check if stored in Cache $cacheValue = Yii::app()->cache->get($cacheId); if ($cacheValue !== false) { return $cacheValue; } $condition = ""; $params = array('name' => $name, 'user_id' => $userId); if ($moduleId != "") { $params['module_id'] = $moduleId; } else { $condition = "module_id IS NULL"; } $record = UserSetting::model()->findByAttributes($params, $condition); if ($record == null) { $record = new UserSetting(); $record->user_id = $userId; $record->module_id = $moduleId; $record->name = $name; } else { $expireTime = 3600; if ($record->name != 'expireTime' && $record->module_id != "cache") { $expireTime = HSetting::Get('expireTime', 'cache'); } Yii::app()->cache->set($cacheId, $record, $expireTime); RuntimeCache::Set($cacheId, $record); } return $record; }