diff --git a/booking.events.inc b/booking.events.inc index 23e6aff..c213688 100644 --- a/booking.events.inc +++ b/booking.events.inc @@ -187,8 +187,6 @@ function booking_event_form($node, &$form_state, $create, $editid = 0) ); - - if ($create == true) { $form['submit'] = array @@ -241,8 +239,8 @@ function booking_event_form_submit($form, &$form_state) { { db_insert('booking_event') ->fields(array( - 'booking_eventname' => $values['booking_eventname'], - 'booking_event_active' => $values['booking_event_active'] == 1 ? 1 : 0, + 'booking_eventname' => $values['booking_eventname'], + 'booking_event_active' => $values['booking_event_active'] == 1 ? 1 : 0, 'booking_register_open' => _datetime_array_to_ts($values['booking_register_open']), 'booking_register_close' => _datetime_array_to_ts($values['booking_register_close']), 'booking_earlybird_close' => _datetime_array_to_ts($values['booking_earlybird_close']), @@ -250,7 +248,13 @@ function booking_event_form_submit($form, &$form_state) { 'booking_event_end' => _datetime_array_to_ts($values['booking_event_end']), )) - ->execute(); + ->execute(); + + //if we're making a new event and setting it active, then reset the count of study groups back to 0 + if ($values['booking_event_active'] == 1) + { + variable_set('booking_studygroup_count', 0); + } } elseif ($form_state['values']['op'] == 'Delete') { diff --git a/booking.helper.inc b/booking.helper.inc index 6b9fe6b..75eef5a 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -1399,16 +1399,17 @@ function _booking_studygroup_email_summary($node) { array(':eid' => $event->eid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); - for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) + //for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) + foreach ($studygroups as $studygroup) { //calculate the session references - $sessionid = "session" . $i; + $sessionid = "session" . $studygroup->sid; $roleid = $sessionid . "_role"; //check that this study group session has been defined for this attendee if (!empty($node->$sessionid)) { - $rows[] = t($studygroups[$i]->booking_studygroup_descrip . ": Group " . $node->$sessionid . ", " . _booking_studygroup_role_lookup($node->$roleid)); + $rows[] = t($studygroup->booking_studygroup_descrip . ": Group " . $node->$sessionid . ", " . _booking_studygroup_role_lookup($node->$roleid)); } } } @@ -1435,16 +1436,23 @@ function _booking_leader_helper_email_summary($node) { array(':eid' => $event->eid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); - for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) + //for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) + //for ($i = 1; $i <= count($studygroups); $i++) + foreach ($studygroups as $studygroup) { //don't print info about the readings groups //if ($i == variable_get('booking_readinggroup_id','7')) // continue; - if ($studygroups[$i]->booking_is_readinggroup == 'Y') - continue; + + //if ($studygroups[$i]->booking_is_readinggroup == 'Y') + // continue; + + if ($studygroup->booking_is_readinggroup == 'Y') + continue; //calculate the session references - $sessionid = "session" . $i; + //$sessionid = "session" . $i; + $sessionid = "session" . $studygroup->sid; $roleid = $sessionid . "_role"; $otherperson_name = "TBA"; $otherperson_email = ""; diff --git a/booking.regn_form.inc b/booking.regn_form.inc index 8cdf911..49a4a13 100644 --- a/booking.regn_form.inc +++ b/booking.regn_form.inc @@ -58,6 +58,7 @@ function booking_form($node, &$form_state, $inserting = FALSE) { date_default_timezone_set(date_default_timezone(FALSE)); //calculate what years to show in the date of birth field + //along with some fudge factors to handle dates partway through the year $min_dob_years = _booking_year_offset(variable_get('booking_min_dob','1970-01-01 00:00:00')) + 1; $max_dob_years = _booking_year_offset(variable_get('booking_max_dob','1970-01-01 00:00:00')) - 1; $date_year_range = "-" . $min_dob_years . ':-' . $max_dob_years; @@ -496,7 +497,7 @@ function booking_form($node, &$form_state, $inserting = FALSE) { $form['emergency']['booking_guardian_type'] = array( '#type' => 'radios', '#title' => t('Relation to you'), - '#options' => $emergency_contact_type_options, + '#options' => _booking_get_emergency_contact_types(), '#default_value' => empty($data->booking_guardian_type) ? 'parent' : $data->booking_guardian_type, '#required' => TRUE ); diff --git a/booking.regn_node.inc b/booking.regn_node.inc index 7b2e0ad..b7e3758 100644 --- a/booking.regn_node.inc +++ b/booking.regn_node.inc @@ -21,7 +21,8 @@ function booking_node_presave($node) { function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) { global $event; - $studygroup_count = variable_get('booking_studygroup_count','0'); + //$studygroup_count = variable_get('booking_studygroup_count','0'); + $studygroups = array(); $query = db_select('booking_person', 'p'); //add price info @@ -40,11 +41,26 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) //add the joins to flatten out study groups into columns if (variable_get('booking_enable_studygroups', 0) == 1) { + + //get details of the study groups defined for this event + //but when this function gets called we don't have the global $event variable populated, so do the join here ourselves + //TODO: Fix up all the other places where we stupidly hard coded study group numbers 1 to n instead of using the ids from the database (see commented out for loop below for an example) + $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} l INNER JOIN {booking_event} e ON l.booking_eventid = e.eid WHERE e.booking_event_active=1"); + $studygroups = $studygroups_query->fetchAllAssoc('sid'); + + foreach ($studygroups as $studygroup) + { + $id = $studygroup->sid; + $query->leftJoin('booking_studygroup_mapping', 's' . $id, 'p.nid = s' . $id . '.booking_node_id and s' . $id . '.booking_studygroup_id = ' . $id); + } + + /* for ($i = 1; $i <= $studygroup_count; $i++) { $query->leftJoin('booking_studygroup_mapping', 's' . $i, 'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i); } + */ } //filter the results either by specific nodes if passed as a parameter or by all nodes matching the event id @@ -72,6 +88,14 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) //now add the study group fields if applicable if (variable_get('booking_enable_studygroups', 0) == 1) { + + foreach ($studygroups as $studygroup) + { + $id = $studygroup->sid; + $query->addField('s' . $id, 'booking_session_id', 'session' . $id); + $query->addField('s' . $id, 'booking_studygroup_role', 'session' . $id . '_role'); + } + /* for ($i = 1; $i <= $studygroup_count; $i++) { //$label = "Group_" . $studygroups[$i]->booking_studygroup_descrip; @@ -82,6 +106,7 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE) //$query->addField('s' . $i, 'booking_is_reserveleader', 'session' . $i . '_reserveleader'); //$query->addField('s' . $i, 'booking_is_helper', 'session' . $i . '_helper'); } + */ } //get the query result as either an associative array @@ -802,6 +827,7 @@ function booking_view($node, $view_mode) { $studygroup_heading = t("

Study Groups

!link

", array('!link' => l(t('Edit Groups'), t('admin/booking/!id/edit-studygroup-membership', array('!id' => $node->nid))) )); + $group_rows = array(); //look up the titles of the study groups $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", @@ -810,6 +836,17 @@ function booking_view($node, $view_mode) { //watchdog('booking', "
Displaying node studygroups query output:\n@info
", array('@info' => print_r( $studygroups, true))); + foreach ($studygroups as $studygroup) + { + //calculate the session references + $sessionid = "session" . $studygroup->sid; + $roleid = $sessionid . "_role"; + + $group_rows[] = array(t('' . $studygroup->booking_studygroup_descrip . ' group number'), $node->$sessionid); + $group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid)); + } + + /* for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) { //calculate the session references @@ -819,16 +856,23 @@ function booking_view($node, $view_mode) { $group_rows[] = array(t('' . $studygroups[$i]->booking_studygroup_descrip . ' group number'), $node->$sessionid); $group_rows[] = array(t('Role'), _booking_studygroup_role_lookup($node->$roleid)); } + */ - $node->content['group-heading'] = array( - '#markup' => $studygroup_heading, - '#weight' => 8, - ); + //only add to the render array if there were some study groups found + if (count($group_rows) > 0) + { + $node->content['group-heading'] = array( + '#markup' => $studygroup_heading, + '#weight' => 8, + ); - $node->content['group-details'] = array( - '#markup' => theme('table', array('header' => $header, 'rows' => $group_rows)), - '#weight' => 9, - ); + $node->content['group-details'] = array( + '#markup' => theme('table', array('header' => $header, 'rows' => $group_rows)), + '#weight' => 9, + ); + } + + } $node->content['details'] = array(