function views_handler_filter_is_online::query in User Stats 6
Same name and namespace in other branches
- 7 views/views_handler_filter_is_online.inc \views_handler_filter_is_online::query()
File
- views/
views_handler_filter_is_online.inc, line 12 - User Stats is user online sort handler.
Class
- views_handler_filter_is_online
- Is user online sort handler.
Code
function query() {
$this
->ensure_my_table();
$join = new views_join();
$join
->construct('sessions', $this->table_alias, 'uid', 'uid', array());
$session = $this->query
->ensure_table('sessions', NULL, $join);
// We have to make sure this field is in the query, and Views knows to
// create GROUP BY's.
$sql_if_part = "IF((" . time() . " - MAX({$session}.timestamp)) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
$this->query
->add_field(NULL, $sql_if_part, $this->table_alias . '_' . $this->field, array(
'aggregate' => TRUE,
));
$this->query->distinct = TRUE;
if ($this->value == 1) {
// Is online.
$sql = $sql_if_part . " = 1";
}
else {
// Is offline
$sql = $sql_if_part . " = 0";
}
$this->query
->add_having($this->options['group'], $sql);
}