When viewing a view 1 by 1 with ajax pager, or normal pager and display style as Node - Full, I would like to update the node count in the node statistics. I've noticed that only updates if I visit the node itself by it's path... not when I display it in this particular view which as an example is a full picture display of a photoblog.

So I would like to update the statistics on each page display in the views. Any way to do it? Thank you

Comments

dawehner’s picture

Yes, have a look how the statistics module does it, and do this in preprocess or the view template for a single row.

merlinofchaos’s picture

Right, this isn't something Views itself is likely to provide at any point. It should only be a few lines of code to add externally. Perhaps it could make a decent very small module. Heck, maybe there already is one.

hedac’s picture

ok.. I was confused with the node full display view in views, because it was displayed exactly as a full node view, except that the counters wasn't updated in each view. And I know it's not a standard node view. Of course Views is more generic and doesn't have to include a counter... but maybe in that case when it is full node view and 1 by 1... could be the case. Node - Teaser doesn't have to count as view.. but Node - Full would have to count.

I'm also thinking that it may be interesting also if using a View with fields if you want to control which fields to display as a full node when you don't have teasers..

Will look at that statistics module and look how to code a preprocess function... I still don't have a lot of experience in module programming but getting there day by day. Any help is appreciated too :)

In my case, maybe it is easier to use standard node views.. and include a Custom pager with "Custom pagers"

dawehner’s picture

Category: feature » support

You could write the following in your theme. I don't tested the code, and there is a todo

<?php
/**
 * Implementation of hook_exit().
 *
 * This is where statistics are gathered on page accesses.
 */
function yourtheme_preprocess_views_view_row_node__frontpage(&$vars) {
  // TODO get the nid
  global $user, $recent_activity;

  // A node has been viewed, so update the node's counters.
  db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $nid);
  // If we affected 0 rows, this is the first time viewing the node.
  if (!db_affected_rows()) {
    // We must create a new row to store counters for the new node.
    db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $nid, time());
  }
  if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
    // Log this page access.
    db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time());
  }
}
?>
dawehner’s picture

Status: Active » Fixed

I think this is fixed now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

hedac’s picture

omg dereine sorry I missed your replies for some reason. Thank you very much !