two way comparison between old and new variety sessions
This commit is contained in:
@@ -765,26 +765,67 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
|||||||
array(':nid' => $values['nid']))->fetchObject();
|
array(':nid' => $values['nid']))->fetchObject();
|
||||||
$previous_variety_ids = drupal_json_decode($person->booking_variety_ids);
|
$previous_variety_ids = drupal_json_decode($person->booking_variety_ids);
|
||||||
|
|
||||||
|
// iterate over the new list comparing to the old list
|
||||||
foreach ($booking_variety_ids as $new_tid => $new_sid) {
|
foreach ($booking_variety_ids as $new_tid => $new_sid) {
|
||||||
|
|
||||||
//check if there was a previous session ID for this person in this timeslot
|
//check if there was a previous session ID for this person in this timeslot
|
||||||
if (! isset($previous_variety_ids[$new_tid])) {
|
if (! isset($previous_variety_ids[$new_tid])) {
|
||||||
watchdog('booking_debug', 'Person @nid in timeslot @tid had no previous session id registered but is now @new.', array(
|
watchdog('booking_debug', 'Person @nid in timeslot @tid had no previous session id registered but is now @new.', array(
|
||||||
'@nid' => $values['nid'], '@tid' => $new_tid, '@new' => $new_sid));
|
'@nid' => $values['nid'], '@tid' => $new_tid, '@new' => $new_sid));
|
||||||
|
|
||||||
|
// increase regn count for new session
|
||||||
|
db_update('booking_variety_sessions')
|
||||||
|
->expression('booking_variety_regncount', 'booking_variety_regncount + :count', array(':count' => 1))
|
||||||
|
->condition('vid', $new_sid)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$previous_sid = $previous_variety_ids[$new_tid];
|
||||||
//compare session id in this timeslot to the previous value
|
//compare session id in this timeslot to the previous value
|
||||||
if ($new_sid != $previous_variety_ids[$new_tid]) {
|
if ($new_sid != $previous_sid) {
|
||||||
watchdog('booking_debug', 'Person @nid in timeslot @tid previously registered for session id @vid but new value is @new', array(
|
watchdog('booking_debug', 'Person @nid in timeslot @tid previously registered for session id @vid but new value is @new', array(
|
||||||
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $previous_variety_ids[$new_tid], '@new' => $new_sid));
|
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $previous_sid, '@new' => $new_sid));
|
||||||
|
|
||||||
|
// if variety session has changed then update the counts for old and new
|
||||||
|
if ($new_sid != $previous_sid) {
|
||||||
|
// reduce regn count for old session
|
||||||
|
watchdog('booking_debug', 'Person @nid in timeslot @tid is no longer registered for variety session @vid so reducing count by 1', array(
|
||||||
|
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $previous_sid));
|
||||||
|
db_update('booking_variety_sessions')
|
||||||
|
->expression('booking_variety_regncount', 'booking_variety_regncount - :count', array(':count' => 1))
|
||||||
|
->condition('vid', $previous_sid)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
// increase regn count for new session
|
||||||
|
watchdog('booking_debug', 'Person @nid in timeslot @tid is now registered for variety session @vid so increasing count by 1', array(
|
||||||
|
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $new_sid));
|
||||||
|
db_update('booking_variety_sessions')
|
||||||
|
->expression('booking_variety_regncount', 'booking_variety_regncount + :count', array(':count' => 1))
|
||||||
|
->condition('vid', $new_sid)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
watchdog('booking_debug', 'Person @nid in timeslot @tid has not changed variety session @vid', array(
|
watchdog('booking_debug', 'Person @nid in timeslot @tid has not changed variety session @vid', array(
|
||||||
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $new_sid));
|
'@nid' => $values['nid'], '@tid' => $new_tid, '@vid' => $new_sid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//iterate over the old list comparing to the new list in case there are regn counts we need to decrease
|
||||||
|
foreach ($previous_variety_ids as $previous_tid => $previous_sid) {
|
||||||
|
if (! isset($booking_variety_ids[$previous_tid])) {
|
||||||
|
watchdog('booking_debug', 'Person @nid in timeslot @tid is no longer registered for a variety session so reducing count for @vid by 1', array(
|
||||||
|
'@nid' => $values['nid'], '@tid' => $previous_tid, '@vid' => $previous_sid,
|
||||||
|
));
|
||||||
|
// reduce regn count for old session
|
||||||
|
db_update('booking_variety_sessions')
|
||||||
|
->expression('booking_variety_regncount', 'booking_variety_regncount - :count', array(':count' => 1))
|
||||||
|
->condition('vid', $previous_sid)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
foreach ($previous_variety_ids as $previous_tid => $previous_sid) {
|
foreach ($previous_variety_ids as $previous_tid => $previous_sid) {
|
||||||
if (! isset($booking_variety_ids[$previous_tid])) {
|
if (! isset($booking_variety_ids[$previous_tid])) {
|
||||||
@@ -828,7 +869,7 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //end iterate over previous variety session registrations
|
} //end iterate over previous variety session registrations
|
||||||
|
*/
|
||||||
// update the session registration information for this person
|
// update the session registration information for this person
|
||||||
$result = db_update('booking_variety_regn')
|
$result = db_update('booking_variety_regn')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
@@ -837,7 +878,7 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
|||||||
->condition('booking_person_nid', $values['nid'])
|
->condition('booking_person_nid', $values['nid'])
|
||||||
->execute();
|
->execute();
|
||||||
watchdog('booking', "Updated variety session registration for person ID !nid", array('!nid' => $values['nid']));
|
watchdog('booking', "Updated variety session registration for person ID !nid", array('!nid' => $values['nid']));
|
||||||
*/
|
|
||||||
$form_state['redirect'] = $redirect_path;
|
$form_state['redirect'] = $redirect_path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user