示例#1
0
 /**
  * 
  * @param unknown_type $params
  */
 public function getTemplateById($collect_template_id, $allow_cache = false)
 {
     if (isset($this->cache) && $allow_cache) {
         //
         $cacheKey = "collect.template.row.{$collect_template_id}";
         $ret = json_decode($this->cache->get($cacheKey), true);
         if (!empty($ret) && is_array($ret)) {
             return $ret;
         }
     }
     $sql = "SELECT * FROM {{collect_template}} WHERE collect_template_id=:collect_template_id";
     $params = array(':collect_template_id' => $collect_template_id);
     $ret = $this->db->queryRow($sql, $params);
     $ret['collect_template_list_rules'] && ($ret['collect_template_list_rules'] = json_decode($ret['collect_template_list_rules'], true));
     if (!is_array($ret['collect_template_list_rules'])) {
         $ret['collect_template_list_rules'] = array();
     }
     $ret['collect_template_addons_rules'] && ($ret['collect_template_addons_rules'] = json_decode($ret['collect_template_addons_rules'], true));
     if (!is_array($ret['collect_template_addons_rules'])) {
         $ret['collect_template_addons_rules'] = array();
     }
     $fields = CollectModelFieldModel::inst()->getFieldsByModelId($ret['collect_model_id']);
     foreach ($fields as $_k => $_v) {
         if (isset($ret['collect_template_addons_rules'][$_v['collect_fields_identify']])) {
             $ret['collect_template_addons_rules'][$_v['collect_fields_identify']] += $_v;
         } else {
             $_v['begin'] = '';
             $_v['end'] = '';
             $ret['collect_template_addons_rules'][$_v['collect_fields_identify']] = $_v;
         }
     }
     unset($fields, $_k, $_v);
     if (!empty($ret) && isset($this->cache) && $allow_cache) {
         //
         $this->cache->set($cacheKey, json_encode($ret));
     }
     return $ret;
 }
示例#2
0
 /**
  * 
  * @param unknown_type $params
  */
 public function getTaskById($collect_task_id, $allow_cache = false)
 {
     if (isset($this->cache) && $allow_cache) {
         //
         $_cache_key = md5("collect.task.row.{$collect_task_id}");
         $ret = json_decode($this->cache->get($_cache_key), true);
         if (!empty($ret) && is_array($ret)) {
             return $ret;
         }
     }
     $sql = "SELECT t.*, tp.collect_model_id, tp.collect_template_list_rules, tp.collect_template_addons_rules, m.collect_model_id, m.collect_model_name, m.collect_model_identify, s.collect_source_id FROM {{collect_task}} t\n\t\t\t\tINNER JOIN {{collect_template}} tp ON tp.collect_template_id=t.collect_template_id\n\t\t\t\tINNER JOIN {{collect_model}} m ON m.collect_model_id=tp.collect_model_id\n\t\t\t\tINNER JOIN {{collect_source}} s ON s.collect_source_id=tp.collect_source_id\n\t\t\t\tWHERE t.collect_task_id=:collect_task_id";
     $params = array(':collect_task_id' => $collect_task_id);
     $ret = $this->db->queryRow($sql, $params);
     // 列表规则
     $ret['collect_task_list_rules'] && ($ret['collect_task_list_rules'] = json_decode($ret['collect_task_list_rules'], true));
     $ret['collect_template_list_rules'] && ($ret['collect_template_list_rules'] = json_decode($ret['collect_template_list_rules'], true));
     if (!is_array($ret['collect_task_list_rules'])) {
         $ret['collect_task_list_rules'] = array();
     }
     // 列表开始
     if (!empty($ret['collect_task_list_rules']['begin'])) {
         $ret['collect_list_rules']['begin'] = $ret['collect_task_list_rules']['begin'];
     } else {
         $ret['collect_list_rules']['begin'] = $ret['collect_template_list_rules']['begin'];
     }
     $ret['collect_list_rules']['begin'] = self::rule2reg($ret['collect_list_rules']['begin']);
     // 列表结束
     if (!empty($ret['collect_task_list_rules']['end'])) {
         $ret['collect_list_rules']['end'] = $ret['collect_task_list_rules']['end'];
     } else {
         $ret['collect_list_rules']['end'] = $ret['collect_template_list_rules']['end'];
     }
     $ret['collect_list_rules']['end'] = self::rule2reg($ret['collect_list_rules']['end']);
     // 附加规则
     $ret['collect_task_addons_rules'] && ($ret['collect_task_addons_rules'] = json_decode($ret['collect_task_addons_rules'], true));
     $ret['collect_template_addons_rules'] && ($ret['collect_template_addons_rules'] = json_decode($ret['collect_template_addons_rules'], true));
     if (!is_array($ret['collect_task_addons_rules'])) {
         $ret['collect_content_rules'] = array();
     } else {
         $ret['collect_content_rules'] = $ret['collect_task_addons_rules'];
     }
     unset($ret['collect_task_list_rules'], $ret['collect_task_addons_rules']);
     $collect_model_fields = CollectModelFieldModel::inst()->getFieldsByModelId($ret['collect_model_id']);
     foreach ($collect_model_fields as $_k => $_v) {
         if (empty($ret['collect_content_rules'][$_v['collect_fields_identify']]['begin'])) {
             $ret['collect_content_rules'][$_v['collect_fields_identify']]['begin'] = $ret['collect_template_addons_rules'][$_v['collect_fields_identify']]['begin'];
         }
         if (empty($ret['collect_content_rules'][$_v['collect_fields_identify']]['end'])) {
             $ret['collect_content_rules'][$_v['collect_fields_identify']]['end'] = $ret['collect_template_addons_rules'][$_v['collect_fields_identify']]['end'];
         }
         $ret['collect_content_rules'][$_v['collect_fields_identify']]['begin'] = self::rule2reg($ret['collect_content_rules'][$_v['collect_fields_identify']]['begin']);
         $ret['collect_content_rules'][$_v['collect_fields_identify']]['end'] = self::rule2reg($ret['collect_content_rules'][$_v['collect_fields_identify']]['end']);
         $ret['collect_content_rules'][$_v['collect_fields_identify']] += $_v;
     }
     unset($collect_model_fields, $_k, $_v, $ret['collect_template_list_rules'], $ret['collect_template_addons_rules']);
     // 采集任务附加规则
     foreach ($ret['collect_content_rules'] as $_k => $_v) {
         $rules['addons'][$_k] = $_v;
         if (empty($_v['begin'])) {
             $rules['addons'][$_k]['begin'] = $ret['collect_template_addons_rules'][$_k]['begin'];
         }
         if (empty($_v['end'])) {
             $rules['addons'][$_k]['end'] = $ret['collect_template_addons_rules'][$_k]['end'];
         }
         $rules['addons'][$_k]['begin'] = self::rule2reg($rules['addons'][$_k]['begin']);
         $rules['addons'][$_k]['end'] = self::rule2reg($rules['addons'][$_k]['end']);
     }
     if (!empty($ret) && isset($this->cache) && $allow_cache) {
         //
         $this->cache->set($_cache_key, json_encode($ret));
     }
     return $ret;
 }
