开发者

How to create a Drupal forum reporting/analytics view?

开发者 https://www.devze.com 2023-02-09 15:35 出处:网络
I want to create a page in Drupal to report some basic forum information. I thought I\'d use Views, but Views only lets you set one \"entity\" type per view but forum topics are made up of nodes and c

I want to create a page in Drupal to report some basic forum information. I thought I'd use Views, but Views only lets you set one "entity" type per view but forum topics are made up of nodes and comments (aka, topics and replies).

Ideally, I'd like a single view that lists all forum nodes and comments together in a single table (sorted by date), along with a total number of both combined, if possible. Is there a way to do that with Views?

Update: What I'm looking for is something like this:

-------------------------------------------开发者_StackOverflow中文版------------
| User | Post                      | Type    | Date   |
-------------------------------------------------------
| amy  | post text appears here    | post    | 1/5/01 |
| bob  | comment text appears here | comment | 1/5/01 |
| amy  | another comment here      | comment | 1/5/01 |
| cid  | another post appears here | post    | 1/4/01 |
| dave | yet another comment here  | comment | 1/4/01 |
-------------------------------------------------------
total posts + comments: 5


Not sure what you really want. Either you can display nodes + number of comments or nodes and comments at the same level but then they don't have a total number because they are all separate? Or do you want to show each comment separate together with the number of comments in that thread?

If the latter, that might not be trivial.

Basically, you could create a UNION Select query and query both the node and the comment table. could look like this:

(SELECT 'node' AS type, n.nid as id, n.title as title, nncs.comment_count as comment_count, n.created as timestamp FROM {node} n INNER JOIN {node_comment_statistics} nncs ON n.nid = nncs.nid)
UNION
(SELECT 'comment' AS type, c.cid as id, c.subject as title, cncs.comment_count as comment_count, c.timestamp as timestamp FROM {comments} c INNER JOIN {node_comment_statistics} cncs ON c.nid = cncs.nid)
ORDER BY timestamp DESC LIMIT 10;

That will return a result containing: node/comment | id | title | comment_count | timestamp.

See http://dev.mysql.com/doc/refman/5.1/en/union.html for more information about UNION.

You can then theme that as a table.

Hints:

  • If you need more data, either extend the query or use node/comment_load
  • You could also join {node} in the second query and use the node title instead of comment subject
  • That query is going to be slow because it will always do a filesort because you have a union there. It might actually be faster to execute two separate queries and then mangle them together in PHP if you have a
    large number of nodes/comments


It turns out the Tracker 2 module provides enough of what I needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号