views_handler_sort_is_online.inc 870 B

123456789101112131415161718192021222324
  1. <?php
  2. /**
  3. * @file
  4. * User Stats is user online sort handler.
  5. */
  6. /**
  7. * Is user online sort handler.
  8. */
  9. class views_handler_sort_is_online extends views_handler_sort {
  10. function query() {
  11. $this->ensure_my_table();
  12. // Currently Views has no support for/information on the {sessions} table.
  13. $join = new views_join;
  14. $join->construct('sessions', $this->table_alias, 'uid', 'uid', array());
  15. $session = $this->query->ensure_table('sessions', NULL, $join);
  16. // We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL
  17. // would return 'f' and 't'.
  18. $sql_if_part = "IF((" . REQUEST_TIME . " - $session.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
  19. $this->query->add_orderby(NULL, $sql_if_part, $this->options['order'], $this->table_alias . '_' . $this->field, array('function' => 'max'));
  20. }
  21. }