Beispiel #1
0
 public function actionUpdate($content_model_id, $id, $page = null)
 {
     $field = ContentModelField::get_field_by_id($id, false);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!isset($_POST['Field']) || !is_array($_POST['Field'])) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('保存模型字段信息错误', self::MSG_ERROR, true);
         }
         if ($_POST['Field']['content_model_field_name'] == '') {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('字段名称不能为空', self::MSG_ERROR, true);
         }
         /*if($_POST['Field']['content_model_field_identify'] =='') {
         			$this->redirect[] = array(
         				'text' => '',
         				'href' => 'javascript:history.go(-1);',
         			);
         			$this->message('字段标识不能为空', self::MSG_ERROR, true);
         		}
         		
         		if(!preg_match("/^[\w]+$/",$_POST['Field']['content_model_field_identify'])) {
         			$this->redirect[] = array(
         				'text' => '',
         				'href' => 'javascript:history.go(-1);',
         			);
         			$this->message('字段标识只能为英文字母', self::MSG_ERROR, true);
         		}*/
         if (!isset($_POST['Field']['content_model_field_type']) || $_POST['Field']['content_model_field_type'] == '') {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('请选择字段数据类型', self::MSG_ERROR, true);
         }
         if (intval($_POST['Field']['content_model_field_max_length']) < 1) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('字段最大长度格式错误,请填写大于0的数字', self::MSG_ERROR, true);
         }
         /*$content_model_field = ContentModelField::get_field_by_id($id);
         		$sql = "SELECT `content_model_field_identify` FROM {{content_model_fields}}
         				WHERE content_model_field_id<>:content_model_field_id AND `content_model_field_status`<>:content_model_field_status AND content_model_field_identify=:content_model_field_identify  AND `content_model_id`=:content_model_id";
         		$cmd = Yii::app()->db->createCommand($sql);
         		$cmd->bindValue(':content_model_field_id', $id);
         		$cmd->bindValue(':content_model_field_status', ContentModelField::STAT_DELETED);
         		$cmd->bindValue(':content_model_field_identify', $_POST['Field']['content_model_field_identify']);
         		$cmd->bindValue(':content_model_id', $content_model_id);
         		$cmd->execute();
         		
         		if($cmd->queryScalar()) {
         			$this->redirect[] = array(
         				'text' => '',
         				'href' => 'javascript:history.go(-1);',
         			);
         			$this->message('字段标识重复', self::MSG_ERROR, true);
         		}*/
         $flag = Yii::app()->db->createCommand()->update('{{content_model_fields}}', array('content_model_field_name' => $_POST['Field']['content_model_field_name'], 'content_model_field_type' => isset($_POST['Field']['content_model_field_type']) ? intval($_POST['Field']['content_model_field_type']) : 0, 'content_model_field_default' => $_POST['Field']['content_model_field_default'], 'content_model_field_tips' => $_POST['Field']['content_model_field_tips'], 'content_model_field_max_length' => isset($_POST['Field']['content_model_field_max_length']) ? intval($_POST['Field']['content_model_field_max_length']) : 1, 'content_model_field_rank' => !empty($_POST['Field']['content_model_field_rank']) ? intval($_POST['Field']['content_model_field_rank']) : 255, 'content_model_field_lasttime' => $_SERVER['REQUEST_TIME']), 'content_model_field_id=:content_model_field_id', array(':content_model_field_id' => $id));
         //
         if ($flag) {
             //更新缓存
             ContentModelField::update_cache();
             $content_model_identify = ContentModel::get_model_identify_by_id($content_model_id);
             $newfields = array(array('field_name' => $_POST['Field']['content_model_field_name'], 'field_identify' => $field['content_model_field_identify'], 'field_type' => $_POST['Field']['content_model_field_type'], 'field_length' => $_POST['Field']['content_model_field_max_length']));
             if (ContentModel::alter_addons_table($content_model_identify, $newfields)) {
                 //更新附加表成功
             } else {
                 //更新附加表失败
             }
             //记录操作日志
             $user = Yii::app()->user;
             $message = '{user_name}修改内容模型字段({field_name})信息成功';
             $data = array('user_id' => $user->id, 'user_name' => $user->name, 'field_name' => $field['content_model_field_name'], 'data' => array('content_model_field_id' => $id));
             AdminLogs::add($user->id, 'Content/Model/Field', $id, 'Modify', 'success', $message, $data);
         }
         if (!isset($_GET['ajax'])) {
             $this->redirect[] = array('text' => '', 'href' => url($this->module->id . "/Content/Model/{$content_model_id}/Field/Index"));
             $this->message('修改模型字段完成', self::MSG_SUCCESS, true);
         }
     }
     if (empty($field)) {
         $this->redirect[] = array('text' => '', 'href' => url($this->module->id . "/Collect/Model/{$content_model_id}/Field/Index"));
         $this->message('模型字段不存在或已被删除', self::MSG_ERROR, true);
     }
     $this->render('update', array('field' => $field, "content_model_id" => $content_model_id));
 }