background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
Eric.London's picture

I recently created a view to show all the nodes that exist in a user's organic groups. I originally created the same view in Drupal 5 by adding the filter "OG: Post in User Subbed Groups" is equal to "Currently Logged In User". Unfortunately, I could not find the equivalent filter in Drupal 6 Views, so I decided to use arguments. Argument handling code is structured a differently in Drupal 6:

1) add a new argument
2) for "Action to take if argument is not present" choose "Provide default argument"
3) for "Default argument type" choose "PHP Code"
4) for "PHP argument code" I entered:

return MYMODULE_views_group_nids();

It's a personal preference of mine to NOT insert code into my database, so I added the previously called function into a module. IMHO, code belongs in subversion so it can be versioned properly, not in a database. Here's my function definition:

<?php
function MYMODULE_views_group_nids() {
 
// create SQL statement to look up all group nodes of the current user
 
$sql = "select nid from og_uid where uid = '%d' and is_active='1'";
   
 
// query database
 
$resource = db_query($sql, db_escape_string($GLOBALS['user']->uid));

 
// fetch results from resource
 
$results = array();
  while (
$row = db_fetch_array($resource)) $results[] = $row['nid'];

 
// rollup results, comma separated
 
$results = implode(',', $results);

 
// return result
 
return $results;
}
?>

Syndicate content