2007-09-16 17:37:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statistics class for gathering and formatting of statistical data for tables and charts in
|
|
|
|
* both public and administrative contexts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Statistics extends Controller {
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
function __construct() {
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function trend_chart($table, $filter = "day", $name, $type, $color) {
|
2007-09-16 22:35:04 +02:00
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="trendchart" style="display: none">
|
2007-09-16 17:38:37 +02:00
|
|
|
<h2>Trends</h2>
|
|
|
|
<div><canvas id="chart" height="400" width="700"></canvas></div>
|
|
|
|
<div id="chart_legend"><legend>Legend</legend></div>
|
|
|
|
</div>
|
2007-09-16 17:37:33 +02:00
|
|
|
<script type="text/javascript">\n
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:38:37 +02:00
|
|
|
var chart = new Plotr.{$type}Chart('chart',options);
|
|
|
|
|
|
|
|
chart.addDataset(chartdata);
|
|
|
|
|
|
|
|
|
|
|
|
chart.render();
|
|
|
|
|
|
|
|
chart.addLegend($('chart_legend'));
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
</script>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
$ds = "var chartdata = { \n";
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
foreach($table as $class) {
|
2007-11-08 04:37:45 +01:00
|
|
|
$record = DataObject::get($class, "", $class.".Created DESC");
|
2007-09-16 17:37:33 +02:00
|
|
|
$total = $record->TotalItems();
|
|
|
|
|
|
|
|
$props = $record->toArray();
|
|
|
|
$props = $props[0]->toMap();
|
2007-11-02 02:10:21 +01:00
|
|
|
$startyear = new SSDatetime($props['Created']);
|
2007-09-16 17:37:33 +02:00
|
|
|
$startyear = $startyear->Format('Y');
|
2007-11-02 02:10:21 +01:00
|
|
|
$startmonth = new SSDatetime($props['Created']);
|
2007-09-16 17:37:33 +02:00
|
|
|
$startmonth = $startmonth->Format('m');
|
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
|
2007-09-16 17:37:33 +02:00
|
|
|
if($filter == "day") {
|
2007-11-02 02:10:21 +01:00
|
|
|
$days = new SSDatetime($props['Created']);
|
2007-09-16 17:37:33 +02:00
|
|
|
$days = $days->Format('t');
|
|
|
|
|
|
|
|
$sum = 0;
|
|
|
|
|
2007-09-16 17:41:31 +02:00
|
|
|
$ds .= "{$class}: [";
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
for($i = 1; $i <= $days; $i++) {
|
|
|
|
|
|
|
|
foreach($record as $v) {
|
|
|
|
$props = $v->toMap();
|
2007-11-02 02:10:21 +01:00
|
|
|
$currdate = new SSDatetime($props['Created']);
|
2007-09-16 17:37:33 +02:00
|
|
|
$curryear = $currdate->Format('Y');
|
|
|
|
$currmonth = $currdate->Format('m');
|
|
|
|
$currday = $currdate->Format('j');
|
|
|
|
if($curryear == $startyear && $currmonth == $startmonth && $currday == $i) {
|
|
|
|
$sum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ds .= "[".($i-1).", {$sum}], ";
|
|
|
|
|
|
|
|
}
|
|
|
|
$ds .= "[]],\n";
|
|
|
|
|
|
|
|
|
|
|
|
} else if($filter == "month") {
|
|
|
|
|
|
|
|
$sum = 0;
|
|
|
|
|
|
|
|
$ds .= "{$class}Set: [";
|
|
|
|
|
|
|
|
for($i = 0; $i <= 11; $i++) {
|
|
|
|
$imonth = date('F', mktime(0,0,0,$i+1,1,1));
|
|
|
|
|
|
|
|
foreach($record as $v) {
|
|
|
|
$props = $v->toMap();
|
2007-11-02 02:10:21 +01:00
|
|
|
$currdate = new SSDatetime($props['Created']);
|
2007-09-16 17:37:33 +02:00
|
|
|
$curryear = $currdate->Format('Y');
|
|
|
|
$currmonth = $currdate->Format('m');
|
|
|
|
$currday = $currdate->Format('j');
|
|
|
|
if($curryear == $startyear && $currmonth == $i) {
|
|
|
|
$sum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ds .= "[{$i}, {$sum}], ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$ds .= "[]],\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$xt = "xTicks: [";
|
|
|
|
if($filter == "month") {
|
|
|
|
for($i = 0; $i <= 11; $i++) {
|
|
|
|
$imonth = date('F', mktime(0,0,0,$i+1,1,1));
|
|
|
|
$xt .= "{v:{$i}, label:'{$imonth}'}, ";
|
|
|
|
}
|
|
|
|
} else if($filter == "day") {
|
|
|
|
for($i = 1; $i <= $days; $i++) {
|
|
|
|
$xt .= "{v:".($i-1).", label:'{$i}'}, ";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$opts = <<<HTML
|
2007-09-16 17:37:33 +02:00
|
|
|
var options = {
|
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
axisLabelFontSize: 10,
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
padding: {left: 30, right: 0, top: 10, bottom: 30},
|
|
|
|
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
|
|
|
|
colorScheme: '{$color}',\n\n
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
$opts .= $xt . "]\n};";
|
|
|
|
|
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
return $top . $ds . "\n};\n\n" . $opts . "\n\n" . $bot;
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function user_record_table() {
|
2007-09-16 17:37:33 +02:00
|
|
|
$records = DataObject::get('Member');
|
2007-09-16 22:35:04 +02:00
|
|
|
$baseURL = Director::baseURL();
|
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="usertable" style="display: none">
|
2007-09-16 17:38:37 +02:00
|
|
|
<h2>Registered Users</h2>
|
2007-09-16 17:43:22 +02:00
|
|
|
<p><a href="$baseURL/admin/statistics/usercsv">Export as CSV</a></p>
|
2007-09-16 17:37:33 +02:00
|
|
|
<table class="sortable-onload-1 rowstyle-alt no-arrow paginate-10 statstable" border="0" cellspacing="1" cellpadding="0">
|
|
|
|
<thead>
|
|
|
|
<tr><th class="sortable-numeric">ID</th><th class="sortable-text">Email</th><th class="sortable-sortDatetime">Joined</th></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
$bod = "";
|
|
|
|
foreach($records as $x) {
|
|
|
|
$r = $x->toMap();
|
|
|
|
$id = $r['ID'];
|
|
|
|
$email = $r['Email'];
|
|
|
|
$date = date("F j, Y G:i:s", strtotime($r['Created']));
|
|
|
|
$bod .= "<tr><td>$id</td><td>$email</td><td>$date</td></tr>";
|
|
|
|
}
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:37:33 +02:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
//$js = "\n\n<script type=\"text/javascript\">\n\tvar usertable = new TableKit('usertable');\nusertable.initialize();\n</script>\n";
|
|
|
|
return $top . $bod . $bot;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function collect() {
|
2007-09-16 17:37:33 +02:00
|
|
|
$hit = new PageView();
|
|
|
|
$hit->record();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function get_recent_views($limit = 15) {
|
2007-09-16 17:37:33 +02:00
|
|
|
$records = DataObject::get('PageView', null, 'Created DESC', null, $limit);
|
2007-09-16 22:35:04 +02:00
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="recentviewtable">
|
2007-09-16 17:38:37 +02:00
|
|
|
<h2>Recent Page Views</h2>
|
2007-09-16 17:43:22 +02:00
|
|
|
<table class="sortable-onload-1 rowstyle-alt no-arrow paginate-10 statstable" border="0" cellspacing="1" cellpadding="0">
|
2007-09-16 17:37:33 +02:00
|
|
|
<thead>
|
|
|
|
<tr><th class="sortable-numeric">ID</th><th class="sortable-sortDatetime">Time</th><th class="sortable-text">Browser</th><th class="sortable-text">OS</th><th>User</th><th class="sortable-text">Page</th></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
$bod = "";
|
|
|
|
foreach($records as $x) {
|
|
|
|
$r = $x->toMap();
|
|
|
|
$id = $r['ID'];
|
|
|
|
$time = $r['Created'];
|
|
|
|
$browser = $r['Browser'] . " " . $r['BrowserVersion'];
|
|
|
|
$os = $r['OS'];
|
|
|
|
$user = $r['UserID'];
|
|
|
|
$page = $r['PageID'];
|
|
|
|
$bod .= "<tr><td>$id</td><td>$time</td><td>$browser</td><td>$os</td><td>$user</td><td>$page</td></tr>";
|
|
|
|
}
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:37:33 +02:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
return $top . $bod . $bot;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function get_views($time = 'all') {
|
2007-09-16 17:37:33 +02:00
|
|
|
switch($time) {
|
|
|
|
case 'all':
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
break;
|
|
|
|
case 'year':
|
|
|
|
$pt = time() - 31556926;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'month':
|
|
|
|
$pt = time() - 2629744;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'week':
|
|
|
|
$pt = time() - 604800;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'day':
|
|
|
|
$pt = time() - 86400;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'hour':
|
|
|
|
$pt = time() - 3600;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'minute':
|
|
|
|
$pt = time() - 60;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
}
|
2007-09-16 22:35:04 +02:00
|
|
|
$baseURL = Director::baseURL();
|
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="viewtable" style="display: none">
|
2007-09-16 17:38:37 +02:00
|
|
|
<h2>Page Views</h2>
|
2007-09-16 17:43:22 +02:00
|
|
|
<p><a href="$baseURL/admin/statistics/viewcsv">Export as CSV</a></p>
|
2007-09-16 17:37:33 +02:00
|
|
|
<table class="sortable-onload-1 rowstyle-alt no-arrow paginate-10 statstable" border="0" cellspacing="1" cellpadding="0">
|
|
|
|
<thead>
|
|
|
|
<tr><th class="sortable-numeric">ID</th><th class="sortable-sortDatetime">Time</th><th class="sortable-text">Browser</th><th class="sortable-text">OS</th><th class="sortable-text">User</th><th class="sortable-text">Page</th></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
$bod = "";
|
|
|
|
foreach($records as $x) {
|
|
|
|
$r = $x->toMap();
|
|
|
|
$id = $r['ID'];
|
|
|
|
$time = $r['Created'];
|
|
|
|
$browser = $r['Browser'] . " " . $r['BrowserVersion'];
|
|
|
|
$os = $r['OS'];
|
|
|
|
$user = $r['UserID'];
|
|
|
|
$page = $r['PageID'];
|
|
|
|
$bod .= "<tr><td>$id</td><td>$time</td><td>$browser</td><td>$os</td><td>$user</td><td>$page</td></tr>";
|
|
|
|
}
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:37:33 +02:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
return $top . $bod . $bot;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function browser_chart($type = "Pie", $color = "blue") {
|
2007-09-16 22:35:04 +02:00
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="browserchart" style="display: none">
|
2007-09-16 17:38:37 +02:00
|
|
|
<h2>Browsers</h2>
|
|
|
|
<div><canvas id="bchart" height="400" width="700"></canvas></div>
|
|
|
|
</div>
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
<script type="text/javascript">\n
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:38:37 +02:00
|
|
|
var bchart = new Plotr.{$type}Chart('bchart', boptions);
|
|
|
|
|
|
|
|
bchart.addDataset(bchartdata);
|
|
|
|
|
|
|
|
|
|
|
|
bchart.render();
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
</script>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
|
|
|
|
$ds = "var bchartdata = { \n'Set': [";
|
|
|
|
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
$browsers = array();
|
|
|
|
foreach($records as $r) {
|
|
|
|
$ra = $r->toMap();
|
|
|
|
$cb = $ra['Browser'] . " " . $ra['BrowserVersion'];
|
2007-09-16 22:35:04 +02:00
|
|
|
if(isset($browsers[$cb]) && $browsers[$cb] >= 1) {
|
2007-09-16 17:37:33 +02:00
|
|
|
$browsers[$cb]++;
|
|
|
|
} else {
|
|
|
|
$browsers[$cb] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$xt = "xTicks: [";
|
|
|
|
$i = 0;
|
|
|
|
foreach($browsers as $bn => $bc) {
|
|
|
|
$ds .= "[{$i}, {$bc}], ";
|
|
|
|
$xt .= "{v:" . $i . ", label:'" . $bn . "'}, ";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$ds .= "]\n";
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$opts = <<<HTML
|
2007-09-16 17:37:33 +02:00
|
|
|
var boptions = {
|
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
axisLabelFontSize: 10,
|
|
|
|
|
2007-09-16 17:37:33 +02:00
|
|
|
|
2007-09-16 17:41:31 +02:00
|
|
|
padding: {left: 30, right: 0, top: 10, bottom: 30},
|
|
|
|
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
|
|
|
|
colorScheme: '{$color}',\n\n
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
$opts .= $xt . "]\n};";
|
|
|
|
|
|
|
|
|
|
|
|
return $top . $ds . "\n};\n\n" . $opts . "\n\n" . $bot;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function os_chart($type = "Pie", $color = "blue") {
|
2007-09-16 22:35:04 +02:00
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="oschart" style="display: none">
|
2007-09-16 17:41:31 +02:00
|
|
|
<h2>Operating Systems</h2>
|
|
|
|
<div><canvas id="ochart" height="400" width="700"></canvas></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="text/javascript">\n
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:41:31 +02:00
|
|
|
var ochart = new Plotr.{$type}Chart('ochart', ooptions);
|
|
|
|
|
|
|
|
ochart.addDataset(ochartdata);
|
|
|
|
|
|
|
|
|
|
|
|
ochart.render();
|
|
|
|
|
|
|
|
</script>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
|
|
|
|
$ds = "var ochartdata = { \n'Set': [";
|
|
|
|
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
$oss = array();
|
|
|
|
foreach($records as $r) {
|
|
|
|
$ra = $r->toMap();
|
|
|
|
$cb = $ra['OS'];
|
2007-09-16 22:35:04 +02:00
|
|
|
if(isset($oss[$cb]) && $oss[$cb] >= 1) {
|
2007-09-16 17:41:31 +02:00
|
|
|
$oss[$cb]++;
|
|
|
|
} else {
|
|
|
|
$oss[$cb] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$xt = "xTicks: [";
|
|
|
|
$i = 0;
|
|
|
|
foreach($oss as $bn => $bc) {
|
|
|
|
$ds .= "[{$i}, {$bc}], ";
|
|
|
|
$xt .= "{v:" . $i . ", label:'" . $bn . "'}, ";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$ds .= "]\n";
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$opts = <<<HTML
|
2007-09-16 17:41:31 +02:00
|
|
|
var ooptions = {
|
|
|
|
|
|
|
|
axisLabelFontSize: 10,
|
|
|
|
|
|
|
|
|
|
|
|
padding: {left: 30, right: 0, top: 10, bottom: 30},
|
|
|
|
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
|
|
|
|
colorScheme: '{$color}',\n\n
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
$opts .= $xt . "]\n};";
|
|
|
|
|
|
|
|
|
|
|
|
return $top . $ds . "\n};\n\n" . $opts . "\n\n" . $bot;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function activity_chart($type = "Pie", $color = "blue") {
|
2007-09-16 22:35:04 +02:00
|
|
|
$top = <<<HTML
|
2007-09-16 17:43:22 +02:00
|
|
|
<div id="uacchart" style="display: none">
|
2007-09-16 17:41:31 +02:00
|
|
|
<h2>User Activity</h2>
|
|
|
|
<div><canvas id="uchart" height="400" width="700"></canvas></div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="text/javascript">\n
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$bot = <<<HTML
|
2007-09-16 17:41:31 +02:00
|
|
|
var uacchart = new Plotr.{$type}Chart('uchart', uacoptions);
|
|
|
|
|
|
|
|
uacchart.addDataset(uacchartdata);
|
|
|
|
|
|
|
|
|
|
|
|
uacchart.render();
|
|
|
|
|
|
|
|
</script>
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:41:31 +02:00
|
|
|
|
|
|
|
$ds = "var uacchartdata = { \n'Set': [";
|
|
|
|
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
$users = array();
|
|
|
|
foreach($records as $r) {
|
|
|
|
$ra = $r->toMap();
|
|
|
|
$cb = $ra['UserID'];
|
|
|
|
if($cb == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-16 22:35:04 +02:00
|
|
|
if(isset($users[$cb]) && $users[$cb] >= 1) {
|
2007-09-16 17:41:31 +02:00
|
|
|
$users[$cb]++;
|
|
|
|
} else {
|
|
|
|
$users[$cb] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$xt = "xTicks: [";
|
|
|
|
$i = 0;
|
|
|
|
foreach($users as $bn => $bc) {
|
|
|
|
$ds .= "[{$i}, {$bc}], ";
|
|
|
|
$xt .= "{v:" . $i . ", label:'" . $bn . "'}, ";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$ds .= "]\n";
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
$opts = <<<HTML
|
2007-09-16 17:41:31 +02:00
|
|
|
var uacoptions = {
|
|
|
|
|
|
|
|
axisLabelFontSize: 10,
|
|
|
|
|
|
|
|
|
2007-09-16 17:37:33 +02:00
|
|
|
padding: {left: 30, right: 0, top: 10, bottom: 30},
|
|
|
|
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
|
|
|
|
colorScheme: '{$color}',\n\n
|
|
|
|
|
2007-09-16 22:35:04 +02:00
|
|
|
HTML;
|
2007-09-16 17:37:33 +02:00
|
|
|
$opts .= $xt . "]\n};";
|
|
|
|
|
|
|
|
|
2007-09-16 17:38:37 +02:00
|
|
|
return $top . $ds . "\n};\n\n" . $opts . "\n\n" . $bot;
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function get_view_csv($time = 'all') {
|
2007-09-16 17:43:22 +02:00
|
|
|
$data = "ID, ClassName, Created, LastEdited, Browser, FromExternal, Referrer, SearchEngine, Keywords, OS, PageID, UserID, BrowserVersion, IP\n";
|
|
|
|
|
|
|
|
switch($time) {
|
|
|
|
case 'all':
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
break;
|
|
|
|
case 'year':
|
|
|
|
$pt = time() - 31556926;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'month':
|
|
|
|
$pt = time() - 2629744;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'week':
|
|
|
|
$pt = time() - 604800;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'day':
|
|
|
|
$pt = time() - 86400;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'hour':
|
|
|
|
$pt = time() - 3600;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
case 'minute':
|
|
|
|
$pt = time() - 60;
|
|
|
|
$pt = date("Y-m-d H:i:s", $pt);
|
|
|
|
$ct = time() + 10;
|
|
|
|
$ct = date("Y-m-d H:i:s", $ct);
|
|
|
|
$records = DataObject::get('PageView', "Created >= '$pt' AND Created <= '$ct'");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$records = DataObject::get('PageView');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($records as $x) {
|
|
|
|
$r = $x->toMap();
|
|
|
|
$data .= implode(', ', $r) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2007-10-25 02:37:09 +02:00
|
|
|
static function get_user_csv() {
|
2007-09-16 17:43:22 +02:00
|
|
|
$data = "ID, ClassName, Created, LastEdited, FirstName, Surname, Email, Password, NumVisit, LastVisited, Bounced, AutoLoginHash, AutoLoginExpired, BlacklistedEmail, RememberLoginToken, IdentityURL, PasswordEncryption, Salt\n";
|
|
|
|
|
|
|
|
$records = DataObject::get('Member');
|
|
|
|
|
|
|
|
foreach($records as $x) {
|
|
|
|
$r = $x->toMap();
|
|
|
|
$data .= implode(', ', $r) . "\n";
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2007-09-16 17:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|