_getSourceChannelData()

function _getSourceChannelData()
{
    GLOBAL $_sourceChannelData;

    GLOBAL $_statSourceData_Level_2;
    GLOBAL $_statSourceData_Level_3;

    GLOBAL $_tag_Level_1;
    GLOBAL $_tag_Level_2;

    $mysql = ToolUtil::getDBObj('icson');
    if (false === $mysql) {
        Logger::err("Get mysql db [icson] failed: " . ToolUtil::$errMsg . "\n");

        return false;
    }

    $table_name = "t_tag_source";
    $sqlstmt_level_0 = "SELECT s_name, tag_id FROM {$table_name} WHERE s_level = 0";
    $sqlstmt_level_1 = "SELECT s_name, tag_fid, level_1_id FROM {$table_name} WHERE s_level = 1";
    $sqlstmt_level_2 = "SELECT s_name, level_1_id, level_2_id FROM {$table_name} WHERE s_level = 2";
    $sqlstmt_level_3 = "SELECT s_name, level_1_id, level_2_id, level_3_id FROM {$table_name} WHERE s_level = 3";

    $level_0_data = array();
    $level_1_data = array();
    $level_2_data = array();
    $level_3_data = array();

    // get level 0
    $rows = $mysql->getRows($sqlstmt_level_0);
    if (false === $rows) {
        Logger::err("Query mysql db [icson].[{$table_name}] failed: " . $mysql->errMsg . "\n");

        return false;
    }
    else {
        foreach ($rows as &$row) {
            $level_0_data[$row['tag_id']] = $row;

            $_statSourceData_Level_2[intval($row['tag_id'])] = array(
                    'level_2_id' => intval($row['tag_id']),
                    'level_2_name' => $row['s_name'],

                    'level_1_id' => CHANNEL_LEVEL_1_ID,
                    'level_1_name' => CHANNEL_LEVEL_1_NAME,
                );
        }
    }

    // get level 1
    $rows = $mysql->getRows($sqlstmt_level_1);
    if (false === $rows) {
        Logger::err("Query mysql db [icson].[{$table_name}] failed: " . $mysql->errMsg . "\n");

        return false;
    }
    else {
        foreach ($rows as &$row) {
            $level_1_data[$row['level_1_id']] = $row;
        }
    }

    // get level 2
    $rows = $mysql->getRows($sqlstmt_level_2);
    if (false === $rows) {
        Logger::err("Query mysql db [icson].[{$table_name}] failed: " . $mysql->errMsg . "\n");

        return false;
    }
    else {
        foreach ($rows as &$row) {
            $level_2_data[$row['level_1_id']][$row['level_2_id']] = $row;
        }
    }

    // get level 3
    $rows = $mysql->getRows($sqlstmt_level_3);
    if (false === $rows) {
        Logger::err("Query mysql db [icson].[{$table_name}] failed: " . $mysql->errMsg . "\n");

        return false;
    }
    else {
        foreach ($rows as &$row) {
            $tag_source_id = _getLevel3TagID($row['level_1_id'], $row['level_2_id'], $row['level_3_id']);
            $level_3_data[$tag_source_id] = $row;
        }
    }

    // 获取TAG映射数据
    foreach ($level_3_data as $tag_source_id => &$tag_data) {
        $tag_level_1_id = $tag_data['level_1_id'];
        $tag_level_2_id = $tag_data['level_2_id'];
        $tag_level_3_id = $tag_data['level_3_id'];

        $tag_level_1_name = $level_1_data[$tag_level_1_id]['s_name'];
        $tag_level_2_name = $level_2_data[$tag_level_1_id][$tag_level_2_id]['s_name'];
        $tag_level_3_name = $tag_data['s_name'];

        $level_3_id = $tag_level_1_id;
        $level_2_id = $level_1_data[$tag_level_1_id]['tag_fid'];
        $level_1_id = CHANNEL_LEVEL_1_ID;

        $level_3_name = $tag_level_1_name;
        $level_2_name = $level_0_data[$level_2_id]['s_name'];
        $level_1_name = CHANNEL_LEVEL_1_NAME;

        $_sourceChannelData[$tag_source_id] = array(
                // TAG 系统level
                'tag_level_1_id' => $tag_level_1_id,
                'tag_level_2_id' => $tag_level_2_id,
                'tag_level_3_id' => $tag_level_3_id,

                'tag_level_1_name' => $tag_level_1_name,
                'tag_level_2_name' => $tag_level_2_name,
                'tag_level_3_name' => $tag_level_3_name,

                // 统计结果level
                'level_1_id' => $level_1_id,
                'level_2_id' => $level_2_id,
                'level_3_id' => $level_3_id,

                'level_1_name' => $level_1_name,
                'level_2_name' => $level_2_name,
                'level_3_name' => $level_3_name,
            );

        // tag level 1
        $_tag_Level_1[$tag_level_1_id] = array(
                'tag_level_1_id' => $tag_level_1_id,

                'tag_level_1_name' => $tag_level_1_name,
            );

        // tag level 2
        $_tag_Level_2[$tag_level_1_id][$tag_level_2_id] = array(
                'tag_level_1_id' => $tag_level_1_id,
                'tag_level_2_id' => $tag_level_2_id,

                'tag_level_1_name' => $tag_level_1_name,
                'tag_level_2_name' => $tag_level_2_name,
            );

        // stat level 3 data
        $_statSourceData_Level_3[$level_3_id] = array(
                'level_1_id' => $level_1_id,
                'level_2_id' => $level_2_id,
                'level_3_id' => $level_3_id,

                'level_1_name' => $level_1_name,
                'level_2_name' => $level_2_name,
                'level_3_name' => $level_3_name,
            );
    }

    // 直接访问
    $_sourceChannelData[SOURCE_ID_DIRECT] = array(
            // 统计结果level
            'level_1_id' => DIRECT_LEVEL_1_ID,
            'level_1_name' => DIRECT_LEVEL_1_NAME,
        );

    // 其它来源
    $_sourceChannelData[SOURCE_ID_OTHER] = array(
            // 统计结果level
            'level_2_id' => STAT_OTHER_LEVEL_2_ID,
            'level_2_name' => '其它',

            'level_1_id' => OTHER_LEVEL_1_ID,
            'level_1_name' => OTHER_LEVEL_1_NAME,
        );

    return true;
}

 

posted on 2014-09-03 16:59  阮佳佳  阅读(211)  评论(0编辑  收藏  举报

导航