You are here

function signup_nodeapi in Signup 5.2

Same name and namespace in other branches
  1. 5 signup.module \signup_nodeapi()
  2. 6.2 signup.module \signup_nodeapi()
  3. 6 signup.module \signup_nodeapi()

Implementation of hook_nodeapi().

Related topics

File

./signup.module, line 621
The Signup module (http://drupal.org/project/signup) manages replies to nodes. In particular, it's good for event management. Signup supports sending reminder emails and automatically closing signups for nodes with a start time, via the Event…

Code

function signup_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      signup_save_node($node, $op);
      break;
    case 'delete':

      // Clean up the signup tables for the deleted node.
      db_query("DELETE FROM {signup} WHERE nid = %d", $node->nid);
      db_query("DELETE FROM {signup_log} WHERE nid = %d", $node->nid);
      break;
    case 'load':

      // Check for a signup for this node.
      // If it's a new node, load the defaults.
      $result = db_query("SELECT * FROM {signup} WHERE nid = %d", $node->nid ? $node->nid : 0);

      // Load signup data for both new nodes w/ enabled node types,
      // and any existing nodes that are already signup enabled.
      if (!$node->nid && variable_get('signup_node_default_state_' . $node->type, 'disabled') == 'enabled_on' || $node->nid && db_num_rows($result)) {
        $signup = db_fetch_object($result);
        $node->signup = 1;
        $node->signup_forwarding_email = $signup->forwarding_email;
        $node->signup_send_confirmation = $signup->send_confirmation;
        $node->signup_confirmation_email = $signup->confirmation_email;
        $node->signup_send_reminder = $signup->send_reminder;
        $node->signup_reminder_days_before = $signup->reminder_days_before;
        $node->signup_reminder_email = $signup->reminder_email;
        $node->signup_close_signup_limit = $signup->close_signup_limit;
        $node->signup_status = $signup->status;
        if ($node->nid) {
          $node->signup_total = db_result(db_query("SELECT COUNT(*) FROM {signup_log} WHERE nid = %d", $node->nid));
        }
      }
      else {
        $node->signup = 0;
      }
      break;
    case 'view':

      // If this is a signup node, figure out what (if anything) to print.
      // Only include any of this if we're trying to view the node as
      // a page, not during the view from comment validation, etc.
      if ($page && _signup_needs_output($node) && variable_get('signup_form_location', 'node') == 'node') {
        $output = _signup_node_output($node);
        if (!empty($output)) {

          // Save into a node property for retrieval from the theme layer.
          $node->signup_view = $output;

          // Store the data into the content array, for default display.
          $node->content['signup'] = array(
            '#value' => $output,
            '#weight' => variable_get('signup_info_node_weight_' . $node->type, 10),
          );
        }
      }
      break;
  }
}