Elgg\Database\UsersTable::findActive PHP Method

findActive() public method

Return users (or the number of them) who have been active within a recent period.
public findActive ( array $options = [] ) : ElggUser[] | integer
$options array Array of options with keys: seconds (int) => Length of period (default 600 = 10min) limit (int) => Limit (default 10) offset (int) => Offset (default 0) count (bool) => Return a count instead of users? (default false)
return ElggUser[] | integer
    public function findActive(array $options = [])
    {
        $options = array_merge(array('seconds' => 600, 'limit' => $this->config->get('default_limit')), $options);
        // cast options we're sending to hook
        foreach (array('seconds', 'limit', 'offset') as $key) {
            $options[$key] = (int) $options[$key];
        }
        $options['count'] = (bool) $options['count'];
        // allow plugins to override
        $params = array('seconds' => $options['seconds'], 'limit' => $options['limit'], 'offset' => $options['offset'], 'count' => $options['count'], 'options' => $options);
        $data = _elgg_services()->hooks->trigger('find_active_users', 'system', $params, null);
        // check null because the handler could legitimately return falsey values.
        if ($data !== null) {
            return $data;
        }
        $dbprefix = $this->config->get('dbprefix');
        $time = $this->getCurrentTime()->getTimestamp() - $options['seconds'];
        return elgg_get_entities(array('type' => 'user', 'limit' => $options['limit'], 'offset' => $options['offset'], 'count' => $options['count'], 'joins' => array("join {$dbprefix}users_entity u on e.guid = u.guid"), 'wheres' => array("u.last_action >= {$time}"), 'order_by' => "u.last_action desc"));
    }