Hiya Guys,

Am trying to work out a way to filter which node types appear using the tracker.module. For example in the FORUM there is a link called ACTIVE FORUM DISCUSSIONS, which, when you click on it gives you a list of every node type. As opposed to active forum discussions.

It's been noted as a feature request, but, I have managed to come up with a PHP Snippet that calls the tracker_page function in the tracker.module to display JUST a list of active forum topics.

I need help with the following (which works with 4.5.2) if anyone out there more familiar with php has a moment.

Here's the code (go to CREATE CONTENT -->> PAGE and paste the following into the page body and select the PHP filter before submitting):

** THIS ONLY WORKS WITH 4.5.X IT DOESN'T WORK WITH 4.6. ************



/**
 * Creates a RECENT POSTS tracker.module style list of forum topics and replies.
 * This works with drupal 4.5.x 
 * and does NOT work with 4.6. yet.
 *
 * To change the node type you want listed...simply change the $type value below
 * To change the length of list you want displayed..simply change the $listlength value below
 */

  $type="forum";
  $listlength="10";

  $header = array(
    array("data" => t("type"), "field" => "type"),
    array("data" => t("title"), "field" => "title"),
    array("data" => t("author"), "field" => "u.name"),
    array("data" => t("last post"), "field" => "last_activity", "sort" => "desc")
  );

  if ($id) {
    $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1  AND n.type='$type' GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name";
    $sql .= tablesort_sql($header);
    $sresult = pager_query($sql, $listlength, 1, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");

  }
  else {
    $sql = "SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND n.type='$type' GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name";
    $sql .= tablesort_sql($header);
    $sresult = pager_query($sql, $listlength, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND n.type='$type'");
  }

  while ($node = db_fetch_object($sresult)) {
    if (node_hook($node, 'tracker_comments')) {
      $cresult = node_invoke($node, 'tracker_comments');
    }
    elseif ($id) {
      $cresult = db_query("SELECT c.*, u.name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY c.cid DESC", $id, $node->nid);
    }
    else {
      $cresult = db_query("SELECT c.*, u.name FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.cid DESC", $node->nid);
    }

    $type = ucfirst(node_invoke($node->type, "node_name"));
    $title = l($node->title, "node/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme("mark") : "");
    $author = format_name($node);

    $comments = array();
    while ($comment = db_fetch_object($cresult)) {
      $comments[] = "<li>". t("%subject by %author", array("%subject" => l($comment->subject, "node/$node->nid", NULL, NULL, "comment-$comment->cid"), "%author" => format_name($comment))) ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : "") ."</li>\n";
    }

    if ($comments) {
      $comments = "<ul>". implode("\n", $comments) ."</ul>";
    }
    else {
      $comments = "";
    }

    $rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title . $comments, "class" => "content"), array("data" => $author, "class" => "author"), array("data" => format_date($node->last_activity, "small"), "class" => "last_post"));
  }

  if ($pager = theme("pager", NULL, $listlength, 1, tablesort_pager())) {
   $rows[] = array(array("data" => $pager, "colspan" => 4));
  }

  $output  = "<div id=\"tracker\">";
  $output .= theme("table", $header, $rows);
  $output .= "</div>";

print $output;


the above, just lists the 10 most recent active forum topics. need help with:

1. getting it paging - at the moment it doesn't have the NEXT/PREVIOUS page links it should at the bottom and I'm not sure where to change that in the code.

2. working with 4.6. - the above snippet is taken from an old version of tracker.module which has changed significantly between 4.5. to 4.6. Need tips on how to restructure it to work with 4.6

Anyone ?

Am very new to php.

Dub

Comments

Dublin Drupaller’s picture

Found a tracking.module that does the job..

http://drupal.org/node/24504

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate