update delete functionality
This commit is contained in:
@@ -731,6 +731,11 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
||||
}
|
||||
watchdog('booking_debug', "<pre>Variety session IDs from edit form:\n@info</pre>", array('@info' => print_r( $booking_variety_ids, true)));
|
||||
|
||||
// Get the previous variety session IDs and compare them
|
||||
$person = db_query("SELECT * FROM {booking_person_view} WHERE nid = :nid",
|
||||
array(':nid' => $values['nid']))->fetchObject();
|
||||
$previous_variety_ids = drupal_json_decode($person->booking_variety_ids);
|
||||
|
||||
//if we're deleting, add the confirmation to the form if it hasn't been defined yet
|
||||
if($form_state['values']['op'] == 'Delete Session Registration' && (!isset($form_state['storage']['confirm']))) {
|
||||
//watchdog('booking_debug', "<pre>Variety session deletion confirmation being set:\n@info</pre>", array('@info' => print_r( $form_state, true)));
|
||||
@@ -741,17 +746,19 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
||||
//delete the variety session
|
||||
watchdog('booking', "Deleting variety session registration for person ID !nid", array('!nid' => $values['nid']));
|
||||
|
||||
//@todo - decremement regn count for this person's variety sessions
|
||||
/*
|
||||
|
||||
//use an update query for the regncount field
|
||||
//idea from https://api.drupal.org/comment/19374#comment-19374
|
||||
//decremement regn count for this person's variety sessions
|
||||
foreach ($previous_variety_ids as $previous_tid => $previous_sid) {
|
||||
watchdog('booking_debug', 'Person @nid in timeslot @tid is no longer registered for any variety sessions 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', $selected_session_id)
|
||||
->execute();
|
||||
*/
|
||||
->expression('booking_variety_regncount', 'booking_variety_regncount - :count', array(':count' => 1))
|
||||
->condition('vid', $previous_sid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
//delete this person's entry in the session registration table
|
||||
db_delete('booking_variety_regn')
|
||||
->condition('booking_person_nid', $values['nid'])
|
||||
->execute();
|
||||
@@ -760,10 +767,7 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
||||
$form_state['redirect'] = $redirect_path;
|
||||
}
|
||||
elseif ($form_state['values']['op'] == 'Update Session Registration') {
|
||||
// Get the previous variety session IDs and compare them
|
||||
$person = db_query("SELECT * FROM {booking_person_view} WHERE nid = :nid",
|
||||
array(':nid' => $values['nid']))->fetchObject();
|
||||
$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) {
|
||||
@@ -825,51 +829,6 @@ function booking_variety_regn_edit_form_submit($form, &$form_state) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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();
|
||||
}
|
||||
else {
|
||||
$new_sid = $booking_variety_ids[$previous_tid];
|
||||
watchdog('booking_debug', 'Person @nid in timeslot @tid previously registered for session id @vid but new value is @new', array(
|
||||
'@nid' => $values['nid'], '@tid' => $previous_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' => $previous_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' => $previous_tid, '@vid' => $booking_variety_ids[$previous_tid]));
|
||||
|
||||
db_update('booking_variety_sessions')
|
||||
->expression('booking_variety_regncount', 'booking_variety_regncount + :count', array(':count' => 1))
|
||||
->condition('vid', $booking_variety_ids[$previous_tid])
|
||||
->execute();
|
||||
}
|
||||
else {
|
||||
watchdog('booking_debug', 'Person @nid in timeslot @tid has not changed variety session @vid', array(
|
||||
'@nid' => $values['nid'], '@tid' => $previous_tid, '@vid' => $previous_sid));
|
||||
}
|
||||
}
|
||||
} //end iterate over previous variety session registrations
|
||||
*/
|
||||
// update the session registration information for this person
|
||||
$result = db_update('booking_variety_regn')
|
||||
->fields(array(
|
||||
|
Reference in New Issue
Block a user