Example #1
0
 public function actionUpdate()
 {
     $op = Yii::app()->request->getParam('op', '');
     $id = Yii::app()->request->getPost('id', '');
     $code = Yii::app()->request->getPost("code", '');
     $name = Yii::app()->request->getPost("name", '');
     if (!$name || !$code) {
         $this->_output(-1, '参数错误');
     }
     $configModel = new ConfigModel();
     $configModel['type'] = Yii::app()->params['configType']['HOSPITAL'];
     $configModel['c_key'] = $code;
     $configModel['c_value'] = $name;
     $hospitalModel = new ConfigModel();
     $hospitals = $hospitalModel->getSetByType(Yii::app()->params['configType']['HOSPITAL']);
     //共享
     $shares = array();
     $my = new ShareModel();
     $my->setIsNewRecord(1);
     $my['hospital'] = $code;
     $my['target_hospital'] = $code;
     $my['permission'] = join(',', array_keys(Yii::app()->params['permission']));
     $shares[$code] = $my;
     foreach ($hospitals as $key => $value) {
         $permission = Yii::app()->request->getPost('permission_' . $key, '');
         if ($permission) {
             $item = new ShareModel();
             $item->setIsNewRecord(1);
             $item['hospital'] = $code;
             $item['target_hospital'] = $key;
             $item['permission'] = join(',', $permission);
             $shares[$key] = $item;
         }
     }
     //更新
     if ($op == 'edit' && $id && ($hospital = $configModel->getModel($configModel['type'], $code))) {
         $configModel['id'] = $hospital['id'];
         $configModel->update();
     }
     // 新增
     if ($op == 'add') {
         $configModel->setIsNewRecord(1);
         $configModel->save();
     }
     $shareModel = new ShareModel();
     $shareModel->deleteByHospital($code);
     $shareModel->saveMany($shares);
     $this->redirect(Yii::app()->getBaseUrl() . "/admin/hospital/list");
 }
	public static function _ConfigSubmit(Form $form) {
		$elements = $form->getElements();

		$updatedcount = 0;

		foreach ($elements as $e) {
			/** @var FormElement $e */
			
			// I'm only interested in config options.
			if (strpos($e->get('name'), 'config[') === false) continue;

			// Make the name usable a little.
			$n = $e->get('name');
			if (($pos = strpos($n, '[]')) !== false) $n = substr($n, 0, $pos);
			$n = substr($n, 7, -1);

			// And get the config object
			$c = new ConfigModel($n);
			$val = null;

			switch ($c->get('type')) {
				case 'string':
				case 'text':
				case 'enum':
				case 'boolean':
				case 'int':
					$val = $e->get('value');
					break;
				case 'set':
					$val = implode('|', $e->get('value'));
					break;
				default:
					throw new Exception('Unsupported configuration type for ' . $c->get('key') . ', [' . $c->get('type') . ']');
					break;
			}

			// This is required because enterprise multisite mode has a different location for site configs.
			if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::GetCurrentSiteID()){
				$siteconfig = MultiSiteConfigModel::Construct($c->get('key'), MultiSiteHelper::GetCurrentSiteID());
				$siteconfig->setValue($val);
				if($siteconfig->save()) ++$updatedcount;
			}
			else{
				$c->setValue($val);
				if ($c->save()) ++$updatedcount;
			}

		}

		\Core\set_message('t:MESSAGE_SUCCESS_UPDATED_N_CONFIGURATION', $updatedcount);

		return true;
	}