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

Definition of views_handler_field_history_user_timestamp.

File

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