Ejemplo n.º 1
0
 /**
  * 编辑单元
  * 
  * @param  array $data 单元信息
  * @return  array 编辑过后的单元的详细信息
  */
 public function cellUpdate($data)
 {
     if (!$data) {
         return false;
     }
     if (is_array($data) && count($data) > 0) {
         if (!class_exists('cell')) {
             include_once CUR_CONF_PATH . 'lib/cell.class.php';
         }
         $this->obj = new cell();
         $return = array();
         foreach ($data as $k => $v) {
             $oriCellInfo = $this->obj->detail(" AND id = " . $v['id']);
             $info = array();
             $condition = " AND site_id = " . intval($v['site_id']) . " AND page_id = " . intval($v['page_id']) . " AND page_data_id = " . intval($v['page_data_id']) . " AND content_type = " . intval($v['content_type']) . " AND template_sign = '" . $v['template_sign'] . "' AND template_style = '" . $v['template_style'] . "' AND cell_name='" . $v['cell_name'] . "' AND original_id != 0 AND del=0";
             $q = $this->obj->detail($condition);
             $param = array();
             if (is_array($v['input_param']) && count($v['input_param']) > 0) {
                 foreach ($v['input_param'] as $kk => $vv) {
                     $vv['value'] = str_replace("&#60;", '<', $vv['value']);
                     if ($vv['sign'] == 'count') {
                         $dataCountNum = $vv['value'];
                     }
                     if ($vv['value'] !== $vv['default_value']) {
                         $param['input_param'][$vv['sign']] = $vv['value'];
                     }
                 }
             }
             if (is_array($v['mode_param']) && count($v['mode_param']) > 0) {
                 foreach ($v['mode_param'] as $kk => $vv) {
                     $vv['value'] = str_replace("&#60;", '<', $vv['value']);
                     if ($vv['value'] !== $vv['default_value']) {
                         $param['mode_param'][$vv['sign']] = $vv['value'];
                     }
                 }
             }
             if (is_array($v['css_param']) && count($v['css_param']) > 0) {
                 foreach ($v['css_param'] as $kk => $vv) {
                     if ($vv['value'] !== $vv['default_value']) {
                         $param['css_param'][$vv['sign']] = $vv['value'];
                     }
                 }
             }
             if (is_array($v['js_param']) && count($v['js_param']) > 0) {
                 foreach ($v['js_param'] as $kk => $vv) {
                     if ($vv['value'] !== $vv['default_value']) {
                         $param['js_param'][$vv['sign']] = $vv['value'];
                     }
                 }
             }
             empty($this->arPageInfo) && ($this->arPageInfo = common::getPageBySign('special', 'id'));
             $blSpecial = $v['page_id'] == $this->arPageInfo['id'] ? 1 : 0;
             //取专题的页面,如果是专题单元时不自动选择css
             $v['css_id'] == 0 && $v['cell_mode'] && !$blSpecial && ($v['css_id'] = common::get_mode_default_css($v['cell_mode']));
             $v['css_id'] == -1 && ($v['css_id'] = 0);
             $info = array('css_id' => $v['css_id'], 'cell_type' => $v['cell_type'], 'cell_mode' => $v['cell_mode'], 'param_asso' => addslashes(serialize($param)), 'is_header' => $v['is_header'], 'header_text' => $v['header_text'], 'is_more' => $v['is_more'], 'more_href' => $v['more_href']);
             $info['cell_type'] != 3 && ($info['static_html'] = $v['static_html'] = '');
             isset($v['data_source']) && ($info['data_source'] = $v['data_source']);
             if ($info['cell_mode']) {
                 //区块样式处理
                 $modeDetail = $info['cell_mode'] ? common::modeDetail($info['cell_mode'], 'title') : array();
                 $info['using_block'] = $v['using_block'] = substr($modeDetail['title'], 0, 3) == 'qk_' ? 1 : 0;
                 if ($info['using_block']) {
                     $postFields = array('site_id' => intval($v['site_id']), 'page_id' => intval($v['page_id']), 'page_data_id' => intval($v['page_data_id']), 'content_type' => intval($v['content_type']), 'client_type' => $this->intClientType, 'datasource_id' => intval($info['data_source']), 'datasource_argument' => $param['input_param'], 'name' => $v['id'] . '_' . $v['cell_name'], 'expand_name' => $this->arPageColumnInfo['name'] ? $this->arPageColumnInfo['name'] : $this->arPageSiteInfo['site_name'], 'line_num' => $dataCountNum);
                 }
                 include_once ROOT_PATH . 'lib/class/block.class.php';
                 $objBlock = new block();
             }
             if ($oriCellInfo['using_block'] && !$info['using_block']) {
                 $objBlock->delete_block($oriCellInfo['block_id']);
                 $info['block_id'] = $v['block_id'] = 0;
             }
             if ($q || $this->blPreset && $this->blPreset != 'false' || $v['layout_id']) {
                 $info['update_time'] = TIMENOW;
                 if ($info['using_block']) {
                     $response = $v['block_id'] ? $objBlock->update_block($postFields, $v['block_id']) : $objBlock->insert_block($postFields);
                     !$v['block_id'] && ($info['block_id'] = $v['block_id'] = $response['id']);
                 }
                 if ($v['layout_id']) {
                     $condition = " id = " . $v['id'];
                     $this->db->update_data($info, 'layout_cell', $condition);
                 } else {
                     $this->obj->update($info, $v['id']);
                 }
             } else {
                 $info['block_id'] = $response['id'];
                 $info['original_id'] = $v['id'];
                 //原单元id
                 $info['create_time'] = TIMENOW;
                 $info['update_time'] = TIMENOW;
                 $info['sign'] = uniqid();
                 $info['cell_name'] = $v['cell_name'];
                 $info['template_style'] = $v['template_style'];
                 $info['sort_id'] = intval($v['sort_id']);
                 $info['template_id'] = $v['template_id'];
                 $info['template_sign'] = $v['template_sign'];
                 $info['site_id'] = $v['site_id'];
                 $info['page_id'] = $v['page_id'];
                 $info['page_data_id'] = $v['page_data_id'];
                 $info['content_type'] = $v['content_type'];
                 $v['original_id'] = $v['id'];
                 $v['id'] = $this->obj->create($info);
                 if ($info['using_block']) {
                     $postFields['name'] = $v['id'] . '_' . $v['cell_name'];
                     $response = $objBlock->insert_block($postFields);
                     $this->obj->update(array('block_id' => $response['id']), $v['id']);
                     $v['block_id'] = $response['id'];
                 }
             }
             $v['param_asso'] = $param;
             $v = $this->cellProcess($v, true);
             $return[] = $v;
         }
     }
     return $return;
 }