I am struggling with a seemingly simple problem (this cuts across a couple of modules although Views is at the centre of it).

I have created a view (which is based on a required node reference relationship) which I am feeding through to a Node panel page, which - using the node being viewed NID argument- displays the CCK data for that particular node alone. Any node that satisfies the required node reference relationship displays the view.

In addition to the data for that node, I also want to display the same fields of data for a "Benchmark" node persistently across all nodes that display results above. I managed to accomplish this using the Views_Or module, where I inserted the fixed value of the benchmark node's NID as the second OR argument in the view. The Panel page now displays both the node being viewed and the benchmark node together in a table.

However, this has raised a new problem, as the Benchmark node is displayed (alone) even when the node being viewed does not satisfy the node reference relationship. Basically, I only want this second argument (the benchmark node) to display if the first argument validates. Otherwise I don't want the view to show any results.

Is there a way that I can accomplish this? Perhaps I have taken the wrong approach with Views_Or, as there may be alternative ways to achieve this apparently simple objective. I am a beginner so can't dig too deep into the code to resolve this. Really grateful for any help or pointers.

Comments

merlinofchaos’s picture

Status: Active » Fixed

Your first error is the phrase 'relatively simple'. Views doesn't do a good job of showing completely unrelated data (your benchmark node has absolutely no relationship to the node you're actually displaying) in the same table. Ordinarily I'd say to just use an attachment view, but if you're using a table, they won't be in the same table.

The only reasonable solution I can think is to use PHP code in the argument validator. Use the node: nid argument, and set it to receive multiple nids.

Your validator will receive the original nid; node_load to get the referenced nid (you'll need to figure out the right query to do this, I'm not sure what it is) and if the node is there, change the argument to 'XXX+YYY' where XXX is the referenced nid you want to display, and YYY is your benchmark nid. The order of the two arguments is unimportant, you'll need to use sort criteria to make sure your benchmark node appears where you want it.

danieldd’s picture

Thanks very much for the advice, and for the module. I'm new to PHP so am going to struggle a bit even with the solution pointed out, but if/when I get there will post for others to see. Thanks again.

danieldd’s picture

If anyone is interested a solution to this issue is to add this code to the Views argument validator:

$count = db_result(db_query("SELECT nid FROM {content_type_mycontenttypehere} WHERE field_mynodereferencefieldhere_nid = %d", $argument)); 
if ($count) {
$handler->argument = $argument . '+myfixedNIDhere'; 
return TRUE; 
} 
else { 
return FALSE; 
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.