Move mod/nodeinfo to src/Module/Nodeinfo

This commit is contained in:
Philipp Holzer 2019-04-22 14:00:17 +02:00
parent 9d3a131204
commit 6056081d5a
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
6 changed files with 295 additions and 223 deletions

View file

@ -967,4 +967,51 @@ class User
return $identities;
}
/**
* Returns statistical information about the current users of this node
*
* @return array
*
* @throws Exception
*/
public static function getStatistics()
{
$statistics = [
'total_users' => 0,
'active_users_halfyear' => 0,
'active_users_monthly' => 0,
];
$userStmt = DBA::p("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
FROM `user`
INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
AND NOT `user`.`account_expired`");
if (!DBA::isResult($userStmt)) {
return $statistics;
}
$halfyear = time() - (180 * 24 * 60 * 60);
$month = time() - (30 * 24 * 60 * 60);
while ($user = DBA::fetch($userStmt)) {
$statistics['total_users']++;
if ((strtotime($user['login_date']) > $halfyear) ||
(strtotime($user['last-item']) > $halfyear)) {
$statistics['active_users_halfyear']++;
}
if ((strtotime($user['login_date']) > $month) ||
(strtotime($user['last-item']) > $month)) {
$statistics['active_users_monthly']++;
}
}
return $statistics;
}
}