Show block for the user if uid has created a node where nodetype=...
I've been searching for a solution to this for about six hours now... I'm turning to the forum.
I've created a site that allows arts organizations to submit grant applications online. I used CCK to create the application as a nodetype ("application2007"). And I used Node Family to set the maximum population to 1 (since each org is only allowed to submit once a year).
Everything is working fine, the application's working, no one can submit more than once... Except that I'm not sure how to present the navigation and add/node in a friendly way:
1. I'd like to remove "APPLY NOW" from the primary navigation if the logged-in user has already submitted a node where nodetype=application2007... I think this may require some sort of block. But I only have a vague feeling about that.
2. And/or I'd like to have a block that shows up on the node/add page where nodetype=application2007 and the user has already submitted a node of that type (right now, they can't submit two nodes of the same type, but they get the warning AFTER they've hit submit, and that seems kind of an unfriendly thing to do).
So! That's my question.

Views with arguments
Hi mjgfoster,
refering to your question.
Step one create a view use block as display, fields any fields you want to show, argument = uid is author/ Use empty text in the empty text you write something like" you may still create an grant aplication". In the Header you write "You have already done one aplication for this yaer" Save the view. Now go to administer->blocks activate your block and just show him ad pages with= node/add/* or node node/add/yourcontenttype.
I hope this will help you. Other posibility is to theme our tpl.php but this is more complicate.
Dirk
To make a block visible only
To make a block visible only if the current user has *not* posted anything of type 'application2007', you can use something like this in the block's visibility text box:
<?php
global $user; // the current logged-in user
$result = db_query(db_rewrite_sql("SELECT nid FROM {node} n WHERE type = 'application2007' AND uid = $user->uid"));
$rows = db_num_rows($result);
$showit = $rows ? FALSE : TRUE;
return $showit;
?>
To do that with a '/node/add/application2007' link, I don't know... maybe put the link in a block, using:
<?phpprint l('Submit an Application', 'node/add/application2007');
?>
not a link
Hi cog.rusty,
I´m not talking about a link. In the block settings you can choose where to show the block. If he shows the block at the page node/add/* it will apear only on page with the arguments node/add in the url.
I think for a beginner this is a quite easy solution.
Dirk
Thanks, guys!
Hey cog.rusty and Dirk --
As it turns out, both your solutions work -- and, better, I can use them both (although it'll take some content tweaking, but that's better than smacking my head against the PHP wall all afternoon).
Thanks for the help.
Matthew
(no title)
@DesignWork: The block could be made to appear only in those pages AND only if the user has not already created an 'application2007' node, by changing the code slightly to include both condition:
$showit = $rows ? FALSE : TRUE;$allowedpage = (arg(0) == 'node' && arg(1) == 'add') ? TRUE : FALSE;
$showit = $showit && $allowedpage;
yes you are right
Hi cog.rusty
you are all right. I think we both just had two different aproaches.
Dirk