I'm using Views to display fields of an event content type. I created a custom link that allows users to quickly go to the signup form. However, this link is now always shown and does not update when someone has already signed up, allowing multiple signups per person for the same event.

I'd like a link like you have with the content edit and delete link, a prebuilt Views signup link. Which displays 'Sign up' when a user hasn't done this yes, and displays 'Manage your signup' after that. Or perhaps with a field button that allows the link to be hidden when someone has already signed up.

Comments

Pene’s picture

There is a method which you can use to solve this problem. First of all you have to be user #1. Then go and get Views PHP module, then install and enable. Then go in to your calendar, week etc. view. Add a PHP field into Fields section. Then at the Output code section, insert something like this:


/*
$nodeidd - the node (event) ID.
field_data_field_event_capacity - A table in your database. The field_event_capacity shows the maximum capacity of an event (this must be a mandatory, number-type variable in your event content type).
$capacity - The maximum capacity of your events.
field_data_field_event_signup - Another table in your database. The field_event_signup is a referencing variable in your signup module.
$signedup - The actual number of attendees on your events.
$usernumber - User ID.
*/

$nodeidd=$data->nid;
$query2 = db_select('field_data_field_event_capacity', 'fec');
$query2->fields('fec', array('field_event_capacity_value'))
    ->condition('fec.entity_id', $nodeidd);
$capacity = $query2->execute()->fetchField();
$query = db_select('field_data_field_event_signup', 'fes');
$query->fields('fes', array('entity_id'))
    ->condition('fes.field_event_signup_nid', $nodeidd);
$signedup=$query->countQuery()->execute()->fetchField();
echo $signedup." / ".$capacity." - "; // Prints the actual / maximum capacity.

global $user;
$usernumber = $user->uid;
$query = db_select('node', 'n');
$query->join('field_data_field_event_signup', 'b', 'n.nid = b.entity_id');
$query
  ->fields('n', array('nid'))
  ->condition('n.type', 'signup') // singup type content
  ->condition('n.status', '1') // available content
  ->condition('n.uid', $usernumber) // actual user's content
  ->condition('b.field_event_signup_nid', $nodeidd); // This is the last query that turns the scale (one or no hit).
$countt=$query->countQuery()->execute()->fetchField(); // : If it has been set (with 1), the user signed up to the event before. If the user has not signed up yet, it will be empty.

if ($capacity > $signedup) { // Is there any room for you? Yes.
  if (!$countt) { // So variable not set.
    echo "<a href=/node/add/signup/".$nodeidd."?destination=node/".$nodeidd."><b>GO!</b>"; // Direct link to every event's signup page
  } else { // So variable has been set.
    echo "<font color=green><b>OK</b></font>"; // You are in.
  }
} else { // There is no room for you.
    echo "<font color=red><b>Full</b></font>"; // Full house.
}

It works for me atm, but there is a possibility that it has some serious bugs. Hope it helps.