Visitor count fix

This commit is contained in:
Roman Hergenreder 2020-07-18 12:51:36 +02:00
parent 5254f3488b
commit 852d94e736
6 changed files with 32 additions and 4 deletions

@ -2,6 +2,8 @@
namespace Api;
use DateTime;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondBool;
class Stats extends Request {
@ -47,6 +49,22 @@ class Stats extends Request {
return $this->success;
}
private function getVisitorCount() {
$sql = $this->user->getSQL();
$date = new DateTime();
$monthStart = $date->format("Ym00");
$monthEnd = $date->modify("+1 month")->format("Ym00");
$res = $sql->select($sql->count($sql->distinct("cookie")))
->from("Visitor")
->where(new Compare("day", $monthStart, ">="))
->where(new Compare("day", $monthEnd, "<"))
->execute();
$this->success = ($res !== false);
$this->lastError = $sql->getLastError();
return ($this->success ? $res[0]["count"] : $this->success);
}
public function execute($values = array()) {
if(!parent::execute($values)) {
return false;
@ -62,6 +80,11 @@ class Stats extends Request {
}
$visitorStatistics = $req->getResult()["visitors"];
$visitorCount = $this->getVisitorCount();
if (!$this->success) {
return false;
}
$loadAvg = "Unknown";
if (function_exists("sys_getloadavg")) {
$loadAvg = sys_getloadavg();
@ -74,6 +97,7 @@ class Stats extends Request {
$this->result["userCount"] = $userCount;
$this->result["pageCount"] = $pageCount;
$this->result["visitors"] = $visitorStatistics;
$this->result["visitorsTotal"] = $visitorCount;
$this->result["server"] = array(
"version" => WEBBASE_VERSION,
"server" => $_SERVER["SERVER_SOFTWARE"] ?? "Unknown",

@ -303,6 +303,8 @@ abstract class SQL {
public function count($col = NULL) {
if (is_null($col)) {
return new Keyword("COUNT(*) AS count");
} else if($col instanceof Keyword) {
return new Keyword("COUNT(" . $col->getValue() . ") AS count");
} else {
$countCol = strtolower(str_replace(".","_", $col)) . "_count";
$col = $this->columnName($col);

@ -1,6 +1,6 @@
<?php
define("WEBBASE_VERSION", "1.0.2");
define("WEBBASE_VERSION", "1.0.3");
function getProtocol() {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";

2
js/admin.min.js vendored

File diff suppressed because one or more lines are too long

@ -5,7 +5,7 @@ export default function Footer() {
return (
<footer className={"main-footer"}>
Theme: <strong>Copyright © 2014-2019 <a href={"http://adminlte.io"}>AdminLTE.io</a>. <b>Version</b> 3.0.3</strong>&nbsp;
CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.2
CMS: <strong><a href={"https://git.romanh.de/Projekte/web-base"}>WebBase</a></strong>. <b>Version</b> 1.0.3
</footer>
)
}

@ -22,6 +22,7 @@ export default class Overview extends React.Component {
statusVisible : true,
userCount: 0,
notificationCount: 0,
visitorsTotal: 0,
visitors: { },
server: { load_avg: ["Unknown"] },
errors: []
@ -48,6 +49,7 @@ export default class Overview extends React.Component {
userCount: res.userCount,
pageCount: res.pageCount,
visitors: res.visitors,
visitorsTotal: res.visitorsTotal,
server: res.server
});
}
@ -157,7 +159,7 @@ export default class Overview extends React.Component {
<div className={"col-lg-3 col-6"}>
<div className={"small-box bg-danger"}>
<div className={"inner"}>
<h3>{visitorCount}</h3>
<h3>{this.state.visitorsTotal}</h3>
<p>Unique Visitors</p>
</div>
<div className="icon">