You are here

function notifications_custom_fields_update_all in Notifications 6.4

Update all fields for this subscription type

1 call to notifications_custom_fields_update_all()
notifications_custom_fields_form_submit in notifications_custom/notifications_custom.admin.inc
Submit fields form

File

notifications_custom/notifications_custom.admin.inc, line 270
Custom notifications module (admin features)

Code

function notifications_custom_fields_update_all($subscription) {
  if ($count = db_result(db_query("SELECT COUNT(*) FROM {notifications} WHERE type = '%s'", $subscription->type))) {

    // Delete all fields for this subscription type
    db_query("DELETE FROM {notifications_fields} WHERE sid IN (SELECT sid FROM {notifications} WHERE type = '%s')", $subscription->type);

    // Create the new fields
    foreach ($subscription
      ->get_fields() as $field) {
      db_query("INSERT INTO {notifications_fields} (sid, field, value, intval) SELECT sid, '%s', '%s', %d FROM {notifications} WHERE type = '%s'", $field->field, $field->value, (int) $field->value, $subscription->type);
    }
    drupal_set_message(t('@count subscriptions have been updated with the new values.', array(
      '@count' => $count,
    )));
  }
}