You are here

function sms_valid_save_ruleset in SMS Framework 7

Same name and namespace in other branches
  1. 6.2 modules/sms_valid/sms_valid.module \sms_valid_save_ruleset()
  2. 6 modules/sms_valid/sms_valid.module \sms_valid_save_ruleset()

Creates or updates a ruleset.

Parameters

array $ruleset: A ruleset array.

Return value

bool true on success, false otherwise.

3 calls to sms_valid_save_ruleset()
SmsValidWebTest::testSmsValidFunctions in modules/sms_valid/sms_valid.test
Tests the internal sms_valid functions.
SmsValidWebTest::testSmsValidSettingsForm in modules/sms_valid/sms_valid.test
Tests the application of the sms_valid settings form and settings.
sms_valid_admin_ruleset_form_submit in modules/sms_valid/sms_valid.admin.inc
Submit handler for the sms_valid_admin_ruleset_form().

File

modules/sms_valid/sms_valid.module, line 274
Number validation feature module for Drupal SMS Framework.

Code

function sms_valid_save_ruleset($ruleset) {
  $prefix = $ruleset['prefix'];
  $name = $ruleset['name'];
  $iso2 = $ruleset['iso2'];
  $rules_z = serialize($ruleset['rules']);
  $dirs_enabled = $ruleset['dirs_enabled'];
  if (sms_valid_get_ruleset($prefix)) {

    // The ruleset exists so we use update query.
    return db_update('sms_valid_rules')
      ->fields(array(
      'name' => $name,
      'rules' => $rules_z,
      'dirs_enabled' => $dirs_enabled,
      'iso2' => $iso2,
    ))
      ->condition('prefix', $prefix)
      ->execute();
  }
  else {

    // The ruleset does not exist so we use insert query.
    return $id = db_insert('sms_valid_rules')
      ->fields(array(
      'prefix' => $prefix,
      'name' => $name,
      'rules' => $rules_z,
      'dirs_enabled' => $dirs_enabled,
      'iso2' => $iso2,
    ))
      ->execute();
  }
}