Video tutorials and Online Training
Unlimited Access
Video Tutorials
Video Available as Flash

Bookmark Us

Bookmark Website 
Bookmark Page 

User login

Recent comments

Navigation

Creating a view to show all nodes that exist in user's Organic Groups using argument handling code in Drupal 6

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;
}
?>

No comments

Add your comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.

Videos Search