示例#3
0
文件: Fields.php 项目: nbaiwan/yav
 public function indexAction($collect_model_id = null)
 {
     $this->getView()->assign(array('fields' => CollectModelFieldModel::inst()->Pages(array('allow_cache' => false, "collect_model_id" => $collect_model_id)), "collect_model_id" => $collect_model_id));
 }
示例#4
0
文件: Template.php 项目: nbaiwan/yav
 public function ruleAction($id)
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $template_fields = array();
         if ($_POST['Rule']) {
             $this->db->update('{{collect_template}}', array('collect_template_list_rules' => json_encode($_POST['Rule']['List']), 'collect_template_addons_rules' => json_encode($_POST['Rule']['Addons'])), 'collect_template_id=:collect_template_id', array(':collect_template_id' => intval($id)));
         }
         if (!isset($_GET['ajax'])) {
             $this->redirect[] = array('text' => '', 'href' => '/collect/template/index');
             $this->message('修改模板规则完成', self::MSG_SUCCESS, true);
         }
     }
     $template = CollectTemplateModel::inst()->getTemplateById($id);
     $fields = CollectModelFieldModel::inst()->getFieldsByModelId($template['collect_model_id']);
     foreach ($fields as $_k => $_v) {
         if (isset($template['collect_template_addons_rules'][$_v['collect_fields_identify']])) {
             $template['collect_template_addons_rules'][$_v['collect_fields_identify']] += $_v;
         } else {
             $rules['collect_template_addons_rules'][$_v['collect_fields_identify']] = $_v;
         }
     }
     unset($fields);
     $this->getView()->assign(array('template' => $template));
 }
示例#5
0
 /**
  * 强制更新缓存
  */
 public function updateCache()
 {
     //
     self::$__fields = null;
     //
     if (isset($this->cache)) {
         self::$__fields = $this->readFieldsArray();
         $this->cache->set('collect.model.fields', self::$__fields);
     }
     return true;
 }