@@ -15,6 +15,7 @@ function comment_timer_views_data() {
'comments' => array(
'left_field' => 'cid',
'field' => 'cid',
+ 'required' => TRUE,
),
);
$data['comment_timer']['seconds'] = array(
@@ -31,6 +32,13 @@ function comment_timer_views_data() {
'handler' => 'views_handler_filter_numeric',
),
);
+ $data['node']['comment_timer'] = array(
+ 'title' => t('Time'),
+ 'help' => t('Time spent with the comments of the node.'),
+ 'field' => array(
+ 'handler' => 'comment_timer_handler_field_comment_timer',
+ ),
+ );
return $data;
}
@@ -49,6 +57,9 @@ function comment_timer_views_handlers() {
'comment_timer_handler_field_seconds' => array(
'parent' => 'views_handler_field_numeric',
),
+ 'comment_timer_handler_field_comment_timer' => array(
+ 'parent' => 'views_handler_field_numeric',
+ ),
),
);
}
--- /dev/null
+<?php
+// vim: set ft=php syntax=php expandtab ts=2 sw=2 autoindent smartindent:
+
+/**
+ * @file @TODO
+ */
+
+/**
+ * Views field handler for the Comment Timer's (bogus) summary field.
+ */
+class comment_timer_handler_field_comment_timer extends views_handler_field_numeric {
+ function render($values) {
+ if (!user_access('access comment timer')) {
+ // User is not permitted to access comment timer.
+ return;
+ }
+ return _comment_timer_seconds_to_hms($values->{$this->field_alias});
+ }
+ function query() {
+ // @TODO: This is terribly ugly. Please teach me the proper way to
+ // achieve the same result.
+ // @TODO: The same applies to sort and filter capabilities, which are
+ // missing, too.
+ $this->query->ensure_table('comments');
+ $this->query->tables['comment_timer'] = array('count' => 1, 'alias' => 'comment_timer');
+ $join = new views_join();
+ $join->construct('comment_timer', 'comments', 'cid', 'cid', array(), 'LEFT');
+ $this->query->table_queue['comment_timer'] = array(
+ 'table' => 'comment_timer',
+ 'num' => '1',
+ 'alias' => 'comment_timer',
+ 'join' => $join,
+ 'relationship' => 'comment_timer',
+ );
+ $this->query->add_groupby('nid');
+ parent::query();
+ $this->query->fields[$this->field_alias]['field'] = 'seconds)';
+ $this->query->fields[$this->field_alias]['table'] = 'SUM(comment_timer';
+ $this->query->fields[$this->field_alias]['aggregate'] = TRUE;
+ }
+}