Created
August 2, 2011 21:24
-
-
Save kepford/1121258 to your computer and use it in GitHub Desktop.
A module adding session selection to UC Signup module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implementation of hook_perm(). | |
*/ | |
function pre_conference_sessions_perm() { | |
return array('change pre-conference sessions', 'allow check or money order payment'); | |
} | |
/** | |
* Implements hook_form_alter(). | |
*/ | |
function pre_conference_sessions_form_alter(&$form, &$form_state, $form_id) { | |
switch ($form_id) { | |
case 'uc_signup_attendees_form': | |
// uc_signup_attendees_form_submit was being fired before our function | |
// in particular there is a drupal goto function that is preventing our | |
// submit function from ever being fired. We array_unshift() to make sure | |
// ours is fired first | |
array_unshift($form['#submit'], 'pre_conference_sessions_submit'); | |
if ($form_state['storage']['step'] == 'profiles') { | |
_get_sessions(&$form, &$form_state); | |
} | |
break; | |
case 'uc_cart_checkout_form': | |
$form['panes']['payment']['payment_method']['#default_value'] = 'credit'; | |
if (!user_access('allow check or money order payment')) { | |
unset($form['panes']['payment']['payment_method']['#options']['check']); | |
} | |
break; | |
} | |
} | |
function _get_sessions($form, &$form_state) { | |
$events = $form_state['storage']['uc_signup']['nids']; | |
// Build an array keyed on the nids of each event in the cart | |
foreach ($events as $nid => $event) { | |
foreach ($event as $key => $mail) { | |
if (user_is_logged_in() && !user_access('purchase signups for other users')) { | |
$mail = $user->mail; | |
$_SESSION['uc_signup']['nids'][$nid][0] = $mail; | |
} | |
// get session nodes for attendees to choose | |
$morning_nodes = views_get_view_result(pre_conference_sessions_am, NULL); | |
$afternoon_nodes = views_get_view_result(pre_conference_sessions_pm, NULL); | |
$morning_options = array(); | |
foreach ($morning_nodes as $node) { | |
$morning_options[$node->nid] = $node->node_title; | |
} | |
$afternoon_options = array(); | |
foreach ($afternoon_nodes as $node) { | |
$afternoon_options[$node->nid] = $node->node_title; | |
} | |
// set the pre_conf_nid so we can only show the sessions to those who are registering | |
// for the pre-conference. | |
// TODO: make a configuration settings page where this can be set in the UI instead of | |
// hard coded | |
$pre_conf_nid = 2; | |
$pre_conf_and_conf_nid = 147; | |
// only show preconference sessions to attendees registering for the pre-conference | |
if (($nid == $pre_conf_nid) || ($nid == $pre_conf_and_conf_nid)) { | |
$count++; | |
$morning_default = $_SESSION['pre_conference'][$mail]['am_session']; | |
$afternoon_default = $_SESSION['pre_conference'][$mail]['pm_session']; | |
$form[$mail]['pre_conference'] = array( | |
'#type' => 'fieldset', | |
'#title' => t('Pre Conference Sessions'), | |
'#description' => t('Please select your morning sessions.'), | |
'#collapsible' => FALSE, | |
'#collapsed' => FALSE, | |
'#tree' => TRUE, | |
); | |
$form[$mail]['pre_conference']['morning'.$count] = array( | |
'#type' => 'radios', | |
'#title' => t('Select A Pre-Conference Morning Session for this attendee'), | |
'#default_value' => $morning_default, | |
'#options' => $morning_options, | |
'#required' => TRUE, | |
'#weight' => 20, | |
); | |
$form[$mail]['pre_conference']['afternoon'.$count] = array( | |
'#type' => 'radios', | |
'#title' => t('Select Pre-Conference a Afternoon Session for this attendee'), | |
'#default_value' => $afternoon_default, | |
'#options' => $afternoon_options, | |
'#required' => TRUE, | |
'#weight' => 22, | |
); | |
// hidden fields so we can associate the sessions with a user email/account | |
$form[$mail]['pre_conference']['morning_attendee'.$count] = array( | |
'#type' => 'hidden', | |
'#value' => $mail, | |
); | |
$form[$mail]['pre_conference']['afternoon_attendee'.$count] = array( | |
'#type' => 'hidden', | |
'#value' => $mail, | |
); | |
} | |
} | |
} | |
} | |
/** | |
* Store attendee Pre-conference sessions keyed on the attendee email | |
*/ | |
function pre_conference_sessions_submit($form, &$form_state) { | |
if ($form_state['storage']['step'] == 'profiles') { | |
$count = 1; | |
if (!empty($form_state['values']['pre_conference'])) { | |
foreach ($form_state['values']['pre_conference'] as $key => $value) { | |
if ($key == 'morning_attendee' . $count) { | |
$morning_attendee = $form_state['values']['pre_conference']['morning_attendee' . $count]; | |
$_SESSION['pre_conference'][$morning_attendee]['am_session'] = $form_state['values']['pre_conference']['morning' . $count]; | |
} | |
if ($key == 'afternoon_attendee' . $count) { | |
$afternoon_attendee = $form_state['values']['pre_conference']['afternoon_attendee' . $count]; | |
$_SESSION['pre_conference'][$afternoon_attendee]['pm_session'] = $form_state['values']['pre_conference']['afternoon' . $count]; | |
$count++; | |
} | |
} | |
} | |
} | |
// stuff pre_conference Sessions in to $_Session | |
$form_state['storage']['pre_conference'] = $_SESSION['pre_conference']; | |
} | |
/** | |
* Implementation of hook_order(). | |
*/ | |
function pre_conference_sessions_order($op, &$arg1, $arg2) { | |
switch ($op) { | |
case 'submit': | |
// Loop through the attendees | |
foreach ($_SESSION['pre_conference'] as $mail => $pre_sessions) { | |
$account = user_load(array('mail'=> $mail)); | |
// save the sessions to the $edit var | |
$edit = array(); | |
$edit['pre_conference_am'] = $pre_sessions['am_session']; | |
$edit['pre_conference_pm'] = $pre_sessions['pm_session']; | |
// save existing user | |
user_save((object) array('uid' => $account->uid), $edit, null); | |
} | |
// unset attendee in $_SESSION | |
unset($_SESSION['pre_conference']); | |
break; | |
} | |
} | |
/** | |
* Implementation of hook_user(). | |
*/ | |
function pre_conference_sessions_user($op, &$edit, &$account) { | |
switch ($op) { | |
case 'form': | |
if (user_access('change pre-conference sessions')) { | |
$am_nodes = views_get_view_result(pre_conference_sessions_am, NULL); | |
$am_options = array(); | |
foreach ($am_nodes as $am_node) { | |
$am_options[$am_node->nid] = $am_node->node_title; | |
} | |
$pm_nodes = views_get_view_result(pre_conference_sessions_pm, NULL); | |
$pm_options = array(); | |
foreach ($pm_nodes as $pm_node) { | |
$pm_options[$pm_node->nid] = $pm_node->node_title; | |
} | |
$form = array(); | |
$form['pre_conference'] = array( | |
'#type' => 'fieldset', | |
'#title' => t('Pre-Conference Sessions'), | |
'#description' => t('The description appears at the top of the fieldset.'), | |
'#collapsible' => TRUE, | |
'#collapsed' => FALSE, | |
'#access' => user_access('change pre-conference sessions'), | |
); | |
$form['pre_conference']['pre_conference_pm'] = array( | |
'#type' => 'radios', | |
'#title' =>t('Select A Pre-Conference Afternoon Session for this attendee'), | |
'#options' => $pm_options, | |
'#default_value' => $edit['pre_conference_pm'], | |
); | |
$form['pre_conference']['pre_conference_am'] = array( | |
'#type' => 'radios', | |
'#title' => t('Select A Pre-Conference Morning Session for this attendee'), | |
'#options' => $am_options, | |
'#default_value' => $edit['pre_conference_am'], | |
); | |
} | |
return $form; | |
case 'categories': | |
return array(array( | |
'name' => 'pre-conference-sessions', | |
'title' => t('Pre-Conference Sessions'), | |
'weight' => 0, | |
)); | |
case 'view': | |
if (user_access('change pre-conference sessions')) { | |
$account->content['pre_conference_am'] = array( | |
'#type' => 'user_profile_item', | |
'#title' => t('AM Session'), | |
'#value' => theme('pre_conference_sessions_am', $account), | |
'#weight' => 1, | |
); | |
$account->content['pre_conference_pm'] = array( | |
'#type' => 'user_profile_item', | |
'#title' => t('PM Session'), | |
'#value' => theme('pre_conference_sessions_pm', $account), | |
'#weight' => 2, | |
); | |
} | |
break; | |
} | |
} | |
/** | |
* Implements hook_theme(). | |
*/ | |
function pre_conference_sessions_theme($existing, $type, $theme, $path) { | |
return array( | |
'pre_conference_sessions_am' => array( | |
'arguments' => array('account' => NULL) | |
), | |
'pre_conference_sessions_pm' => array( | |
'arguments' => array('account' => NULL) | |
), | |
); | |
} | |
/** | |
* Theme 'pre_conference_sessions_am' to output Pre-conference Sessions. | |
*/ | |
function theme_pre_conference_sessions_am($account) { | |
$output = node_load($account->pre_conference_am)->title; | |
return $output; | |
} | |
function theme_pre_conference_sessions_pm($account) { | |
$output = node_load($account->pre_conference_pm)->title; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment