| 1 |
<?php |
<?php |
| 2 |
// $Id: views_handler_field_is_online.inc,v 1.1.2.3 2009/02/13 03:18:36 liammcdermott Exp $ |
// $Id: views_handler_field_is_online.inc,v 1.1.2.4 2009/04/30 07:54:48 liammcdermott Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
* Is user online handler. Useful for newbies who don't know how to do this |
* Is user online handler. |
|
* using filters. |
|
| 11 |
*/ |
*/ |
| 12 |
class views_handler_field_is_online extends views_handler_field_boolean { |
class views_handler_field_is_online extends views_handler_field_boolean { |
| 13 |
function query() { |
function query() { |
| 14 |
|
$this->ensure_my_table(); |
| 15 |
|
// Currently Views has no support for/information on the {sessions} table. |
| 16 |
|
$join = new views_join; |
| 17 |
|
$join->construct('sessions', $this->table_alias, 'uid', 'uid', array()); |
| 18 |
|
$session = $this->query->ensure_table('sessions', NULL, $join); |
| 19 |
|
|
| 20 |
|
$this->query->distinct = TRUE; |
| 21 |
// We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL |
// We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL |
| 22 |
// would return 'f' and 't'. |
// would return 'f' and 't'. |
| 23 |
$sql = "IF((". time() ." - users.access) < 900, 1, 0)"; |
$sql = "IF((". time() ." - MAX($session.timestamp)) < ". variable_get('user_block_seconds_online', 900) .", 1, 0)"; |
| 24 |
// We liberally steal from views_handler_sort_formula here. |
// We liberally steal from views_handler_sort_formula and |
| 25 |
$this->ensure_my_table(); |
// views_handler_filter_search here. |
| 26 |
$this->field_alias = $this->query->add_field(NULL, $sql, $this->table_alias .'_'. $this->field); |
$this->field_alias = $this->query->add_field(NULL, $sql, $this->table_alias .'_'. $this->field, array('aggregate' => TRUE)); |
| 27 |
} |
} |
| 28 |
|
|
| 29 |
function option_definition() { |
function option_definition() { |