views_handler_field_history_user_timestamp.inc

  1. 3.x modules/node/views_handler_field_history_user_timestamp.inc
  2. 2.x modules/node/views_handler_field_history_user_timestamp.inc

File

modules/node/views_handler_field_history_user_timestamp.inc
View source
  1. <?php
  2. /**
  3. * Field handler to display the marker for new content.
  4. */
  5. class views_handler_field_history_user_timestamp extends views_handler_field_node {
  6. function init(&$view, $options) {
  7. parent::init($view, $options);
  8. global $user;
  9. if ($user->uid) {
  10. $this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
  11. $this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
  12. if (module_exists('comment') && !empty($this->options['comments'])) {
  13. $this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
  14. }
  15. }
  16. }
  17. function option_definition() {
  18. $options = parent::option_definition();
  19. $options['comments'] = array('default' => FALSE);
  20. return $options;
  21. }
  22. function options_form(&$form, &$form_state) {
  23. parent::options_form($form, $form_state);
  24. if (module_exists('comment')) {
  25. $form['comments'] = array(
  26. '#type' => 'checkbox',
  27. '#title' => t('Check for new comments as well'),
  28. '#default_value' => !empty($this->options['comments']),
  29. );
  30. }
  31. }
  32. function query() {
  33. // Only add ourselves to the query if logged in.
  34. global $user;
  35. if (!$user->uid) {
  36. return;
  37. }
  38. parent::query();
  39. }
  40. function render($values) {
  41. // Let's default to 'read' state.
  42. // This code shadows node_mark, but it reads from the db directly and
  43. // we already have that info.
  44. $mark = MARK_READ;
  45. global $user;
  46. if ($user->uid) {
  47. $last_read = $values->{$this->field_alias};
  48. $created = $values->{$this->aliases['created']};
  49. $changed = $values->{$this->aliases['changed']};
  50. $last_comment = module_exists('comment') && !empty($this->options['comments']) ? $values->{$this->aliases['last_comment']} : 0;
  51. if (!$last_read && $created > NODE_NEW_LIMIT) {
  52. $mark = MARK_NEW;
  53. }
  54. elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
  55. $mark = MARK_UPDATED;
  56. }
  57. elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
  58. $mark = MARK_UPDATED;
  59. }
  60. return $this->render_link(theme('mark', $mark), $values);
  61. }
  62. }
  63. }