Skip to content

Instantly share code, notes, and snippets.

@dapseen
Created September 25, 2017 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dapseen/0c1e2bc3e180e255ee81525a8a5c8c98 to your computer and use it in GitHub Desktop.
Save dapseen/0c1e2bc3e180e255ee81525a8a5c8c98 to your computer and use it in GitHub Desktop.
generating unique account ID -- Drupal 7
<?php
/**
* implements hook_schema()
*/
function cribs_schema()
{
$schema['cribs'] = array(
'description' => 'table holding account id of users',
'fields' => array(
'uid' => array(
'description' => 'user id from users table',
'type' => 'int',
'not null' => TRUE,
),
'accountid' => array(
'description' => 'variable generated from cribs module',
'type' => 'varchar',
'length' => '256',
'not null' => TRUE,
),
),
'foreign keys' => array(
'user_account' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
'indexes' => array(
'uid' => array('uid'),
),
);
return $schema;
}
function cribs_user_insert(&$edit, $account, $category) {
kpr($edit);
kpr($account);
function _cribs_accountid_during($account){
$strip = substr($account->name, 0, -2);
$content = $strip . '490' . $account->uid;
return $content;
}
//insert records into database
db_insert('cribs')
->fields( array(
'uid'=> $account->uid,
'accountid'=> _cribs_accountid_during($account),
))
->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment