You are here

function views_handler_field_is_online::query in User Stats 7

Same name and namespace in other branches
  1. 6 views/views_handler_field_is_online.inc \views_handler_field_is_online::query()

Called to add the field to a query.

Overrides views_handler_field::query

File

views/views_handler_field_is_online.inc, line 12
User Stats is user online handler.

Class

views_handler_field_is_online
Is user online handler.

Code

function query() {
  $this
    ->ensure_my_table();

  // Currently Views has no support for/information on the {sessions} table.
  $join = new views_join();
  $join
    ->construct('sessions', $this->table_alias, 'uid', 'uid', array());
  $session = $this->query
    ->ensure_table('sessions', NULL, $join);

  // We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL
  // would return 'f' and 't'.
  $sql_if_part = "IF((" . REQUEST_TIME . " - {$session}.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";

  // We liberally steal from views_handler_sort_formula and
  // views_handler_filter_search here.
  $this->field_alias = $this->query
    ->add_field(NULL, $sql_if_part, $this->table_alias . '_' . $this->field, array(
    'function' => 'max',
  ));
}