Created
September 25, 2017 17:45
-
-
Save dapseen/0c1e2bc3e180e255ee81525a8a5c8c98 to your computer and use it in GitHub Desktop.
generating unique account ID -- Drupal 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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