Hi.

I need to create some menu items which will vary based on whether a user has any nodes of a particular type.

If they have no nodes of type Example
- they would get a link to create a node of type Example.
If they have 1 node of type Example
- they would get 3 links which would have to change based on the actual node they created of that type.
--- View your Example
--- Edit your Example
--- Delete your Example

I've been told that I need to write a custom module to do this by several people. I understand that.

I'm hoping someone has done something similar and that someone has something I could look at as an example to work from as I have not written a module before and I am finding that doing so is very intimidating and complex.

I have a query that I think I can use to check how many nodes a user has of that type.

$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE uid = %d AND type = %s", $user->uid, $type))

Comments

GeekyLass’s picture

This was entered into a block.
On one of my test accounts, I have a personal ad but I'm getting the create a personal ad link.
A beta tester has no personal ad, and he is getting view, edit and delete links.
on Admin (user 01) it has a create a personal ad link, which is correct. If I create a personal ad the menu doesn't change.
Code is thanks to cat omega

global $user;
global $base_url;

$type = "personal_ad";
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type =
'%s' AND uid = %d", $type, $user->uid));

if ($count < 0) 
{
    $pad_nid = db_result(db_query("SELECT nid FROM {node} WHERE type = '%s' AND uid = %d", $type, $user->uid));

    print '<ul>';
    print '<li>' . '<a href="' . $base_url . '/' . drupal_get_path_alias('node/' . $pad_nid) . '">View Personal Ad</a></li>';
    print '<li>' . '<a href="' . $base_url . '/' . drupal_get_path_alias('node/' . $pad_nid) . '/edit">Edit Personal Ad</a></li>';
    print '<li>' . '<a href="' . $base_url . '/' . drupal_get_path_alias('node/' . $pad_nid) . '/delete">Delete Personal Ad</a></li>';
    print '</ul>';

}

else 
{
    print '<ul><li><a href="' . $base_url . '/node/add/personal-ad">Create Personal Ad</a></li></ul>';
}
As If’s picture

i think you mean > 0.
if($count > 0)

-------------------------------------------
Interactive Worlds and Immersive Obsessions
http://www.asifproductions.com