From 210ebdbc265e1fee6529f4402a28d9f990f05e4d Mon Sep 17 00:00:00 2001 From: zero Date: Mon, 23 Apr 2007 06:29:08 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/trunk@1280 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/db/DB.class.php | 6 +- modules/counter/counter.model.php | 82 ++++++++++++++++++-- modules/counter/counter.view.php | 9 ++- modules/counter/lang/ko.lang.php | 10 ++- modules/counter/queries/getCounterLog.xml | 4 +- modules/counter/queries/getStartLogDate.xml | 11 +++ modules/counter/tpl/images/blank.gif | Bin 0 -> 43 bytes modules/counter/tpl/index.html | 49 ++++++++++++ 8 files changed, 151 insertions(+), 20 deletions(-) create mode 100644 modules/counter/queries/getStartLogDate.xml create mode 100644 modules/counter/tpl/images/blank.gif diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index 7efaf6631..9c6c527b5 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -284,17 +284,17 @@ $value = preg_replace('/(^\'|\'$){1}/','',$value); switch($operation) { - case 'like_tail' : + case 'like_prefix' : $value = $value.'%'; break; - case 'like_prefix' : + case 'like_tail' : $value = '%'.$value; break; case 'like' : $value = '%'.$value.'%'; break; case 'in' : - return "'".$value."'"; + return "'".$value."'"; break; } diff --git a/modules/counter/counter.model.php b/modules/counter/counter.model.php index 29bce40da..419a684f0 100644 --- a/modules/counter/counter.model.php +++ b/modules/counter/counter.model.php @@ -18,6 +18,7 @@ **/ function isLogged() { $args->regdate = date("Ymd"); + $args->ipaddress = $_SERVER['REMOTE_ADDR']; $output = executeQuery('counter.getCounterLog', $args); return $output->data->count?true:false; } @@ -34,22 +35,22 @@ /** * @brief 특정 일의 접속 통계를 가져옴 **/ - function getStatus($regdate) { + function getStatus($selected_date) { // 여러개의 날자 로그를 가져올 경우 - if(is_array($regdate)) { - $date_count = count($regdate); - $args->regdate = implode(',',$regdate); + if(is_array($selected_date)) { + $date_count = count($selected_date); + $args->regdate = implode(',',$selected_date); // 단일 날자의 로그를 가져올 경우 } else { - if(strlen($regdate)==8) $regdate = $regdate; - $args->regdate = $regdate; + if(strlen($selected_date)==8) $selected_date = $selected_date; + $args->regdate = $selected_date; } $output = executeQuery('counter.getCounterStatus', $args); $status = $output->data; - if(!is_array($regdate)) return $status; + if(!is_array($selected_date)) return $status; if(!is_array($status)) $status = array($status); unset($output); @@ -60,5 +61,72 @@ return $output; } + /** + * @brief 지정된 일자의 시간대별 로그 가져오기 + **/ + function getHourlyStatus($type='hour', $selected_date) { + $max = 0; + $sum = 0; + switch($type) { + case 'year' : + // 카운터 시작일 구함 + $output = executeQuery('counter.getStartLogDate'); + $start_year = substr($output->data->regdate,0,4); + if(!$start_year) $start_year = date("Y"); + for($i=$start_year;$i<=date("Y");$i++) { + unset($args); + $args->regdate = sprintf('%04d', $i); + $output = executeQuery('counter.getCounterLog', $args); + $count = (int)$output->data->count; + $status->list[$i] = $count; + if($count>$max) $max = $count; + $sum += $count; + } + break; + break; + case 'month' : + $year = substr($selected_date, 0, 4); + for($i=1;$i<=12;$i++) { + unset($args); + $args->regdate = sprintf('%04d%02d', $year, $i); + $output = executeQuery('counter.getCounterLog', $args); + $count = (int)$output->data->count; + $status->list[$i] = $count; + if($count>$max) $max = $count; + $sum += $count; + } + break; + case 'day' : + $year = substr($selected_date, 0, 4); + $month = substr($selected_date, 4, 2); + $end_day = date('t', mktime(0,0,0,$month,1,$year)); + for($i=1;$i<=$end_day;$i++) { + unset($args); + $args->regdate = sprintf('%04d%02d%02d', $year, $month, $i); + $output = executeQuery('counter.getCounterLog', $args); + $count = (int)$output->data->count; + $status->list[$i] = $count; + if($count>$max) $max = $count; + $sum += $count; + } + break; + default : + for($i=0;$i<24;$i++) { + unset($args); + $args->regdate = sprintf('%08d%02d', $selected_date, $i); + $output = executeQuery('counter.getCounterLog', $args); + $count = (int)$output->data->count; + $status->list[$i] = $count; + if($count>$max) $max = $count; + $sum += $count; + } + break; + } + + $status->max = $max; + $status->sum = $sum; + return $status; + } + } ?> diff --git a/modules/counter/counter.view.php b/modules/counter/counter.view.php index 2c0981ce6..b16deeaf9 100644 --- a/modules/counter/counter.view.php +++ b/modules/counter/counter.view.php @@ -27,15 +27,16 @@ // counter model 객체 생성 $oCounterModel = &getModel('counter'); - // 전체 카운터 현황 가져오기 + // 전체 카운터 및 지정된 일자의 현황 가져오기 $status = $oCounterModel->getStatus(array(0,$selected_date)); Context::set('total_counter', $status[0]); Context::set('selected_day_counter', $status[$selected_date]); - - // 정해진 일자 현황 가져오기 - // 시간, 일, 월, 년도별로 데이터 가져오기 + $type = Context::get('type'); + if(!$type) $type = 'hour'; + $detail_status = $oCounterModel->getHourlyStatus($type, $selected_date); + Context::set('detail_status', $detail_status); // 표시 $this->setTemplateFile('index'); diff --git a/modules/counter/lang/ko.lang.php b/modules/counter/lang/ko.lang.php index 1b3cceb1e..ffd407077 100644 --- a/modules/counter/lang/ko.lang.php +++ b/modules/counter/lang/ko.lang.php @@ -6,6 +6,12 @@ **/ $lang->cmd_select_date = '날자 선택'; + $lang->cmd_select_counter_type = array( + 'hour' => '시간대별', + 'day' => '일별', + 'month' => '월별', + 'year' => '년도별', + ); $lang->total_counter = '전체현황'; $lang->selected_day_counter = '선택일 현황'; @@ -13,8 +19,4 @@ $lang->unique_visitor = '방문자'; $lang->pageview = '페이지뷰'; - $lang->unit_time = '시간별'; - $lang->unit_day = '시간별'; - $lang->unit_month = '시간별'; - $lang->unit_year = '시간별'; ?> diff --git a/modules/counter/queries/getCounterLog.xml b/modules/counter/queries/getCounterLog.xml index 038c8a5a6..c71d3907a 100644 --- a/modules/counter/queries/getCounterLog.xml +++ b/modules/counter/queries/getCounterLog.xml @@ -6,7 +6,7 @@ - - + + diff --git a/modules/counter/queries/getStartLogDate.xml b/modules/counter/queries/getStartLogDate.xml new file mode 100644 index 000000000..675d2aac8 --- /dev/null +++ b/modules/counter/queries/getStartLogDate.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/modules/counter/tpl/images/blank.gif b/modules/counter/tpl/images/blank.gif new file mode 100644 index 0000000000000000000000000000000000000000..35d42e808f0a8017b8d52a06be2f8fec0b466a66 GIT binary patch literal 43 scmZ?wbhEHbWMp7uXkcLY|NlP&1B2pE7Dgb&paUX6G7L;iE{qJ;0LZEa`2YX_ literal 0 HcmV?d00001 diff --git a/modules/counter/tpl/index.html b/modules/counter/tpl/index.html index 990438020..c68e49c5f 100644 --- a/modules/counter/tpl/index.html +++ b/modules/counter/tpl/index.html @@ -26,3 +26,52 @@
  • {$lang->pageview} : {number_format($selected_day_counter->pageview)}
  • + + +
    +

    + {$lang->unique_visitor} + + {$val} + +

    +
    + + +
    +
    + + + + + {@$percent = sprintf("%0.2f", $val / $detail_status->sum * 100 )} + {@$img_width = sprintf("%0.0f", $val / $detail_status->max * 100 )} + + {@$percent = 0} + {@$img_width = 1} + + + + + + +
    + + + {$key} {$lang->unit_year} + + {$key} {$lang->unit_month} + + {$key} {$lang->unit_day} + + {$key} {$lang->unit_hour} + + +
    + {$percent}% +
    +
    + {number_format($val)} ({$percent}%) +
    +
    +