function og_notifications_user_page_submit in Organic groups 6
Same name and namespace in other branches
- 5.8 og_notifications/og_notifications.module \og_notifications_user_page_submit()
- 5 og_notifications/og_notifications.module \og_notifications_user_page_submit()
- 5.7 og_notifications/og_notifications.module \og_notifications_user_page_submit()
Process og_notifications_user_page form submission.
@todo Decide on whether to allow contenttype and "all" subscriptions for the same group.
File
- modules/
og_notifications/ og_notifications.module, line 508 - Provide notifications and messaging support for organic groups.
Code
function og_notifications_user_page_submit($form, &$form_state) {
$groups = $grouptypes = array();
$form_values = $form_state['values'];
$current = $form_values['grouptype_current'];
foreach ($form_values['groups'] as $gid => $values) {
$groups['checkbox'][$gid] = $values['checkbox']['all'];
$groups['send_interval'][$gid] = $values['send_interval']['all'];
$groups['send_method'][$gid] = $values['send_method']['all'];
unset($form_values['groups'][$gid]['checkbox']['all'], $form_values['groups'][$gid]['send_interval']['all'], $form_values['groups'][$gid]['send_method']['all']);
// Save grouptype subscriptions directly as notifications_user_form_submit
// does not handle multiple-field notifications very well.
foreach ($form_values['groups'][$gid]['checkbox'] as $type => $check) {
$subscription = NULL;
if ($check == 1) {
if (!isset($current[$gid]) || !isset($current[$gid][$type])) {
$subscription = $form_values['grouptype_defaults'] + array(
'uid' => $form_values['account']->uid,
);
}
elseif ($current[$gid][$type]->send_interval != $values['send_interval'][$type] || $current[$gid][$type]->send_method != $values['send_method'][$type]) {
$subscription = (array) $current[$gid][$type];
}
if ($subscription) {
$subscription['send_interval'] = $values['send_interval'][$type];
$subscription['send_method'] = $values['send_method'][$type];
// String cast due to notifications requiring it as the value field is
// a varchar.
$subscription['fields'] = array(
'group' => (string) $gid,
'type' => $type,
);
notifications_save_subscription($subscription);
}
}
elseif (isset($current[$gid]) && isset($current[$gid][$type])) {
notifications_delete_subscription($current[$gid][$type]->sid);
}
}
}
// Save group changes.
$group_submit['values'] = array(
'account' => $form_values['account'],
'current' => $form_values['group_current'],
'defaults' => $form_values['group_defaults'],
'subscription_fields' => $form_values['group_subscription_fields'],
'subscriptions' => $groups,
);
notifications_user_form_submit('og_notifications_user_page', $group_submit);
}