I want to create a view that displays all forum topics a user posted, plus added in that same view all forum posts to which the user commented. I can't figure out how to do this. It's easy to create a view that displays a user's forum posts. I also managed to create a view that displays all forum posts to which the user commented. (I used a relationship "Comment:Node" and added a filter that says the user id from the relation must not be the current user. I basically want the combination of both results in one (sortable) table.

Please note that this is exactly what the standard Drupal track page for a user does (except that's not just forum topics).

I would be able to create this view if I could specify two filters and specify that they have a boolean OR relationship, instead of the standard AND relationship.

Am I making sense? I find it difficult to explain. Let me phrase it completely differently.

If I create the first view I described above, and then add a relationship "Comment:Node", I get a view with the following query:

SELECT node.nid AS nid,
   node.title AS node_title,
   users.name AS users_name,
   users.uid AS users_uid
 FROM node node 
 LEFT JOIN comments comments ON node.nid = comments.nid
 LEFT JOIN node node_comments ON comments.nid = node_comments.nid
 INNER JOIN users users ON node.uid = users.uid
 WHERE node.type in ('forum')

I want this query, but somehow add the following condition to the where clause:

AND (comments.uid=***CURRENT_USER*** OR node.uid=***CURRENT_USER***)

Any help is much appreciated. (I'm considering writing a custom filter, but I don't know how to do that yet.)

Comments

svdoord’s picture

Ok, I got it to work using (what feels to me like) a work-around. I created a custom Drupal module and implemented the hook views_query_alter:

function mymodule_views_query_alter(&$view, &$query) {
	if ($view->name == 'forum_tracker') {
	  $query->add_where(1, 'node.uid = ***CURRENT_USER*** OR comments.uid = ***CURRENT_USER***');
	  /* The '1' makes sure that the where clause is put in a new group, which is required for this
	   * to work correctly. If you already have more than one group, this number needs to be higher.
	   */
	}
}

I still would like to know if I can do this without resorting to custom modules and PHP code, but it's less urgent now.

merlinofchaos’s picture

Status: Active » Fixed

...why don't you just look at the 'tracker' view that comes with Views, which does what tracker.module does?

svdoord’s picture

What the "tracker" view does is different from what the standard "track" tab inside a user's profile displays (which is what I was referring to). Tracker displays all articles, I only want the articles written by OR commented on by a specific user.

Status: Fixed » Closed (fixed)

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