From a57a6a2242a043789ce5e1a3a541ff5d2a31137f Mon Sep 17 00:00:00 2001
From: Nathan Coad
Date: Sun, 27 Apr 2014 01:00:23 +1000
Subject: [PATCH] Code to manually update studygroup sessions
---
booking.helper.inc | 2 +-
booking.module | 9 ++++
booking.reports.inc | 21 +++++---
booking.studygroups.inc | 106 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 131 insertions(+), 7 deletions(-)
diff --git a/booking.helper.inc b/booking.helper.inc
index c4f9141..a14c396 100644
--- a/booking.helper.inc
+++ b/booking.helper.inc
@@ -547,7 +547,7 @@ function _booking_amount_paid($nid, $person = NULL)
// $amount_paid = $person->booking_amount_paid;
}
- watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
+ //watchdog('booking', "Total amount already paid for this registration " . $nid . " is " . $amount_paid);
return $amount_paid;
}
diff --git a/booking.module b/booking.module
index b3bbc7a..94d322c 100644
--- a/booking.module
+++ b/booking.module
@@ -337,6 +337,15 @@ function booking_menu() {
//'type' => MENU_NORMAL_ITEM,
);
+ $items['admin/booking/%/edit-studygroup'] = array(
+ 'title' => 'Edit Study Group Allocation',
+ 'description' => 'Manually Update Study Group memberships',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('booking_studygroups_edit_form', 2),
+ 'access arguments' => array('edit study groups'),
+ 'type' => MENU_CALLBACK,
+ );
+
$items['admin/booking/studygroups/%/view/print'] = array(
'title' => 'Print Study Group',
'description' => 'Print Study Group memberships',
diff --git a/booking.reports.inc b/booking.reports.inc
index 7bc8420..9569f14 100644
--- a/booking.reports.inc
+++ b/booking.reports.inc
@@ -24,6 +24,7 @@ function booking_report_summary() {
$person_count = 0;
$welfare_count = 0;
$fullypaid_count = 0;
+ $travelform_count = 0;
$stats_attributes = array('style' => 'max-width:30%');
@@ -34,6 +35,7 @@ function booking_report_summary() {
$header = array(
array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
array('data' => t('Name'), 'field' => 'booking_lastname'),
+ array('data' => t('Edit Studygroups')),
array('data' => t('Email'), 'field' => 'booking_email'),
array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
array('data' => t('Total Payment Required')),
@@ -82,11 +84,13 @@ function booking_report_summary() {
//more detailed summary
//allow user-selectable sorting of columns as per http://www.drup-all.com/blog/table-sort-pagination-drupal-7
- $query = db_select('booking_person', 'p')
- ->fields('p')
- ->fields('pr', array('booking_price', 'booking_late_price'))
- ->condition('p.booking_event_id', $event->eid, '=');
+ $query = db_select('booking_person', 'p');
$query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
+ $query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
+ $query->condition('p.booking_event_id', $event->eid, '=')
+ ->fields('p')
+ ->fields('t')
+ ->fields('pr', array('booking_price', 'booking_late_price'));
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
$result = $table_sort->execute();
@@ -101,6 +105,7 @@ function booking_report_summary() {
l(t('!first !last', array('!first' => ucwords($person->booking_firstname), '!last' => ucwords($person->booking_lastname))),
t('node/!id/edit', array('!id' => $person->nid))
),
+ l(t('Edit'), t('admin/booking/!id/edit-studygroup', array('!id' => $person->nid))),
t('!email', array('!email' => $person->booking_email)),
t('!payment', array('!payment' => $person->booking_amount_paid)),
t('!payment', array('!payment' => $amount_owing == 0 ? $person->booking_total_pay_reqd : _booking_total_due($person))),
@@ -110,6 +115,10 @@ function booking_report_summary() {
//add up the total paid
$total_paid += $person->booking_amount_paid;
+ //travel form completed?
+ if (! empty($person->tid))
+ $travelform_count++;
+
//booking status
if ($person->booking_status == 0)
$notpaid_counter++;
@@ -162,8 +171,8 @@ function booking_report_summary() {
$output .= t("There are !bookedin registrations currently booked in, !waiting on waiting list, !notpaid haven't paid, and !notcoming are no longer coming, which comes to a total of !total people who have filled in the registration form.
",
array('!bookedin' => $bookedin_counter, '!waiting' => $waiting_counter, '!notpaid' => $notpaid_counter, '!total' => $person_count,
'!notcoming' => $notcoming_counter));
- $output .= t("There are !welfare people with special financial consideration approved. !fullypaid people have completed their payments.
",
- array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count
+ $output .= t("
There are !welfare people with special financial consideration approved. !fullypaid people have completed their payments and !travel people have filled in their travel form.
",
+ array('!welfare' => $welfare_count, '!fullypaid' => $fullypaid_count, '!travel' => $travelform_count,
));
$output .= t("Total amount paid: $!paid
", array('!paid' => $total_paid));
$output .= t("Bookings by state
");
diff --git a/booking.studygroups.inc b/booking.studygroups.inc
index f51dc5f..d6f2f6b 100644
--- a/booking.studygroups.inc
+++ b/booking.studygroups.inc
@@ -344,6 +344,112 @@ function booking_available_leadhelp_select_form_submit($form, &$form_state) {
watchdog('booking', $message);
}
+
+/**
+ * Function for manually assigning study group sessions for a person
+ */
+function booking_studygroups_edit_form($node, &$form_state, $nid) {
+ global $event;
+
+ //see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
+ $form = array ();
+ $options = array ();
+ $session_options = array();
+ $session_options[0] = '';
+
+ //verify that $nid is a number
+ if (! preg_match('/^[0-9]+$/', $nid)) {
+ drupal_set_message("Error: Invalid registration ID '" . $nid . "' supplied. Unable to edit study group sessions.", 'error', FALSE);
+ drupal_goto('admin/booking/studygroups');
+ return "";
+ }
+
+ //check that this person exists
+ $person = db_query("SELECT person.nid, person.booking_firstname, person.booking_lastname " .
+ "FROM {booking_person} person " .
+ "WHERE nid = :nid",
+ array(':nid' => $nid))
+ ->fetchObject();
+ //throw an error if they don't exist
+ if (! $person)
+ {
+ drupal_set_message("Error: Unable to find booking corresponding with registration ID '" . $nid . "'.", 'error', FALSE);
+ drupal_goto('admin/booking/studygroups');
+ return "";
+ }
+
+ $prefix = t("Manually assign/update study group sessions for !first !last. Note: Not yet functional!
", array('!first' => $person->booking_firstname, '!last' => $person->booking_lastname));
+
+ //select the groups this person is already assigned to, indexed by studygroup id
+ $person_groups_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid AND booking_node_id = :nid",
+ array(':eid' => $event->eid, ':nid' => $nid));
+ $person_groups = $person_groups_query->fetchAllAssoc('booking_studygroup_id');
+
+ //select all the study groups for this event id
+ $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
+ $studygroups = $studygroups_query->fetchAll();
+
+ //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++)
+ $session_options[$i] = $i;
+
+ //select any entries already in the mapping table
+ $group_mapping_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_eventid = :eid", array(':eid' => $event->eid));
+ $group_mapping = $group_mapping_query->fetchAllAssoc('sid');
+
+ //***form starts here***
+ $header = array(
+ 'booking_studygroup_descrip' => array('data' => t('Study Group')),
+ 'booking_current_session_id' => array('data' => t('Current Session Number')),
+ 'booking_session_id' => array('data' => t('Select Session Number')),
+ );
+
+ //create a new row for each group
+ foreach ($studygroups as $group)
+ {
+ //retrieve the current session id for this group if defined already
+ $default = empty($person_groups[$group->sid]) ? '' : $person_groups[$group->sid]->booking_session_id;
+
+ $options[] = array (
+ 'booking_studygroup_descrip' => $group->booking_studygroup_descrip,
+ 'booking_current_session_id' => $default,
+ 'booking_session_id' => array('data' => array(
+ '#type' => 'select',
+ '#options' => $session_options,
+ '#value' => $default,
+ '#name' => 'booking_assign_sessionid[' . $nid . ']',
+ )
+ ),
+ );
+ }
+
+ //so we can access the dropdown elements
+ $form['booking_assign_sessionid'] = array( '#type' => 'value', );
+
+ //generate the render array
+ $form['table'] = array (
+ '#type' => 'tableselect',
+ '#header' => $header,
+ '#options' => $options,
+ );
+ $form['submit'] = array (
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+
+ return array (
+ 'first_para' => array (
+ '#type' => 'markup',
+ '#markup' => $prefix,
+ ),
+ 'form' => $form,
+ );
+}
+
+
+
/**
* Function for defining the number of study group sessions
* Note: This is hard-coded for now in the install file