You are here

function webform_civicrm_nodeapi in Webform CiviCRM Integration 6

Same name and namespace in other branches
  1. 6.2 webform_civicrm.module \webform_civicrm_nodeapi()

Implementation of hook_nodeapi().

File

./webform_civicrm.module, line 61
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'load':
      $db = db_query('SELECT * FROM {webform_civicrm_forms} WHERE nid = %d', $node->nid);
      if ($settings = db_fetch_array($db)) {
        return array(
          'webform_civicrm' => $settings,
        );
      }
      break;
    case 'insert':

      // For compatibility with node_clone module
      if (arg(2) == 'clone') {
        $db = db_query('SELECT * FROM {webform_civicrm_forms} WHERE nid = %d', arg(1));
        if ($settings = db_fetch_array($db)) {
          $settings['nid'] = $node->nid;
          drupal_write_record('webform_civicrm_forms', $settings);
        }
      }
      break;
    case 'delete':
      if (isset($node->webform)) {
        db_query('DELETE FROM {webform_civicrm_forms} WHERE nid = %d', $node->nid);

        // Submissions have already been deleted from webform_submissions table, so we'll do the opposite of a join to find them
        db_query('DELETE FROM {webform_civicrm_submissions} WHERE sid NOT IN (SELECT sid FROM {webform_submissions})');
      }
      break;
  }
}