Tuning study group function
This commit is contained in:
@@ -223,12 +223,25 @@ function booking_studygroups_calculate() {
|
||||
$working_list = array();
|
||||
|
||||
//consider using a lock as per https://api.drupal.org/api/drupal/includes!lock.inc/group/lock/7
|
||||
|
||||
//select all the study groups for this event id
|
||||
$studygroups = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
||||
|
||||
//calculate the max number of attendees in a group
|
||||
$firstgroup = $studygroups[0];
|
||||
$limit = variable_get('booking_regn_limit','500');
|
||||
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions);
|
||||
|
||||
drupal_set_message(t('Fitting !num people in each group.', array('!num' => $max_people)));
|
||||
|
||||
//select all the attendees booked in
|
||||
$query = db_query("SELECT * FROM {booking_person} p left outer join {booking_leadhelp_list} l on p.nid = l.booking_node_id WHERE p.booking_event_id = :eid AND p.booking_status = 1",
|
||||
array(':eid' => $event->eid));
|
||||
$attendees = $query->fetchAllAssoc('nid');
|
||||
|
||||
//select any entries already in the mapping table
|
||||
$group_mapping = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
||||
|
||||
//iterate over the attendee associative array and add some fields
|
||||
foreach ($attendees as $person)
|
||||
{
|
||||
@@ -246,10 +259,7 @@ function booking_studygroups_calculate() {
|
||||
}
|
||||
|
||||
//watchdog('booking', "Attendee list: @info", array('@info' => var_export($attendees, TRUE)));
|
||||
|
||||
//select all the study groups for this event id
|
||||
$studygroups = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
|
||||
|
||||
|
||||
//iterate over each study group (eg Monday Tuesday Wednesday etc)
|
||||
foreach ($studygroups as $group)
|
||||
{
|
||||
@@ -391,8 +401,8 @@ function booking_studygroups_calculate() {
|
||||
}
|
||||
|
||||
//iterate over the session list
|
||||
//for ($i = 1; $i <= $group->booking_num_group_sessions; $i++)
|
||||
for ($i = 1; $i <= 16; $i++)
|
||||
for ($i = 1; $i <= $group->booking_num_group_sessions; $i++)
|
||||
//for ($i = 1; $i <= 16; $i++)
|
||||
{
|
||||
//check we have attendees left
|
||||
if (! $it->valid() )
|
||||
@@ -437,13 +447,17 @@ function booking_studygroups_calculate() {
|
||||
//iterate over the attendee list and write to the database the session they're assigned to
|
||||
//use the multi-insert query type at https://drupal.org/node/310079
|
||||
|
||||
//TODO: a check to update existing records rather than inserting new ones
|
||||
|
||||
|
||||
$query = db_insert('booking_studygroup_mapping')->fields(array('booking_eventid', 'booking_node_id',
|
||||
$insert_query = db_insert('booking_studygroup_mapping')->fields(array('booking_eventid', 'booking_node_id',
|
||||
'booking_studygroup_id', 'booking_session_id', 'booking_is_leader', 'booking_is_helper'));
|
||||
|
||||
|
||||
foreach($working_list as $person)
|
||||
{
|
||||
|
||||
//TODO: a check to update existing records rather than inserting new one
|
||||
// if already in $group_mapping then just run an update query here
|
||||
|
||||
$record = array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_node_id' => $person->nid,
|
||||
|
Reference in New Issue
Block a user