function node_registration_update_13 in Node registration 7
Create `weight` column and fill it.
File
- ./
node_registration.install, line 338 - Install, uninstall, enable and disable hooks and schema.
Code
function node_registration_update_13() {
db_add_field('node_registration', 'weight', array(
'description' => 'Used for waitinglist execution order and display.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
$registrations = db_query('SELECT registration_id, nid FROM {node_registration} ORDER BY nid ASC, registration_id ASC')
->fetchAllKeyed();
$weight = $last_nid = 0;
foreach ($registrations as $rid => $nid) {
if ($nid != $last_nid) {
$weight = 0;
}
$last_nid = $nid;
db_update('node_registration')
->fields(array(
'weight' => $weight,
))
->condition('registration_id', $rid)
->execute();
$weight++;
}
}