| 1 |
<?php |
<?php |
| 2 |
// $Id: views_handler_filter_is_online.inc,v 1.1.2.3 2009/02/13 03:18:36 liammcdermott Exp $ |
// $Id: views_handler_filter_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 sort handler. Useful for newbies who don't know how to do this |
* Is user online sort handler. |
|
* using filters. |
|
| 11 |
*/ |
*/ |
| 12 |
class views_handler_filter_is_online extends views_handler_filter_boolean_operator { |
class views_handler_filter_is_online extends views_handler_filter_boolean_operator { |
| 13 |
function query() { |
function query() { |
| 14 |
|
$this->ensure_my_table(); |
| 15 |
|
$join = new views_join; |
| 16 |
|
$join->construct('sessions', $this->table_alias, 'uid', 'uid', array()); |
| 17 |
|
$session = $this->query->ensure_table('sessions', NULL, $join); |
| 18 |
|
// We have to make sure this field is in the query, and Views knows to |
| 19 |
|
// create GROUP BY's. |
| 20 |
|
$sql = "IF((". time() ." - MAX($session.timestamp)) < ". variable_get('user_block_seconds_online', 900) .", 1, 0)"; |
| 21 |
|
$is_online = $this->query->add_field(NULL, $sql, $this->table_alias .'_'. $this->field, array('aggregate' => TRUE)); |
| 22 |
|
|
| 23 |
|
$this->query->distinct = TRUE; |
| 24 |
if ($this->value == 1) { |
if ($this->value == 1) { |
| 25 |
// Is online. |
// Is online. |
| 26 |
$sql = "(". time() ." - users.access) < 900"; |
$sql = "$is_online = 1"; |
| 27 |
} |
} |
| 28 |
else { |
else { |
| 29 |
// Is offline |
// Is offline |
| 30 |
$sql = "(". time() ." - users.access) > 900"; |
$sql = "$is_online = 0"; |
| 31 |
} |
} |
| 32 |
$this->ensure_my_table(); |
$this->query->add_having($this->options['group'], $sql); |
|
$this->query->add_where($this->options['group'], $sql); |
|
|
$this->field_alias = $this->table_alias .'_'. $this->field; |
|
| 33 |
} |
} |
| 34 |
|
|
| 35 |
/** |
/** |