One solution that comes to mind includes using the nodereference_url_create_link function that is included in the Node Reference URL Widget module. From the documentation of the specific function:
* Helper function for themers to easily create a link.
* This function should be used in custom themes, rather than making manual
* links because it first checks a user's access before showing the link. If
* the user does not have access to create the node then an empty string will
* be returned.
* @param $node
* The node object that will be referenced.
* @param $field_name
* The name of the Node Reference field.
* @param $type_name
* The name of node type that contains the Node Reference field.
* @param $attributes
* Optional. An array of additional attributes to add to the link.
You can use this in the node.tpl.php file for the Job Posting content type (which should be along the lines of node--job_posting.tpl.php if you're in D7 or node-job_posting.tpl.php for D6). The outline of the process should be as described below:
- Hide the field at the top of your template file (you will render it later on if the user did not apply for the specific job).
- Check if the user has already created an application node that references to the current posting.
The first step can be easily implemented by writing something along the lines of:
at the top of your template file. Use a
dpm($content); first to make sure that you are hiding the right field.
The second step is a bit trickier. The most elegant way that comes to mind is to use the Corresponding Node References module so that when you create a reference from the application to the posting, a corresponding reference from the posting to the application is also created (this can also be useful if you want to show all the applications that were created for a specific posting in the posting's page).
After you have "linked" the posting and the application with CNR, all you need to do is check if the author of the other postings is the logged in user. Specifically, you can use the node reference array in the
$node object to get the referencing applications with node_load_multiple and then with a
foreach loop compare each
$node->uid against the uid of the logged in user.
There is a blog post in Drutácora that describes a similar process and includes relevant code snippets (it's not in English but you should get the basic idea from the code).