public function createAction() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['Template']) || !is_array($_POST['Template'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存采集模板信息错误', self::MSG_ERROR, true); } if ($_POST['Template']['collect_template_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集模板名称不能为空', self::MSG_ERROR, true); } if ($_POST['Template']['collect_source_id'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('请选择一个采集来源', self::MSG_ERROR, true); } /*if($_POST['Template']['collect_template_charset'] =='') { $this->redirect[] = array( 'text' => '', 'href' => 'javascript:history.go(-1);', ); $this->message('请选择一个编码', self::MSG_ERROR, true); }*/ if ($_POST['Template']['collect_model_id'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('请选择一个采集模型', self::MSG_ERROR, true); } $flag = $this->db->insert('{{collect_template}}', array('collect_template_id' => 0, 'collect_template_name' => $_POST['Template']['collect_template_name'], 'collect_source_id' => $_POST['Template']['collect_source_id'], 'collect_model_id' => $_POST['Template']['collect_model_id'], 'collect_template_remark' => $_POST['Template']['collect_template_remark'], 'collect_template_list_rules' => json_encode(array()), 'collect_template_addons_rules' => json_encode(array()), 'collect_template_rank' => $_POST['Template']['collect_template_rank'], 'collect_template_status' => CollectTemplateModel::STAT_STATUS_NORMAL, 'collect_template_lasttime' => $_SERVER['REQUEST_TIME'], 'collect_template_dateline' => $_SERVER['REQUEST_TIME'], 'update_user_id' => $this->user->id, 'insert_user_id' => $this->user->id)); if ($flag) { $collect_template_id = $this->db->getLastInsertID(); $collect_template_name = $_POST['Template']['collect_template_name']; /*$sql = "SELECT `collect_fields_id` FROM {{collect_model_fields}} WHERE `collect_model_id`=:collect_model_id AND `collect_fields_status`!=:collect_fields_status"; $cmd = $this->db->createCommand($sql); $cmd->execute(array(':collect_fields_status'=>CollectModelField::STAT_STATUS_DELETED,":collect_model_id"=>$_POST['Template']['collect_model_id'])); $fields_arr = $cmd->queryAll(); if(is_array($fields_arr) && count($fields_arr)){ foreach($fields_arr as $k=>$v){ $this->db->createCommand()->insert('{{collect_template2fields}}', array( 'collect_fields_id' => $v['collect_fields_id'], 'collect_template_id' => $collect_template_id, 'collect_template_rule_status' => CollectTemplateModel::STAT_STATUS_NORMAL, ) ); } }*/ //记录操作日志 $message = '{user_name}添加采集模板{collect_template_name}'; $data = array('collect_template_name' => $collect_template_name, 'data' => array('collect_template_id' => $collect_template_id)); UserLogsModel::inst()->add('Collect/Template', $collect_template_id, 'Insert', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => '/collect/template/' . $collect_template_id . '/rule'); $this->message('添加采集模板完成,请添加规则', self::MSG_SUCCESS, true); } } else { //记录操作日志 $message = '{user_name}添加采集模板{collect_template_name}失败'; $data = array('collect_template_name' => $collect_template_name, 'data' => array('template' => $_POST['Template'])); UserLogsModel::inst()->add('Collect/Template', $collect_template_id, 'Insert', 'failure', $message, $data); $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('添加采集模板失败', self::MSG_ERROR, true); } } $sql = "SELECT `collect_model_id`,`collect_model_name` FROM `{{collect_model}}` WHERE `collect_model_status`!=:collect_model_status"; $params = array(':collect_model_status' => CollectModelModel::STAT_STATUS_DELETED); $model_arr = $this->db->queryAll($sql, $params); $sql = "SELECT `collect_source_id`,`collect_source_name` FROM `{{collect_source}}` WHERE `collect_source_status`!=:collect_source_status"; $params = array(':collect_source_status' => CollectSourceModel::STAT_STATUS_DELETED); $source_arr = $this->db->queryAll($sql, $params); $charset = CollectTaskModel::getCharsets(); $template = array('collect_source_id' => 0, 'collect_model_id' => 0, 'collect_template_name' => '', 'collect_template_remark' => '', 'model_arr' => $model_arr, 'source_arr' => $source_arr, 'charset' => $charset, 'collect_template_rank' => 255); $this->getView()->assign(array('template' => $template)); }
public function updateAction($id) { $task = CollectTaskModel::inst()->getTaskById($id); if (empty($task)) { $this->redirect[] = array('text' => '', 'href' => '/collect/task/index'); $this->message('采集规则不存在或已被删除', self::MSG_ERROR, true); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['Task']) || !is_array($_POST['Task'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存采集任务信息错误', self::MSG_ERROR, true); } if ($_POST['Task']['collect_task_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('采集任务名称不能为空', self::MSG_ERROR, true); } if ($_POST['Task']['collect_template_id'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('请选择一个采集模板', self::MSG_ERROR, true); } $flag = $this->db->update('{{collect_task}}', array('collect_task_name' => $_POST['Task']['collect_task_name'], 'collect_template_id' => $_POST['Task']['collect_template_id'], 'collect_task_urls' => $_POST['Task']['collect_task_urls'], 'collect_task_list_rules' => json_encode($_POST['Task']['List']), 'collect_task_addons_rules' => json_encode($_POST['Task']['Addons']), 'collect_task_rank' => isset($_POST['Task']['collect_task_rank']) ? $_POST['Task']['collect_task_rank'] : 255, 'collect_task_lasttime' => $_SERVER['REQUEST_TIME']), 'collect_task_id=:collect_task_id', array(':collect_task_id' => $id)); if ($flag) { //记录操作日志 $message = '{user_name}修改了采集任务{collect_task_name}'; $data = array('collect_task_name' => $_POST['Task']['collect_task_name'], 'data' => array('ori' => $task, 'new' => $_POST['Task'])); UserLogsModel::inst()->add('Collect/Task', $id, 'Modify', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => '/collect/task/index'); $this->message('保存采集任务成功', self::MSG_SUCCESS, true); } } else { //记录操作日志 $message = '{user_name}修改采集任务({collect_task_name})信息失败'; $data = array('collect_task_name' => $_POST['Task']['collect_task_name'], 'data' => $_POST['Task']); UserLogsModel::inst()->add('Collect/Task', $id, 'Modify', 'failure', $message, $data); $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存采集任务失败', self::MSG_ERROR, true); } } $models = CollectModelModel::inst()->getModelsByCache(); $sources = CollectSourceModel::inst()->getSourcesByCache(); $templates = CollectTemplateModel::inst()->getTemplatesByCache(); $charsets = CollectTaskModel::getCharsets(); // $task['template'] = CollectTemplateModel::inst()->getTemplateById($task['collect_template_id']); $this->getView()->assign(array('task' => $task, 'models' => $models, 'sources' => $sources, 'templates' => $templates, 'charsets' => $charsets)); }
/** * * Enter description here ... * @param unknown_type $params */ public function Pages($params = array()) { //设置默认参数 $_defaults_params = array('allow_cache' => true, 'page' => isset($_GET['page']) ? intval($_GET['page']) : 1, 'pagesize' => 10); $params = array_merge($_defaults_params, $params); //有开启缓存功能,则从缓存中取数据, 如果有数据,则直接返回结果 if ($params['allow_cache'] && isset($this->cache)) { $cacheKey = 'collect.template.pages.' . serialize($params); $ret = $this->cache->get($cacheKey); if ($_r && is_array($ret)) { return $ret; } } //添加条件 $builds = array('select' => 'COUNT(ct.collect_template_id) AS COUNT', 'from' => array('{{collect_template}}', 'ct'), 'join' => array(array('{{collect_source}}', 'cs', '`cs`.`collect_source_id`=`ct`.`collect_source_id`'), array('{{collect_model}}', 'cm', '`cm`.`collect_model_id`=`ct`.`collect_model_id`'))); $sql_params = array(); if (isset($params['collect_template_status']) && !empty($params['collect_template_status'])) { $builds['where'][] = array('AND', 'ct.collect_template_status=:collect_template_status'); $sql_params[':collect_template_status'] = $params['collect_template_status']; } else { $builds['where'][] = array('AND', 'ct.collect_template_status>:collect_template_status'); $sql_params[':collect_template_status'] = 0; } // if (isset($params['collect_template_id']) && !empty($params['collect_template_id'])) { $builds['where'][] = array('AND', 'ct.collect_template_id=:collect_template_id'); $sql_params[':collect_template_id'] = $params['collect_template_id']; } if (isset($params['collect_model_id']) && !empty($params['collect_model_id'])) { $builds['where'][] = array('AND', 'ct.collect_model_id=:collect_model_id'); $sql_params[':collect_model_id'] = $params['collect_model_id']; } if (isset($params['collect_source_id']) && !empty($params['collect_source_id'])) { $builds['where'][] = array('AND', 'ct.collect_source_id=:collect_source_id'); $sql_params[':collect_source_id'] = $params['collect_source_id']; } if (isset($params['collect_template_id']) && !empty($params['collect_template_id'])) { $builds['where'][] = array('AND', 'ct.collect_template_id=:collect_template_id'); $sql_params[':collect_template_id'] = $params['collect_template_id']; } // if (isset($params['collect_template_name']) && !empty($params['collect_template_name'])) { $builds['where'][] = array('LIKE', 'ct.collect_template_name', ':collect_template_name'); $sql_params[':collect_template_name'] = "%{$params['collect_template_name']}%"; } // // if (isset($params['searchKey']) && $params['searchKey']) { $builds['where'][] = array('LIKE', 'ct.collect_template_name', ':collect_template_name'); $sql_params[':collect_template_name'] = "%{$params['searchKey']}%"; } $sql = $this->buildQuery($builds); //统计数量 $count = $this->db->queryScalar($sql, $sql_params); //分页处理 $pages = new CPagination($count); //设置分页大小 $pages->pageSize = $params['pagesize']; if (isset($params['orderby']) && $params['orderby']) { $builds['order'] = $params['orderby']; } else { $builds['order'] = array('ct.collect_template_rank ASC', 'ct.collect_template_id DESC'); } $builds['select'] = 'ct.collect_template_id,ct.collect_template_rank, ct.collect_template_name, ct.collect_template_charset, cs.collect_source_name, cm.collect_model_name, ct.collect_template_lasttime, ct.collect_template_dateline'; $pages->applyLimit($builds); $sql = $this->buildQuery($builds); $ret['pages'] = $pages; $ret['rows'] = $this->db->queryAll($sql, $sql_params); $charset = CollectTaskModel::getCharsets(); foreach ($ret['rows'] as $_k => $_v) { $ret['rows'][$_k]['collect_template_charset'] = $charset[$_v['collect_template_charset']]; } //有开启缓存,则把结果添加到缓存中 /*if($params['allow_cache'] && isset($this->cache)) { $_cache_cache_time = Setting::get_setting_value('COLLECT_TEMPLATE_PAGES_CACHE_TIME'); $this->cache->set($cacheKey, json_encode($ret), $_cache_cache_time); unset($_cache_cache_time, $cacheKey); }*/ return $ret; }