/**
* @param integer $uid
+ * @param array $fields
* @return array|boolean User record if it exists, false otherwise
* @throws Exception
*/
- public static function getById($uid)
+ public static function getById($uid, array $fields = [])
{
- return DBA::selectFirst('user', [], ['uid' => $uid]);
+ return DBA::selectFirst('user', $fields, ['uid' => $uid]);
}
/**
- * @param integer $uid
+ * @param string $nickname
+ * @param array $fields
* @return array|boolean User record if it exists, false otherwise
* @throws Exception
*/
- public static function getPublicContactById($uid)
+ public static function getByNickname($nickname, array $fields = [])
{
- $self = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
- if (!DBA::isResult($self)) {
- return false;
- }
- return Contact::getIdForURL($self['url'], 0, true);
+ return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
}
/**
`user`.`spubkey`,
`user`.`page-flags`,
`user`.`account-type`,
- `user`.`prvnets`
+ `user`.`prvnets`,
+ `user`.`account_removed`
FROM `contact`
INNER JOIN `user`
ON `user`.`uid` = `contact`.`uid`
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;
+ }
}