Hello there,

I think it would be nice to increment node access statistics (daycount, totalcount, ... in {node_counter}) and add the audio node to {accesslog} everytime an audio file is played . Among other things, this would make it easier for users to browse through content that that's new or old to them and would allow the statistics module to keep track of system usage.

Thanks in advance,

.L.

Comments

drewish’s picture

leoburd, that sounds interesting. is there a module you could point me towards that does this correctly?

leoburd’s picture

Hello drewish,

Here's a little code snippet that should do the trick. It has to be updated to increment play_count and other specific audio.module counters, though.

BTW, I'd appreciate if you could concentrate all the statistics update functionality in a single function that could be called by my audio_xmlrpc.module ...

/*
 * Updates the Drupal statistics associated with the access to the specified audio node.
 *
 * @param $nid
 *   integer. the node id of the audio entry to be updated.
 *
 * @return
 *   integer. 1 in case of success, -1 in case of failure
 */
function audio_update_access_statistics($nid) {

  global $user;
// TODO: This method will have to update the file counters in 4.7
  //
  // update audio node access counters
  //

  // NOTE: the following is based on statistics_exit() function

  if (variable_get('statistics_count_content_views', 0)) {
    // We are counting content views.

    // 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)) {
    // Statistical logs are enabled.
    $referrer = referer_uri();  // this will be empty for XMLRPC updates
    $hostname = $_SERVER['REMOTE_ADDR'];  // NOTE: this should be empty, too -- it will show the IP of the DRUPAL server
    $path = "node/$nid"; // path to the specified audio entry node

    $query = "SELECT `title` FROM {node} WHERE nid = %d";
    $title = db_result(db_query($query, $nid));

    // Log this page access.
    db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s', %d, %d)", $title, $path, $referrer, $hostname, $user->uid, time());
  }

 //
 // Update the 'last viewed' timestamp of the specified node for current user
 //

  node_tag_new($nid);

  return 1;
}

drewish’s picture

Status: Active » Closed (duplicate)

I'm going to mark this as a duplicate of #63976, it focuses in on the node_new_tag(). The rest of the statistics code could be put into a contrib module using the new hook_audio() that was committed as part of #33708.