• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

modules/node/views_handler_field_history_user_timestamp.inc

00001 <?php
00009 class views_handler_field_history_user_timestamp extends views_handler_field_node {
00010   function init(&$view, &$options) {
00011     parent::init($view, $options);
00012     global $user;
00013     if ($user->uid) {
00014       $this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
00015       $this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
00016       if (module_exists('comment') && !empty($this->options['comments'])) {
00017         $this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
00018       }
00019     }
00020   }
00021 
00022   function option_definition() {
00023     $options = parent::option_definition();
00024 
00025     $options['comments'] = array('default' => FALSE);
00026 
00027     return $options;
00028   }
00029 
00030   function options_form(&$form, &$form_state) {
00031     parent::options_form($form, $form_state);
00032     if (module_exists('comment')) {
00033       $form['comments'] = array(
00034         '#type' => 'checkbox',
00035         '#title' => t('Check for new comments as well'),
00036         '#default_value' => !empty($this->options['comments']),
00037         '#fieldset' => 'more',
00038       );
00039     }
00040   }
00041 
00042   function query() {
00043     // Only add ourselves to the query if logged in.
00044     global $user;
00045     if (!$user->uid) {
00046       return;
00047     }
00048     parent::query();
00049   }
00050 
00051   function render($values) {
00052     // Let's default to 'read' state.
00053     // This code shadows node_mark, but it reads from the db directly and
00054     // we already have that info.
00055     $mark = MARK_READ;
00056     global $user;
00057     if ($user->uid) {
00058       $last_read = $this->get_value($values);
00059       $created = $this->get_value($values, 'created');
00060       $changed = $this->get_value($values, 'changed');
00061 
00062       $last_comment = module_exists('comment') && !empty($this->options['comments']) ?  $this->get_value($values, 'last_comment') : 0;
00063 
00064       if (!$last_read && $created > NODE_NEW_LIMIT) {
00065         $mark = MARK_NEW;
00066       }
00067       elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
00068         $mark = MARK_UPDATED;
00069       }
00070       elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
00071         $mark = MARK_UPDATED;
00072       }
00073       return $this->render_link(theme('mark', array('type' => $mark)), $values);
00074     }
00075   }
00076 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1