diff --git a/booking.admin.inc b/booking.admin.inc index aae3fdc..1b8f577 100644 --- a/booking.admin.inc +++ b/booking.admin.inc @@ -4,8 +4,7 @@ * The administration menu implementations for the booking module configuration pages */ -function booking_admin() -{ +function booking_admin() { $form = array(); //regenerate all our menu hooks when loading this form @@ -239,7 +238,13 @@ function booking_admin() '#options' => array(0 => t('No'), t('Yes')), '#default_value' => variable_get('booking_friendly_csv_groupnames', 0), ); - + $form['features']['booking_studygroup_csv_ages'] = array( + '#type' => 'radios', + '#title' => t('Include ages in study group CSV export?'), + '#description' => t('Select whether to inclde ages for attendees when exporting study groups to CSV.'), + '#options' => array(0 => t('No'), t('Yes')), + '#default_value' => variable_get('booking_studygroup_csv_ages', 0), + ); $form['misc'] = array( '#type' => 'fieldset', '#title' => 'Configuration Options' @@ -564,7 +569,7 @@ $form['management']['booking_import_include_fields_dynamic'] = array( //return system_settings_form($form); //make sure we update our custom sql view every time we change something on the admin page $form = system_settings_form($form); - $form['#submit'][] = '_booking_node_create_mysqlview'; + //$form['#submit'][] = '_booking_node_create_mysqlview'; return $form; } diff --git a/booking.constants.inc b/booking.constants.inc index 6d46a6a..14b3d67 100644 --- a/booking.constants.inc +++ b/booking.constants.inc @@ -108,18 +108,20 @@ function _get_tshirt_options() { * @param $input integer containing role id * @return string for corresponding role */ -function _booking_studygroup_role_lookup($input = NULL) -{ +function _booking_studygroup_role_lookup($input = NULL) { $role = array(); $role[] = t('No Role'); $role[] = t('Leader'); $role[] = t('Helper'); $role[] = t('Reserve Leader'); - - if ($input != NULL) + $role[] = t('Reserve Helper'); + + if ($input != NULL) { return $role[$input]; - else + } + else { return $role; + } } /** diff --git a/booking.css b/booking.css index 6507348..48f20e8 100644 --- a/booking.css +++ b/booking.css @@ -1,15 +1,32 @@ #leader-row {background: #6495ED;} #helper-row {background: #9dd781;} #reserveleader-row {background: #d4dc5c;} -#new-group-row {border-top: thick double #ff0000;} -#leader-new-group-row {background: #6495ED; border-top: thick double #ff0000;} -#helper-new-group-row {background: #9dd781; border-top: thick double #ff0000;} -#reserveleader-new-group-row {background: #d4dc5c; border-top: thick double #ff0000;} +#reservehelper-row {background: #d4dc5c;} +/* +tr.leader-row.odd {background: #6495ED;} +tr.leader-row.even {background: #6495ED;} +tr.helper-row.odd {background: #9dd781;} +tr.helper-row.even {background: #9dd781;} +tr.reserveleader-row.odd {background: #d4dc5c;} +tr.reserveleader-row.even {background: #d4dc5c;} +tr.reservehelper-row.odd {background: #d4dc5c;} +tr.reservehelper-row.even {background: #d4dc5c;} +*/ +#new-group-row {border-top: thick double black;} +#leader-new-group-row {background: #6495ED; border-top: thick double black;} +#helper-new-group-row {background: #9dd781; border-top: thick double black;} +#reserveleader-new-group-row {background: #d4dc5c; border-top: thick double black;} +#reservehelper-new-group-row {background: #d4dc5c; border-top: thick double black;} + /* test for email page*/ /* tr.normal-row.odd {} */ /* tr.normal-row.even {} */ tr.welfare-row.odd {background: #c3e06c;} tr.welfare-row.even {background: #c3e06c;} +tr.flying-row.odd {background: #c3e06c;} +tr.flying-row.even {background: #e5f2c0;} +tr.accomm-row.odd {background: #ffb380;} +tr.accomm-row.even {background: #ffb380;} div#booking_email_preselection_suffix_wrapper { margin-bottom: 10px; } \ No newline at end of file diff --git a/booking.helper.inc b/booking.helper.inc index f8329bc..96e609d 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -1538,58 +1538,35 @@ function _booking_leader_helper_email_summary($node) { $found = FALSE; //display study session data if enabled - if (variable_get('booking_enable_studygroups', 0) == 1) - { + if (variable_get('booking_enable_studygroups', 0) == 1) { //look up the titles of the study groups $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid)); $studygroups = $studygroups_query->fetchAllAssoc('sid'); - - //for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) - //for ($i = 1; $i <= count($studygroups); $i++) - foreach ($studygroups as $studygroup) - { + + 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 ($studygroup->booking_is_readinggroup == 'Y') + if ($studygroup->booking_is_readinggroup == 'Y') { continue; + } //calculate the session references - //$sessionid = "session" . $i; $sessionid = "session" . $studygroup->sid; $roleid = $sessionid . "_role"; $otherperson_name = "TBA"; $otherperson_email = ""; $otherperson_phone = ""; - //check that this study group session has been defined for this attendee and that they - if (!empty($node->$sessionid) && $node->$roleid > 0) - { - /* - //make sure we only add this prefix text once, as soon as we've found a matching role - if ($found == FALSE) - { - $found = TRUE; - $rows[] = t("You have been assigned to perform the following roles for study groups:"); - } - */ - - //TODO: use a function for this. + //check that this study group session has been defined for this attendee and that they have a role to perform + if (!empty($node->$sessionid) && $node->$roleid > 0) { //if they're a leader or reserver leader, then the matching person is the helper - if ($node->$roleid == 1 || $node->$roleid == 3) - { + if ($node->$roleid == 1 || $node->$roleid == 3) { $role = "Leader"; $otherrole = "Helper"; $otherrole_id = 2; } //otherwise the matching person is the leader - else - { + else { $role = "Helper"; $otherrole = "Leader"; $otherrole_id = 1; @@ -1606,26 +1583,26 @@ function _booking_leader_helper_email_summary($node) { //watchdog('booking', "
Other person for studygroup !group and role !role result:\n@info", // array('!group' => $studygroup->sid, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true))); - - foreach ($otherperson as $other) - { + + //create the text for the token + foreach ($otherperson as $other) { $otherperson_name = $other->booking_firstname . ' ' . $other->booking_lastname; $otherperson_email = $other->booking_email; $otherperson_phone = $other->booking_mobile; } - $rows[] = t('!role for !descrip (section !id). Your !otherrole is !other. You can contact them on !phone or !email.', + $rows[] = t('!role for !descrip. Your !otherrole is !other. You can contact them on !phone or !email.', array('!role' => $role, '!id' => $studygroup->sid, '!descrip' => $studygroup->booking_studygroup_descrip, '!otherrole' => $otherrole, '!other' => $otherperson_name, '!phone' => $otherperson_phone, '!email' => $otherperson_email, )); - } } } - foreach ($rows as $key => $value) + //format the output to be used in an email + foreach ($rows as $key => $value) { $rows[$key] = wordwrap($value); - + } return implode("\n", $rows); } @@ -1657,6 +1634,43 @@ function _booking_room_email_summary($node) { return implode("\n", $rows); } +/** + * Helper function to create the mean, median, mode or average of an array + * @see http://www.phpsnips.com/45/Mean,-Median,-Mode,-Range-Of-An-Array + */ +function _booking_mmmr($array, $output = 'mean'){ + if(!is_array($array)) { + return FALSE; + } + else { + switch($output){ + case 'mean': + $count = count($array); + $sum = array_sum($array); + $total = $sum / $count; + break; + case 'median': + rsort($array); + $middle = round(count($array) / 2); + $total = $array[$middle-1]; + break; + case 'mode': + $v = array_count_values($array); + arsort($v); + foreach($v as $k => $v){$total = $k; break;} + break; + case 'range': + sort($array); + $sml = $array[0]; + rsort($array); + $lrg = $array[0]; + $total = $lrg - $sml; + break; + } + return $total; + } +} + /** * @brief Generates a Universally Unique IDentifier, version 4. * diff --git a/booking.install b/booking.install index 4e77f9b..04d8eef 100644 --- a/booking.install +++ b/booking.install @@ -585,6 +585,26 @@ function booking_update_7237() { _booking_node_create_mysqlview(); } +/** +* Add description field to room definitions +*/ +function booking_update_7238() { + $spec = array('type' => 'varchar', 'length' => '200', 'not null' => FALSE); + db_add_field('booking_room_definition', 'booking_room_description', $spec); + //update the view to match the new table definition + _booking_node_create_mysqlview(); +} + +/** +* Change room number field in room definitions to integer +*/ +function booking_update_7239() { + $spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0); + db_change_field('booking_room_definition', 'booking_room_number', 'booking_room_number', $spec); + //update the view to match the new table definition + _booking_node_create_mysqlview(); +} + /** * Implementation of hook_install(). */ @@ -916,11 +936,12 @@ function booking_schema() { 'fields' => array( 'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), 'booking_room_location_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), - 'booking_room_number' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE), + 'booking_room_number' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_singlebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_doublebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_queenbeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_ensuite' => array('type' => 'varchar', 'length' => '1', 'not null' => FALSE, 'default' => 'N'), + 'booking_room_description' => array('type' => 'varchar', 'length' => '200', 'not null' => TRUE), ), 'primary key' => array('rid'), ); diff --git a/booking.module b/booking.module index 18e4856..2404fc0 100644 --- a/booking.module +++ b/booking.module @@ -324,6 +324,14 @@ function booking_menu() { 'access arguments' => array('access reports'), 'type' => MENU_NORMAL_ITEM, ); + + $items['admin/booking/travel'] = array( + 'title' => 'Booking Travel Summary', + 'description' => "List people's travel details", + 'page callback' => 'booking_report_travel', + 'access arguments' => array('access reports'), + 'type' => MENU_NORMAL_ITEM, + ); $items['admin/booking/manual-email'] = array( 'title' => 'Manually Email People', @@ -432,11 +440,10 @@ function booking_menu() { } //configure study groups - if (variable_get('booking_enable_studygroups', 0) == 1) - { + if (variable_get('booking_enable_studygroups', 0) == 1) { //the config pages for study groups $items['admin/config/booking/studygroups'] = array( - 'title' => 'Booking Module Study Group Configuration', + 'title' => 'Booking module Study Group configuration', 'description' => 'Define and configure Study Groups for the Booking module', 'page callback' => 'booking_studygroups_admin', 'access arguments' => array('administer site configuration'), @@ -575,7 +582,7 @@ function booking_menu() { //config pages $items['admin/config/booking/rooms'] = array( 'title' => 'Booking module room definitions', - 'description' => 'View and Configure room definitions for the Event Booking module', + 'description' => 'View and configure Room Definitions for the Booking module', 'page callback' => 'drupal_get_form', 'page arguments' => array('booking_rooms_view_definitions'), 'access arguments' => array('administer site configuration'), diff --git a/booking.regn_node.inc b/booking.regn_node.inc index f7d39b0..14b71a2 100644 --- a/booking.regn_node.inc +++ b/booking.regn_node.inc @@ -762,7 +762,7 @@ function booking_view($node, $view_mode) { } $rows[] = array(t('Linked Partner:'), t($partner_name)); $rows[] = array(t('Linked Boyfriend/Girlfriend:'), t($bf_gf)); - $rows[] = array(t('Node ID to keep separate:'), $node->booking_keepseparate_id); + $rows[] = array(t('Node ID to keep separate:'), $node->booking_keepseparate_id == 0 ? 'N/A' : $node->booking_keepseparate_id); $rows[] = array(t('Home Phone Number:'), t('!home', array('!home' => $node->booking_phone))); $rows[] = array(t('Mobile Phone Number:'), t('!mob', array('!mob' => $node->booking_mobile))); $rows[] = array(t('Postal Address:'), t('!street
The combined average age at the start of the week will be !average.
The male average age will be !maleaverage.
The female average age will be !femaleaverage.
Room assignment report rows:\n@info", array('@info' => print_r( $rows, true))); - $result = array ( - '#attached' => array ( + $result = array( + '#attached' => array( 'css' => array(drupal_get_path('module', 'booking') . '/booking.css') ), - 'first_para' => array ( + 'first_para' => array( '#type' => 'markup', '#markup' => $prefix, ), - 'table' => array ( + 'table' => array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, @@ -570,8 +558,7 @@ function _booking_rooms_view_formatperson(&$attendees, $nid) { $output = "Empty"; - if ($nid > 0 && !empty($attendees[$nid])) - { + if ($nid > 0 && !empty($attendees[$nid])) { $output = $attendees[$nid]->booking_firstname . " " . $attendees[$nid]->booking_lastname; } diff --git a/booking.rooms_admin.inc b/booking.rooms_admin.inc index c7fc96b..725e247 100644 --- a/booking.rooms_admin.inc +++ b/booking.rooms_admin.inc @@ -225,18 +225,20 @@ function booking_rooms_view_definitions() { $definition_query->join('booking_room_locations', 'l', 'l.lid = r.booking_room_location_id'); $definition_query->condition('l.booking_roomlocation_active', 'Y', '=') ->fields('r') - ->fields('l'); + ->fields('l') + ->orderBy('lid')->orderBy('booking_room_number'); $definition_result = $definition_query->execute(); $location_header = array ( - 'booking_roomlocation_descrip' => t('Location Description'), - 'booking_roomlocation_active' => t('Location Active?'), + 'booking_roomlocation_descrip' => t('Location Description'), + 'booking_roomlocation_active' => t('Location Active?'), 'booking_location_edit' => t('Edit Location'), ); $definition_header = array ( - 'booking_room_location_description' => t('Room Location'), - 'booking_room_number' => t('Room Number'), + 'booking_room_location_description' => t('Room Location'), + 'booking_room_number' => t('Room Number'), + 'booking_room_description' => t('Room Description'), 'booking_room_singlebeds' => t('Number Single Beds'), 'booking_room_doublebeds' => t('Number Double Beds'), 'booking_room_queenbeds' => t('Number Queen Beds'), @@ -244,8 +246,7 @@ function booking_rooms_view_definitions() { 'booking_room_edit' => t('Edit Room'), ); - foreach($location_result as $data) - { + foreach($location_result as $data) { $location_rows[] = array ( $data->booking_roomlocation_descrip, $data->booking_roomlocation_active == 'Y' ? 'Yes' : 'No', @@ -253,12 +254,12 @@ function booking_rooms_view_definitions() { ); } - foreach($definition_result as $data) - { + foreach($definition_result as $data) { $definition_rows[] = array ( - //_booking_room_location_lookup($data->booking_room_location_id), + //_booking_room_location_lookup($data->booking_room_location_id), $data->booking_roomlocation_descrip, - $data->booking_room_number, + $data->booking_room_number, + $data->booking_room_description, $data->booking_room_singlebeds, $data->booking_room_doublebeds, $data->booking_room_queenbeds, @@ -309,33 +310,30 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id = $query = db_query("SELECT * FROM {booking_room_locations} where booking_roomlocation_active='Y'"); - foreach($query as $row) - { + foreach($query as $row) { $location_options[$row->lid] = $row->booking_roomlocation_descrip; } - if ($create == true) - { + if ($create == true) { $data = $node; $prefix = t("
Create new room defintion.
"); //watchdog('booking', 'Creating new room definition: @info', array ('@info' => var_export($node, TRUE))); } - else - { + else { //verify that $editid is a number if (! preg_match('/^[0-9]+$/', $room_id)) { drupal_set_message("Error: Invalid room ID supplied. Unable to update room definition.", 'error', FALSE); drupal_goto('admin/config/booking/rooms'); return ""; } - - //$data = $form_state['input']; - $data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id", - array(':id' => $room_id)) - ->fetchObject(); $prefix = t("Update the room defintions.
"); + + //$data = $form_state['input']; + $data = db_query("SELECT * FROM {booking_room_definition} WHERE rid = :id", array(':id' => $room_id)) + ->fetchObject(); + //add this to the form in a hidden field so we can update the right price - $form['booking_rid'] = array ( + $form['booking_rid'] = array( '#type' => 'hidden', '#value' => $room_id, ); @@ -343,15 +341,14 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id = } //create the options array for bed counts - for ($i = 0; $i <= 15; $i++) + for ($i = 0; $i <= 15; $i++) { $bedcount_options[$i] = $i; + } //define the form for adding to the room definitions - if(!isset($form_state['storage']['confirm'])) { - $form[] = array ( - 'first_heading' => array ( + 'first_heading' => array( '#type' => 'markup', '#markup' => $prefix, ), @@ -363,26 +360,33 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id = '#options' => $location_options, '#default_value' => !empty($data->booking_room_location_id) ? $data->booking_room_location_id : '' ); - $form['booking_room_number'] = array ( + $form['booking_room_number'] = array( '#type' => 'textfield', '#title' => t('Specify room number'), '#size' => 5, '#maxlength' => 10, '#default_value' => !empty($data->booking_room_number) ? $data->booking_room_number : '', ); - $form['booking_room_singlebeds'] = array ( + $form['booking_room_description'] = array( + '#type' => 'textfield', + '#title' => t('Specify room label (not mandatory)'), + '#size' => 50, + '#maxlength' => 100, + '#default_value' => !empty($data->booking_room_description) ? $data->booking_room_description : '', + ); + $form['booking_room_singlebeds'] = array( '#type' => 'select', '#title' => t('Specify number of single beds'), '#options' => $bedcount_options, '#default_value' => !empty($data->booking_room_singlebeds) ? $data->booking_room_singlebeds : '', ); - $form['booking_room_doublebeds'] = array ( + $form['booking_room_doublebeds'] = array( '#type' => 'select', '#title' => t('Specify number of double beds'), '#options' => $bedcount_options, '#default_value' => !empty($data->booking_room_doublebeds) ? $data->booking_room_doublebeds : '', ); - $form['booking_room_queenbeds'] = array ( + $form['booking_room_queenbeds'] = array( '#type' => 'select', '#title' => t('Specify number of queen beds'), '#options' => $bedcount_options, @@ -394,21 +398,18 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id = '#default_value' => (!empty($data->booking_room_ensuite) && $data->booking_room_ensuite == 'Y') ? 1 : 0, ); - if ($create == true) - { - $form['submit'] = array - ( + if ($create == true) { + $form['submit'] = array( '#type' => 'submit', '#value' => t('Add Room'), ); - } else { - $form['Update'] = array - ( + } + else { + $form['Update'] = array( '#type' => 'submit', '#value' => t('Update Room'), ); - $form['Delete'] = array - ( + $form['Delete'] = array( '#type' => 'submit', '#value' => t('Delete Room'), ); @@ -418,12 +419,22 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id = 'form' => $form, ); } - else - { + else { return confirm_form($form, "Are you sure you wish to delete room definition with id " . $room_id . "?", current_path(), NULL, "Delete Room"); } +} +/** + * Validate the form for adding room definitions + */ +function booking_rooms_definition_form_validate($form, $form_state) { + //make sure room number is numerical + $values = $form_state['input']; + + if (! is_numeric($values['booking_room_number'])) { + form_set_error('booking_room_number', t('Room number must be numeric. If you need to use a more descriptive label, please use the room label field.')); + } } /** @@ -437,30 +448,28 @@ function booking_rooms_definition_form_submit($form, &$form_state) { //watchdog('booking', "Room definition submission:\n@info", array('@info' => print_r( $form_state, true))); //if we're deleting, add the confirmation to the form if it hasn't been defined yet - if($form_state['values']['op'] == 'Delete Room' && (!isset($form_state['storage']['confirm']))) - { + if($form_state['values']['op'] == 'Delete Room' && (!isset($form_state['storage']['confirm']))) { //watchdog('booking', "
Room deletion confirmation being set:\n@info", array('@info' => print_r( $form_state, true))); $form_state['storage']['confirm'] = TRUE; $form_state['rebuild'] = TRUE; - } - elseif ($form_state['values']['op'] == 'Delete Room') - { + } + elseif ($form_state['values']['op'] == 'Delete Room') { //delete the room watchdog('booking', "Deleting room ID !rid", array('!rid' => $values['booking_rid'])); - + db_delete('booking_room_definition') ->condition('rid', $values['booking_rid']) ->execute(); - + drupal_set_message('Deleted room id ' . $values['booking_rid'] ); $form_state['redirect'] = $redirect_path; } - elseif ($form_state['values']['op'] == 'Update Room') - { + elseif ($form_state['values']['op'] == 'Update Room') { $result = db_update('booking_room_definition') ->fields(array( - 'booking_room_location_id' => $values['booking_room_location_id'], - 'booking_room_number' => $values['booking_room_number'], + 'booking_room_location_id' => $values['booking_room_location_id'], + 'booking_room_number' => $values['booking_room_number'], + 'booking_room_description' => $values['booking_room_description'], 'booking_room_singlebeds' => $values['booking_room_singlebeds'], 'booking_room_doublebeds' => $values['booking_room_doublebeds'], 'booking_room_queenbeds' => $values['booking_room_queenbeds'], @@ -475,8 +484,9 @@ function booking_rooms_definition_form_submit($form, &$form_state) { { db_insert('booking_room_definition') ->fields(array( - 'booking_room_location_id' => $values['booking_room_location_id'], - 'booking_room_number' => $values['booking_room_number'], + 'booking_room_location_id' => $values['booking_room_location_id'], + 'booking_room_number' => $values['booking_room_number'], + 'booking_room_description' => $values['booking_room_description'], 'booking_room_singlebeds' => $values['booking_room_singlebeds'], 'booking_room_doublebeds' => $values['booking_room_doublebeds'], 'booking_room_queenbeds' => $values['booking_room_queenbeds'], diff --git a/booking.rooms_allocate.inc b/booking.rooms_allocate.inc index fb3d870..1e78923 100644 --- a/booking.rooms_allocate.inc +++ b/booking.rooms_allocate.inc @@ -71,6 +71,8 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) { $header = array ( 'booking_room_location' => array('data' => t('Room Location'), 'field' => 'booking_room_location_id'), 'booking_room_number' => array('data' => t('Room Number')), + 'booking_room_description' => array('data' => t('Room Label')), + 'booking_room_ensuite' => array('data' => t('Ensuite?')), 'booking_room_singlebed' => array('data' => t('Single Bed')), 'booking_room_doublebed_p1' => array('data' => t('Double Bed Person 1')), 'booking_room_doublebed_p2' => array('data' => t('Double Bed Person 2')), @@ -97,24 +99,22 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) { $default_row = array(); $default_row['booking_room_location'] = ""; $default_row['booking_room_number'] = ""; + $default_row['booking_room_description'] = ""; + $default_row['booking_room_ensuite'] = ""; $default_row['booking_room_singlebed'] = ""; $default_row['booking_room_doublebed_p1'] = ""; $default_row['booking_room_doublebed_p2'] = ""; $default_row['booking_room_queenbed_p1'] = ""; $default_row['booking_room_queenbed_p2'] = ""; - foreach ($room_query as $data) - { + foreach ($room_query as $data) { //create an array representing the existing bed mappings for this room $existing_beds = array(); - for ($i = 1; $i <= 3; $i++) - { - foreach ($room_mapping as $mapping) - { + for ($i = 1; $i <= 3; $i++) { + foreach ($room_mapping as $mapping) { //check that the room id in the mapping table matches the room that we're currently adding to the table //and also the bed type matches the first dimension in the array - if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i) - { + if ($mapping->booking_roomid == $data->rid && $mapping->booking_room_bedtype == $i) { $existing_beds[$i][] = $mapping->booking_lastname . ', ' . $mapping->booking_firstname . ' [' . $mapping->booking_nodeid . ']'; } } @@ -125,6 +125,8 @@ function booking_rooms_allocate_form($node, &$form_state, $location_id) { //$new_row['booking_room_location'] = _booking_room_location_lookup($data->booking_room_location_id); $new_row['booking_room_location'] = $data->booking_roomlocation_descrip; $new_row['booking_room_number'] = $data->booking_room_number; + $new_row['booking_room_description'] = $data->booking_room_description; + $new_row['booking_room_ensuite'] = $data->booking_room_ensuite == 'Y' ? "Yes" : "No"; $form['rooms']['#rows'][$counter++] = array( 'data' => $new_row, 'id' => array("new-group-row"), diff --git a/booking.studygroup_leaders.inc b/booking.studygroup_leaders.inc index 2c3e915..6194b8f 100644 --- a/booking.studygroup_leaders.inc +++ b/booking.studygroup_leaders.inc @@ -2,11 +2,9 @@ /** * @file - * Functions for calculating leaders and helpers for discussion groups + * Functions for automatically calculating leaders and helpers for discussion groups */ - - /** * Function for calculating and assigning leaders and helpers to active study group sessions */ @@ -66,20 +64,16 @@ function _booking_get_next_studygroup($type, $studygroups) { $count = count($studygroups) - 1; - for ($i = 0; $i < $count; $i++) - { + for ($i = 0; $i < $count; $i++) { $group = $studygroups[$i]; $leader = $group->leader_nid; //watchdog('booking_debug', "
Study Group Element at index $i:\n@info", array('@info' => print_r( $group, true))); //watchdog('booking_debug', "
Study Group Leader NID at index $i:\n@info", array('@info' => var_dump($group))); - if ($leader == 0) - { + if ($leader == 0) { return $i; } - } - } /** @@ -101,9 +95,7 @@ function _booking_studygroups_retrieve_eligible_people() { $bookedin_result = $query->execute(); //iterate over the attendee associative array and add some fields - foreach ($bookedin_result as $person) - { - + foreach ($bookedin_result as $person) { $person->processed = 0; $person->leading = array(); $person->helping = array(); @@ -124,9 +116,7 @@ function _booking_studygroups_retrieve_eligible_people() { array(':eid' => $event->eid)); //iterate over the attendee associative array and add some fields - foreach ($result2 as $person) - { - + foreach ($result2 as $person){ $person->processed = 0; $person->leading = array(); $person->helping = array(); @@ -156,11 +146,9 @@ function _booking_studygroups_retrieve_groups() { //assume they all have the same number of sessions //$num_sessions = $studygroup->booking_num_group_sessions; - foreach ($group_mapping as $group) - { + foreach ($group_mapping as $group) { //watchdog('booking_debug', "
Study Group Element:\n@info", array('@info' => print_r( $group, true))); - for ($i = 1; $i <= 16; $i++) - { + for ($i = 1; $i <= 16; $i++) { $new_group = clone $group; $new_group->session_id = $i; @@ -235,7 +223,8 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) { 'sid' => array('data' => t('Study Group Session ID'), 'field' => 'sid'), 'booking_assign_leader' => array('data' => t('Leader')), 'booking_assign_helper' => array('data' => t('Helper')), - 'booking_assign_reserveleader' => array('data' => t('Reserve Leader')), + 'booking_assign_reserveleader' => array('data' => t('Reserve Leader')), + 'booking_assign_reservehelper' => array('data' => t('Reserve Helper')), ); //attach the custom css @@ -278,8 +267,8 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) { //create an array representing the existing leaders/helpers for this group $existing_leaders = array(); foreach ($session_members as $person) { - $existing_leaders[$person->booking_session_id][$person->booking_studygroup_role] = $person->booking_lastname - . ', ' . $person->booking_firstname . ' [' . $person->booking_node_id . ']'; + $existing_leaders[$person->booking_session_id][$person->booking_studygroup_role] = + $person->booking_lastname . ', ' . $person->booking_firstname . ' [' . $person->booking_node_id . ']'; } //create the rows for the individual sessions (instances really) of this study group @@ -318,29 +307,47 @@ function booking_studygroup_leadhelp_edit_form($node, &$form_state, $group_id) { '#autocomplete_path' => 'booking/studygroups/autocomplete', '#value' => (!empty($existing_leaders[$i][3])) ? $existing_leaders[$i][3] : '', '#attributes' => array('style' => array('width:200px')), - ); + ); + + $reservehelper = array ( + '#id' => 'booking-studygroup-reservehelper-' . $i, + '#type' => 'textfield', + '#title' => 'Name', + '#title_display' => 'invisible', + '#name' => 'booking_studygroup_reservehelper[' . $i . ']', + '#size' => 100, + '#autocomplete_path' => 'booking/studygroups/autocomplete', + '#value' => (!empty($existing_leaders[$i][4])) ? $existing_leaders[$i][4] : '', + '#attributes' => array('style' => array('width:200px')), + ); $form['studygroups'][$i] = array( 'booking-studygroup-leader' => &$leader, 'booking-studygroup-helper' => &$helper, 'booking-studygroup-reserveleader' => &$reserveleader, + 'booking-studygroup-reservehelper' => &$reservehelper, ); $new_row = array(); + //handle readings group differently if ($studygroup->booking_is_readinggroup == 'Y') { $new_row['sid'] = _booking_readinggroup_colour_lookup($i); } + //non readings groups just show the session ID else { $new_row['sid'] = $i; } $new_row['booking_studygroup_leader'] = array('data' => &$leader); $new_row['booking_studygroup_helper'] = array('data' => &$helper); $new_row['booking_studygroup_reserveleader'] = array('data' => &$reserveleader); + $new_row['booking_studygroup_reservehelper'] = array('data' => &$reservehelper); $form['studygroups']['#rows'][$i] = $new_row; - + + //clean up references unset($leader); unset($helper); unset($reserveleader); + unset($reservehelper); } //record whether this was a reading group, so we can update colours if necessary @@ -376,6 +383,7 @@ function booking_studygroup_leadhelp_edit_form_submit($form, &$form_state) { 'booking_studygroup_leader' => 1, 'booking_studygroup_helper' => 2, 'booking_studygroup_reserveleader' => 3, + 'booking_studygroup_reservehelper' => 4, ); //iterate over the different role types diff --git a/booking.studygroups.inc b/booking.studygroups.inc index db8bf37..0915fe5 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -23,6 +23,7 @@ function booking_available_leadhelp_select_form($node, &$form_state, $group_id) 1 => "leader-row", 2 => "helper-row", 3 => "reserveleader-row", + 4 => "reservehelper-row", ); //verify that $group_id is a number @@ -126,8 +127,7 @@ function booking_available_leadhelp_select_form($node, &$form_state, $group_id) $assigned_role = $role; $session_id = $group->booking_session_id; //list any role for this current group - if ($role > 0) - { + if ($role > 0) { $text = _booking_studygroup_role_lookup($role); $role_listing .= "" . $text . " group " . $group->booking_studygroup_id . " #" . $group->booking_session_id . "; "; $class = $class_array[$role]; @@ -400,8 +400,7 @@ function booking_studygroups_edit_form($node, &$form_state, $nid) { //retrieve the number of study group sessions, assume they all have the same number of sessions $num_sessions = reset($studygroups)->booking_num_group_sessions; //create the array for our html select fields - for ($i = 1; $i <= $num_sessions; $i++) - { + for ($i = 1; $i <= $num_sessions; $i++) { $session_options[$i] = $i; $readinggroup_options[$i] = _booking_readinggroup_colour_lookup($i); } @@ -500,9 +499,10 @@ function booking_studygroups_edit_form($node, &$form_state, $nid) { function booking_studygroups_edit_form_submit($form, &$form_state) { global $event; $counter = 0; - $checkboxes = $form_state['values']['table']; + //$checkboxes = $form_state['values']['table']; $studygroup_ids = $form_state['values']['booking_assign_sessionid']; $values = $form_state['input']; + $update_messages = array(); //check that $values['personid'] is a number if (! preg_match('/^[0-9]+$/', $values['personid'])) { @@ -536,7 +536,7 @@ function booking_studygroups_edit_form_submit($form, &$form_state) { } //check to see if we need to remove a study group mapping if (! empty($person_groups[$key]) && $value == 'Remove') { - watchdog('booking', "Removing an existing Study Group session id: @id from group @group.\n
@info", + $update_messages[] = t("Removing an existing Study Group session id: @id from group @group.\n
@info", array('@id' => $value, '@group' => $key, '@info' => print_r( $person_groups[$key], true))); $num_deleted = db_delete('booking_studygroup_mapping') @@ -545,7 +545,7 @@ function booking_studygroups_edit_form_submit($form, &$form_state) { } //check for an existing study group mapping to change elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id != $value) { - watchdog('booking', "Updating Study Group session from: @key to @value for id @id", + $update_messages[] = t( "Updating Study Group session from: @key to @value for id @id", array('@key' => $person_groups[$key]->booking_session_id, '@value' => $value, '@id' => $nid)); db_update('booking_studygroup_mapping') @@ -567,12 +567,12 @@ function booking_studygroups_edit_form_submit($form, &$form_state) { } //found this entry already, so no change needed elseif ((!empty($person_groups[$key])) && $person_groups[$key]->booking_session_id == $value) { - watchdog('booking', "Study Group @group session already set to @session.", + $update_messages[] = t("Study Group @group session already set to @session.", array('@group' => $key, '@session' => $value)); } //no previously defined value, so add a new entry to the mapping table else { - watchdog('booking', "Adding Study Group session id: @id for group @group.", array('@id' => $value, '@group' => $key)); + $update_messages[] = t("Adding Study Group session id: @id for group @group.", array('@id' => $value, '@group' => $key)); db_insert('booking_studygroup_mapping') ->fields(array( @@ -593,8 +593,12 @@ function booking_studygroups_edit_form_submit($form, &$form_state) { } } //end new value check } //end valid data check - } //end checkbox loop -} + } //end select dropdown loop + //output messages to watchdog + $final_message = t('Finished processing study groups for person id !id.', array('!id' => $nid)); + drupal_set_message($final_message); + watchdog('booking', "
" . $final_message . "\n" . implode("\n", $update_messages) . ""); +} //end function /** * Function for calculating who belongs to which study group @@ -1267,6 +1271,7 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { 1 => "leader-row", 2 => "helper-row", 3 => "reserveleader-row", + 4 => "reservehelper-row", ); //attach the custom css @@ -1336,11 +1341,9 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { $class = $class_array[$data->booking_studygroup_role]; //only add the lines separating groups if we're sorting by the session id - if ($sort['sql'] == "m.booking_session_id") - { + if ($sort['sql'] == "m.booking_session_id") { //Add a different id for first entry of new session, with a border-top to distinguish it - if ($last_session <> $data->booking_session_id) - { + if ($last_session <> $data->booking_session_id) { switch ($data->booking_studygroup_role) { case 1: $class = "leader-new-group-row"; @@ -1351,6 +1354,9 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { case 3: $class = "reserveleader-new-group-row"; break; + case 4: + $class = "reservehelper-new-group-row"; + break; default: $class = "new-group-row"; @@ -1360,7 +1366,7 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { $session = $group->booking_is_readinggroup == 'Y' ? _booking_readinggroup_colour_lookup($data->booking_session_id) : $data->booking_session_id; - $rows[] = array ( + $rows[] = array( 'data' => array( $session, l(t('!first !last', array('!first' => $data->booking_firstname, '!last' => $data->booking_lastname)), @@ -1382,14 +1388,6 @@ function booking_studygroups_view_form($node, &$form_state, $group_id) { } $prefix = t("