function webform_civicrm_nodeapi in Webform CiviCRM Integration 6.2
Same name and namespace in other branches
- 6 webform_civicrm.module \webform_civicrm_nodeapi()
Implements hook_nodeapi().
File
- ./
webform_civicrm.module, line 76 - 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)) {
$settings['data'] = unserialize($settings['data']);
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;
$settings['data'] = unserialize($settings['data']);
drupal_write_record('webform_civicrm_forms', $settings);
}
}
break;
case 'delete':
if (!empty($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;
}
}