| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_handler_field_node_new_comments.inc,v 1.7 2009/07/02 00:13:12 merlinofchaos Exp $ 3 4 /** 5 * Field handler to display the number of new comments 6 */ 7 class views_handler_field_node_new_comments extends views_handler_field_numeric { 8 function init(&$view, $options) { 9 parent::init($view, $options); 10 11 // translate an older setting: 12 if (!empty($options['no_empty'])) { 13 $this->options['hide_empty'] = TRUE; 14 unset($this->options['no_empty']); 15 } 16 } 17 18 function construct() { 19 parent::construct(); 20 $this->additional_fields = array('nid' => 'nid', 'type' => 'type'); 21 } 22 23 function option_definition() { 24 $options = parent::option_definition(); 25 26 $options['link_to_comment'] = array('default' => TRUE); 27 28 return $options; 29 } 30 31 function options_form(&$form, &$form_state) { 32 parent::options_form($form, $form_state); 33 $form['link_to_comment'] = array( 34 '#title' => t('Link this field to new comments'), 35 '#description' => t('This will override any other link you have set.'), 36 '#type' => 'checkbox', 37 '#default_value' => $this->options['link_to_comment'], 38 ); 39 } 40 41 function query() { 42 $this->ensure_my_table(); 43 $this->add_additional_fields(); 44 $this->field_alias = $this->table . '_' . $this->field; 45 } 46 47 function pre_render(&$values) { 48 global $user; 49 if (!$user->uid || empty($values)) { 50 return; 51 } 52 53 $nids = array(); 54 $ids = array(); 55 foreach ($values as $id => $result) { 56 $nids[] = $result->{$this->aliases['nid']}; 57 $values[$id]->{$this->field_alias} = 0; 58 // Create a reference so we can find this record in the values again. 59 if (empty($ids[$result->{$this->aliases['nid']}])) { 60 $ids[$result->{$this->aliases['nid']}] = array(); 61 } 62 $ids[$result->{$this->aliases['nid']}][] = $id; 63 } 64 65 if ($nids) { 66 $result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = %d WHERE n.nid IN (" . implode(', ', $nids) . ") AND c.timestamp > GREATEST(COALESCE(h.timestamp, %d), %d) AND c.status = %d GROUP BY n.nid ", $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT, COMMENT_PUBLISHED); 67 68 while ($node = db_fetch_object($result)) { 69 foreach ($ids[$node->nid] as $id) { 70 $values[$id]->{$this->field_alias} = $node->num_comments; 71 } 72 } 73 74 } 75 } 76 77 function render_link($data, $values) { 78 if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { 79 $node = new stdClass(); 80 $node->nid = $values->{$this->aliases['nid']}; 81 $node->type = $values->{$this->aliases['type']}; 82 $this->options['alter']['make_link'] = TRUE; 83 $this->options['alter']['path'] = 'node/' . $node->nid; 84 $this->options['alter']['query'] = comment_new_page_count($values->node_comment_statistics_comment_count, $values->node_new_comments, $node); 85 $this->options['alter']['fragment'] = 'new'; 86 } 87 88 return $data; 89 } 90 91 function render($values) { 92 if (!empty($values->{$this->field_alias})) { 93 return $this->render_link(parent::render($values), $values); 94 } 95 else { 96 $this->options['alter']['make_link'] = FALSE; 97 } 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |