sms_valid.install in SMS Framework 7
Same filename and directory in other branches
SMS Framework Number Validation feature module: Install file.
@package sms @subpackage sms_valid
File
modules/sms_valid/sms_valid.installView source
<?php
/**
* @file
* SMS Framework Number Validation feature module: Install file.
*
* @package sms
* @subpackage sms_valid
*/
/**
* Implements hook_install().
*/
function sms_valid_install() {
sms_valid_create_example_ruleset();
}
/**
* Implements hook_schema().
*
* @return array
* Drupal schema array.
*/
function sms_valid_schema() {
$schema = array();
$schema['sms_valid_rules'] = array(
'fields' => array(
'prefix' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Number prefix/code; 1-65535',
),
'name' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
'description' => 'Descriptive name for this prefix/ruleset',
),
'rules' => array(
'type' => 'text',
'not null' => FALSE,
'serialize' => TRUE,
'description' => 'Serialized ruleset',
),
'dirs_enabled' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 4,
'description' => 'Active msg directions. See SMS_DIR_* constants.',
),
'iso2' => array(
'type' => 'varchar',
'length' => 2,
'not null' => FALSE,
'description' => 'ISO 3166-1 alpha-2 country code',
),
),
'primary key' => array(
'prefix',
),
);
return $schema;
}
/**
* Create an example number validation ruleset.
*
* @param array $ret
* Array of query results.
*/
function sms_valid_create_example_ruleset(&$ret = array()) {
$prefix = 64;
$name = 'New Zealand';
$dirs_enabled = 4;
$iso2 = 'NZ';
$rules = array(
'21' => array(
'allow' => TRUE,
'comment' => 'Vodafone',
),
'22' => array(
'allow' => TRUE,
'comment' => 'Two Degrees Mobile',
),
'25' => array(
'allow' => FALSE,
'comment' => 'Telecom AMPS+TDMA (old)',
),
'26' => array(
'allow' => FALSE,
'comment' => 'Telecom pager network',
),
'27' => array(
'allow' => TRUE,
'comment' => 'Telecom CDMA',
),
'28' => array(
'allow' => TRUE,
'comment' => 'Slingshot',
),
'29' => array(
'allow' => TRUE,
'comment' => 'TelstraClear',
),
);
$rules_z = serialize($rules);
$sql = "INSERT INTO {sms_valid_rules} (prefix,name,rules,dirs_enabled,iso2)" . "VALUES (%d, '%s', '%s', %d, '%s')";
// @TODO Please convert this statement to the D7 database API syntax.
// $result = db_query($sql, $prefix, $name, $rules_z, $dirs_enabled, $iso2);
$result = db_insert('sms_valid_rules')
->fields(array(
'prefix' => $prefix,
'name' => $name,
'rules' => $rules_z,
'dirs_enabled' => $dirs_enabled,
'iso2' => $iso2,
))
->execute();
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
}
Functions
Name | Description |
---|---|
sms_valid_create_example_ruleset | Create an example number validation ruleset. |
sms_valid_install | Implements hook_install(). |
sms_valid_schema | Implements hook_schema(). |