1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_history_user_timestamp.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to display the marker for new content.
|
10
|
*
|
11
|
* The handler is named history_user, because of compability reasons, the table
|
12
|
* is history.
|
13
|
*
|
14
|
* @ingroup views_field_handlers
|
15
|
*/
|
16
|
class views_handler_field_history_user_timestamp extends views_handler_field_node {
|
17
|
function init(&$view, &$options) {
|
18
|
parent::init($view, $options);
|
19
|
global $user;
|
20
|
if ($user->uid) {
|
21
|
$this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
|
22
|
$this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
|
23
|
if (module_exists('comment') && !empty($this->options['comments'])) {
|
24
|
$this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
|
29
|
function option_definition() {
|
30
|
$options = parent::option_definition();
|
31
|
|
32
|
$options['comments'] = array('default' => FALSE, 'bool' => TRUE);
|
33
|
|
34
|
return $options;
|
35
|
}
|
36
|
|
37
|
function options_form(&$form, &$form_state) {
|
38
|
parent::options_form($form, $form_state);
|
39
|
if (module_exists('comment')) {
|
40
|
$form['comments'] = array(
|
41
|
'#type' => 'checkbox',
|
42
|
'#title' => t('Check for new comments as well'),
|
43
|
'#default_value' => !empty($this->options['comments']),
|
44
|
'#fieldset' => 'more',
|
45
|
);
|
46
|
}
|
47
|
}
|
48
|
|
49
|
function query() {
|
50
|
// Only add ourselves to the query if logged in.
|
51
|
global $user;
|
52
|
if (!$user->uid) {
|
53
|
return;
|
54
|
}
|
55
|
parent::query();
|
56
|
}
|
57
|
|
58
|
function render($values) {
|
59
|
// Let's default to 'read' state.
|
60
|
// This code shadows node_mark, but it reads from the db directly and
|
61
|
// we already have that info.
|
62
|
$mark = MARK_READ;
|
63
|
global $user;
|
64
|
if ($user->uid) {
|
65
|
$last_read = $this->get_value($values);
|
66
|
$changed = $this->get_value($values, 'changed');
|
67
|
|
68
|
$last_comment = module_exists('comment') && !empty($this->options['comments']) ? $this->get_value($values, 'last_comment') : 0;
|
69
|
|
70
|
if (!$last_read && $changed > NODE_NEW_LIMIT) {
|
71
|
$mark = MARK_NEW;
|
72
|
}
|
73
|
elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
|
74
|
$mark = MARK_UPDATED;
|
75
|
}
|
76
|
elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
|
77
|
$mark = MARK_UPDATED;
|
78
|
}
|
79
|
return $this->render_link(theme('mark', array('type' => $mark)), $values);
|
80
|
}
|
81
|
}
|
82
|
}
|