Commit 5dad7c2e authored by sampaioprimo's avatar sampaioprimo

moving stats functions from tikilib to statslib

parent e6c6daa2
......@@ -21,7 +21,8 @@ if ( $prefs['feature_referer_stats'] == 'y' ) {
//if ( $prefs['feature_stats'] == 'y' ) {
if ( $prefs['count_admin_pvs'] == 'y' || $user != 'admin' ) {
if ( ! isset($section) or ( $section != 'chat' and $section != 'livesupport' ) ) {
$tikilib->add_pageview();
$statslib = TikiLib::lib('stats');
$statslib->add_pageview();
}
}
//}
......@@ -376,6 +376,51 @@ class StatsLib extends TikiLib
return $count;
}
function add_pageview() {
$dayzero = $this->make_time(0, 0, 0, $this->date_format("%m",$this->now), $this->date_format("%d",$this->now), $this->date_format("%Y",$this->now));
$conditions = array(
'day' => (int) $dayzero,
);
$pageviews = $this->table('tiki_pageviews');
$cant = $pageviews->fetchCount($conditions);
if ($cant) {
$pageviews->update(array(
'pageviews' => $pageviews->increment(1),
), $conditions);
} else {
$pageviews->insert(array(
'day' => (int) $dayzero,
'pageviews' => 1,
));
}
}
function get_pv_chart_data($days) {
$now = $this->make_time(0, 0, 0, $this->date_format("%m"), $this->date_format("%d"), $this->date_format("%Y"));
$dfrom = 0;
if ($days != 0) $dfrom = $now - ($days * 24 * 60 * 60);
$query = "select `day`, `pageviews` from `tiki_pageviews` where `day`<=? and `day`>=?";
$result = $this->fetchAll($query,array((int)$now,(int)$dfrom));
$ret = array();
$n = ceil(count($result) / 10);
$i = 0;
$xdata=array();
$ydata=array();
foreach ( $result as $res ) {
if ($i % $n == 0) {
$xdata[] = $this->date_format("%e %b", $res["day"]);
} else {
$xdata = '';
}
$ydata[] = $res["pageviews"];
}
$ret['xdata']=$xdata;
$ret['ydata']=$ydata;
return $ret;
}
}
global $dbTiki;
$statslib = new StatsLib;
......@@ -203,6 +203,9 @@ class TikiLib extends TikiDb_Bridge
case 'prefs':
global $prefslib; include_once('lib/prefslib.php');
return $libraries[$name] = $prefslib;
case 'stats':
global $statslib; require_once('lib/stats/statslib.php');
return $libraries[$name] = $statslib;
}
}
......@@ -1375,52 +1378,6 @@ class TikiLib extends TikiDb_Bridge
}
}
function get_pv_chart_data($days) {
$now = $this->make_time(0, 0, 0, $this->date_format("%m"), $this->date_format("%d"), $this->date_format("%Y"));
$dfrom = 0;
if ($days != 0) $dfrom = $now - ($days * 24 * 60 * 60);
$query = "select `day`, `pageviews` from `tiki_pageviews` where `day`<=? and `day`>=?";
$result = $this->fetchAll($query,array((int)$now,(int)$dfrom));
$ret = array();
$n = ceil(count($result) / 10);
$i = 0;
$xdata=array();
$ydata=array();
foreach ( $result as $res ) {
if ($i % $n == 0) {
$xdata[] = $this->date_format("%e %b", $res["day"]);
} else {
$xdata = '';
}
$ydata[] = $res["pageviews"];
}
$ret['xdata']=$xdata;
$ret['ydata']=$ydata;
return $ret;
}
function add_pageview() {
$dayzero = $this->make_time(0, 0, 0, $this->date_format("%m",$this->now), $this->date_format("%d",$this->now), $this->date_format("%Y",$this->now));
$conditions = array(
'day' => (int) $dayzero,
);
$pageviews = $this->table('tiki_pageviews');
$cant = $pageviews->fetchCount($conditions);
if ($cant) {
$pageviews->update(array(
'pageviews' => $pageviews->increment(1),
), $conditions);
} else {
$pageviews->insert(array(
'day' => (int) $dayzero,
'pageviews' => 1,
));
}
}
function get_usage_chart_data() {
$this->compute_quiz_stats();
$data['xdata'][] = tra('wiki');
......
......@@ -17,7 +17,10 @@ $graph = new MultilineGraphic;
$graph->setTitle(tra('Pageviews'));
//Set some data
if (!isset($_REQUEST["days"])) $_REQUEST["days"] = 7;
$data = $tikilib->get_pv_chart_data($_REQUEST["days"]);
$statslib = TikiLib::lib('stats');
$data = $statslib->get_pv_chart_data($_REQUEST["days"]);
foreach($data['xdata'] as $key => $date) {
$data['xdata'][$key] = strtotime($date) / 24 / 3600;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment