Ejemplo n.º 1
0
 public function actionCreate()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (!isset($_POST['Model']) || !is_array($_POST['Model'])) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('保存采集模型信息错误', self::MSG_ERROR, true);
         }
         if ($_POST['Model']['collect_model_name'] == '') {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('采集模型名称不能为空', self::MSG_ERROR, true);
         }
         if ($_POST['Model']['collect_model_identify'] == '') {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('采集模型标识不能为空', self::MSG_ERROR, true);
         }
         if (preg_match("/^[0-9]+.*/", $_POST['Fields']['collect_model_identify'])) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('采集模型标识不能以数字开头', self::MSG_ERROR, true);
         }
         $old_collect_model_identify = CollectModel::get_model_identify_by_id($id);
         $sql = "SELECT `collect_model_identify` FROM `collect_model` WHERE collect_model_identify=:collect_model_identify AND `collect_model_status`!=:collect_model_status";
         $cmd = $this->db->createCommand($sql);
         $cmd->execute(array(':collect_model_identify' => $_POST['Model']['collect_model_identify'], ":collect_model_status" => CollectModel::STAT_STATUS_DELETED));
         if ($cmd->queryScalar()) {
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('采集模型标识不能重复', self::MSG_ERROR, true);
         }
         $flag = $this->db->createCommand()->insert('{{collect_model}}', array('collect_model_id' => 0, 'collect_model_name' => $_POST['Model']['collect_model_name'], 'collect_model_identify' => $_POST['Model']['collect_model_identify'], 'collect_model_status' => CollectModel::STAT_STATUS_NORMAL, 'collect_model_rank' => $_POST['Model']['collect_model_rank'], 'collect_model_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_model_dateline' => $_SERVER['REQUEST_TIME'], 'content_model_id' => $_POST['Model']['content_model_id']));
         if ($flag) {
             $collect_model_id = $this->db->getLastInsertID();
             $collect_model_name = $_POST['Model']['collect_model_name'];
             $sql = "create table `collect_model_addons{$_POST['Model']['collect_model_identify']}` (\n\t\t\t\t\t\t`collect_content_id` int unsigned not null auto_increment,\n\t\t\t\t\t\t`collect_list_id` int unsigned not null comment '采集列表id',\n\t\t\t\t\t\t`collect_content_body` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL comment '正文内容',\n\t\t\t\t\t\t`collect_content_day` date not null comment '采集时间',\n\t\t\t\t\t\tPRIMARY KEY  (`collect_content_id`),\n\t\t\t\t\t\tUNIQUE KEY `collect_list_id` (`collect_list_id`)\n\t\t\t\t\t)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='{$_POST['Model']['collect_model_name']}附加表';";
             $this->db->createCommand($sql)->execute();
             $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '链接地址', 'collect_fields_identify' => 'collect_content_url', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME']));
             $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '标题', 'collect_fields_identify' => 'collect_content_title', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME']));
             $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '缩略图', 'collect_fields_identify' => 'collect_content_thumb', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 1, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME']));
             $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '内容', 'collect_fields_identify' => 'collect_content_body', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 2, 'collect_fields_belong' => 2, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME']));
             $this->db->createCommand()->insert('{{collect_fields}}', array('collect_fields_id' => 0, 'collect_model_id' => $collect_model_id, 'collect_fields_name' => '发布时间', 'collect_fields_identify' => 'collect_content_publish_time', 'collect_fields_status' => CollectFields::STAT_STATUS_NORMAL, 'collect_fields_rank' => 255, 'collect_fields_type' => 1, 'collect_fields_belong' => 3, 'collect_fields_system' => 1, 'collect_fields_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_fields_dateline' => $_SERVER['REQUEST_TIME']));
             //更新缓存
             CollectModelModel::inst()->updateCache();
             //记录操作日志
             $message = '{user_name}添加采集来源{collect_model_name}';
             $data = array('collect_model_name' => $collect_model_name, 'addons_data' => array('collect_model_id' => $collect_model_id));
             UserLogsModel::inst()->add('Collect/Model', $collect_model_id, 'Insert', 'success', $message, $data);
             if (!isset($_GET['ajax'])) {
                 $this->redirect[] = array('text' => '', 'href' => '/collect/model/index');
                 $this->message('添加采集模型完成', self::MSG_SUCCESS, true);
             }
         } else {
             //记录操作日志
             $message = '{user_name}添加采集模型{$collect_model_name}失败';
             $data = array('collect_model_name' => $collect_model_name, 'addons_data' => array('model' => $_POST['Model']));
             UserLogsModel::inst()->add('Collect/Model', $collect_model_id, 'Insert', 'failure', $message, $data);
             $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);');
             $this->message('添加采集模型失败', self::MSG_ERROR, true);
         }
     }
     $model = array('collect_model_id' => 0, 'collect_model_name' => '', 'collect_model_identify' => '', 'content_model_id' => 0, 'collect_model_status' => CollectModelModel::STAT_STATUS_NORMAL, 'collect_model_rank' => 255, 'collect_model_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_model_dateline' => $_SERVER['REQUEST_TIME']);
     $this->render('create', array('model' => $model, 'content_model' => CollectModelModel::inst()->getModelsByCache()));
 }
Ejemplo n.º 2
0
 public function actionDelete($collect_model_id, $id)
 {
     $collect_fields_name = CollectModelField::get_fields_name_by_id($id);
     $collect_model_identify = CollectModel::get_model_identify_by_id($collect_model_id);
     $collect_fields = CollectModelField::get_fields_identify_by_id($collect_model_id, $id);
     $sql = "ALTER TABLE `collect_model_addons{$collect_model_identify}` DROP  `" . $collect_fields['collect_fields_identify'] . "`";
     Yii::app()->db->createCommand($sql)->execute();
     Yii::app()->db->createCommand()->update('{{collect_model_fields}}', array('collect_fields_status' => CollectModelField::STAT_DELETED), 'collect_fields_id=:collect_fields_id', array(':collect_fields_id' => $id));
     CollectModelField::update_cache();
     //记录操作日志
     $user = Yii::app()->user;
     $message = '{user_name}删除了采集字段{collect_fields_name}';
     $data = array('user_id' => $user->id, 'user_name' => $user->name, 'collect_fields_name' => $collect_fields_name, 'data' => array('collect_fields_id' => $id));
     AdminLogs::add($user->id, 'Collect/Fields', $id, 'Delete', 'success', $message, $data);
     if (!isset($_GET['ajax'])) {
         $this->redirect(array("Collect/Model/{$collect_model_id}/Fields/Index"));
     }
 }