I am developing a module that displays offers to users. Offers should be completed only once per person (they are identified by a GUID that is stored either in their user profile, or passed as an argument in the URL) the user is not required to be logged in or to have an account to complete an offer. The offers are a content type.

Once an offer is completed, it is recorded into a table called 'offer_transactions' this includes the GUID, and nid of the offer, amongst other things.

My issue is that I do not know how to create a view that will show all nodes of the type 'offer' that are NOT recorded in the offer_transactions table with 'uguid' (as an argument to the view) and 'status' as 'true'

This is how I ended up doing it:

<?php

function views_views_pre_execute(&$view) {
   if($view->name=="offer_list") {
    $view->build_info['query']="SELECT node.nid AS nid FROM node node WHERE (node.type in ('%s')) AND (node.status <> 0) AND '%s' NOT IN (SELECT offer_transactions.slid FROM offer_transactions WHERE node.nid = offer_transactions.ofid AND offer_transactions.status = 1)";
   }
}

?>

It seems to be working at this point, but suggestions or corrections are appreciated.

Comments

oddible’s picture

You could create a subquery for all nodes "in the offer_transactions table with 'uguid' (as an argument to the view) and 'status' as 'true' " grouped by offer ID with a Count aggregate. Then left join your offer table to this WHERE Count = 0.