1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* User Stats is user online handler.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Is user online handler.
|
10 |
|
|
*/
|
11 |
|
|
class views_handler_field_is_online extends views_handler_field_boolean {
|
12 |
|
|
function query() {
|
13 |
|
|
$this->ensure_my_table();
|
14 |
|
|
// Currently Views has no support for/information on the {sessions} 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 |
|
|
|
19 |
|
|
// We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL
|
20 |
|
|
// would return 'f' and 't'.
|
21 |
|
|
$sql_if_part = "IF((" . REQUEST_TIME . " - $session.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
|
22 |
|
|
|
23 |
|
|
// We liberally steal from views_handler_sort_formula and
|
24 |
|
|
// views_handler_filter_search here.
|
25 |
|
|
$this->field_alias = $this->query->add_field(NULL, $sql_if_part, $this->table_alias . '_' . $this->field, array('function' => 'max'));
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
function option_definition() {
|
29 |
|
|
$options = parent::option_definition();
|
30 |
|
|
|
31 |
|
|
$options['type'] = array('default' => 'online-offline');
|
32 |
|
|
|
33 |
|
|
return $options;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Add the online-offline type to options form.
|
38 |
|
|
*/
|
39 |
|
|
function options_form(&$form, &$form_state) {
|
40 |
|
|
parent::options_form($form, $form_state);
|
41 |
|
|
$form['type']['#options']['online-offline'] = t('Online/Offline');
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
function render($values) {
|
45 |
|
|
$value = $values->{$this->field_alias};
|
46 |
|
|
if (!empty($this->options['not'])) {
|
47 |
|
|
$value = !$value;
|
48 |
|
|
}
|
49 |
|
|
if ($this->options['type'] == 'online-offline') {
|
50 |
|
|
return $value ? '<span class="user-stat-online">' . t('Online') . '</span>' : '<span class="user-stat-offline">' . t('Offline') . '</span>';
|
51 |
|
|
}
|
52 |
|
|
else {
|
53 |
|
|
return parent::render($values);
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
} |