Added confirmation to study group auto updates

This commit is contained in:
2014-06-26 23:41:58 +10:00
parent a61520b72d
commit b51f6a60d1
4 changed files with 206 additions and 147 deletions

View File

@@ -480,6 +480,65 @@ function _booking_assign_attendee_group($nid, $session_id, $gender, $age, &$atte
}
/**
* Validate there is available capacity for the specified room and bed type
* @return TRUE if there is sufficient capacity, otherwise FALSE
*/
function _booking_room_capacity_check($room_id, $room_bedtype, $room_definition_object = NULL) {
global $event;
$bed_inputs = array(
1 => 'booking_room_singlebeds',
2 => 'booking_room_doublebeds',
3 => 'booking_room_queenbeds',
);
//make sure the value exists before validating it
if (!empty($room_bedtype))
{
//if we already have the object available, don't query for it again
if ($room_definition_object == NULL)
{
$details = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :rid",
array(':rid' => $room_id))->fetchObject();
}
else
$details = $room_definition_object;
//get all person-to-room mappings relating to this room and bed type
$mappings = db_query("SELECT count(*) as num FROM {booking_room_mapping} " .
"WHERE booking_eventid = :eid AND booking_roomid = :rid AND booking_room_bedtype = :type",
array(':eid' => $event->eid, ':rid' => $room_id, ':type' => $room_bedtype))->fetchObject();
$db_field = $bed_inputs[$room_bedtype];
$max_beds = $details->$db_field;
//if the beds are dual occupency, pretend there's twice as many of them
if ($room_bedtype == 2 || $room_bedtype == 3)
{
$max_beds = $max_beds * 2;
}
//check that there is sufficient capacity to allocate another person to this room and bed type
if ($mappings->num < $max_beds)
{
watchdog('booking','Sufficient capacity is available in location !id, room !room, with bed type !type. !count beds remaining of this type',
array('!id' => $details->booking_room_location_id, '!room' => $details->booking_room_number,
'!type' => _booking_room_bedtype_lookup($room_bedtype), '!count' => $max_beds - $mappings->num));
return true;
}
else
{
watchdog('booking',"Couldn't locate sufficient capacity in location !id, room !room, with bed type !type. !count beds remaining of this type",
array('!id' => $details->booking_room_location_id, '!room' => $details->booking_room_number,
'!type' => _booking_room_bedtype_lookup($room_bedtype), '!count' => $max_beds - $mappings->num));
}
}
return false;
}
/**
* Function for cleaning up room allocations for people that have withdrawn their registration
* @param $nid - the node id for the person
@@ -994,45 +1053,6 @@ function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid,
return $form;
}
/**
* Function for generating the "lucky number" to be used on the lanyard
*/
function booking_generate_luckynumbers() {
global $event;
$i = 0;
//query for the mappings relating to $readinggroup_studygroup_id
$attendee_query = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid",
array(':eid' => $event->eid));
$attendees = $attendee_query->fetchAll();
//assuming there's less than 900 people, generate numbers within that range and shuffle the order
$numbers = range(100,999);
shuffle($numbers);
foreach ($attendees as $attendee)
{
$luckynum = $numbers[$i++];
drupal_set_message(t('Updating user !id to have lucky number !num.',
array('!id' => $attendee->nid, '!num' => $luckynum)));
//run an update query
db_update('booking_person')
->fields(array (
'booking_luckynum' => $luckynum,
))
->condition('nid', $attendee->nid)
->execute();
}
drupal_set_message(t('Finished.'));
return t("<h3>Generate Lucky Numbers</h3>");
}
/**
* Helper function to format registrations details for summary in the confirmation email