function og_notifications_user_page in Organic groups 5
Same name and namespace in other branches
- 5.8 og_notifications/og_notifications.module \og_notifications_user_page()
- 5.3 og_notifications/og_notifications.module \og_notifications_user_page()
- 5.7 og_notifications/og_notifications.module \og_notifications_user_page()
- 6.2 modules/og_notifications/og_notifications.pages.inc \og_notifications_user_page()
- 6 modules/og_notifications/og_notifications.module \og_notifications_user_page()
Menu callback: Group and grouptype subscription management form. This should ideally play nicer with notifications_user_form. However, due to issues with support for multi-field subscriptions, it is currently going about things in a roundabout manner.
Parameters
Object $account: User object of the user whose page is to be displayed.
Return value
Array $form Form array.
3 string references to 'og_notifications_user_page'
- og_notifications_menu in og_notifications/
og_notifications.module - Implementation of hook_menu_()
- og_notifications_notifications in og_notifications/
og_notifications.module - Implementation of hook_notifications().
- og_notifications_user_page_submit in og_notifications/
og_notifications.module - Process og_notifications_user_page form submission.
File
- og_notifications/
og_notifications.module, line 224 - Subscriptions to content in groups.
Code
function og_notifications_user_page($account = NULL) {
global $user;
$account = $account ? $account : $user;
if (!empty($user->og_groups)) {
$ngroups = _og_notifications_user_groups($account->uid);
$ngrouptypes = _og_notifications_user_grouptypes($account->uid);
// Tap into notifications_user_form to retrieve variables and defaults.
$group_form = notifications_user_form($account, 'group', $ngroups, $user->og_groups, array(
'type' => 'group',
'event_type' => 'node',
), array(
'title' => t('Group'),
));
// Grouptype uses multiple fields which are not addressed adequately by
// notifications_user_form.
$grouptype_form = notifications_user_form($account, 'grouptype', $ngrouptypes, variable_get('og_notifications_content_types', array()), array(
'type' => 'grouptype',
'event_type' => 'node',
), array(
'title' => t('Group Type'),
));
// TODO: Trim unnecessary items.
$form = array(
'account' => $group_form['account'],
'group_defaults' => $group_form['defaults'],
'group_current' => $group_form['current'],
'group_subscription_fields' => $group_form['subscription_fields'],
'grouptype_defaults' => $grouptype_form['defaults'],
'grouptype_current' => $grouptype_form['current'],
'grouptype_subscription_fields' => $grouptype_form['subscription_fields'],
);
$content_types = array_filter(variable_get('og_notifications_content_types', array()));
foreach ($user->og_groups as $gid => $group) {
$group_index = 'groups-' . $gid;
$types = array();
foreach ($content_types as $type => $title) {
// Check if value exists; Only enable node type subscriptions if the
// group is not already subscribed to (for all posts).
$bool = isset($ngrouptypes[$gid]) && isset($ngrouptypes[$gid][$type]);
$types[$type] = array(
'title' => $title,
'checkbox' => $bool,
'send_interval' => $bool ? $ngrouptypes[$gid][$type]->send_interval : $grouptype_form['defaults']['#value']['send_interval'],
'send_method' => $bool ? $ngrouptypes[$gid][$type]->send_method : $grouptype_form['defaults']['#value']['send_method'],
);
}
$all = array(
'all' => array(
'title' => t('All'),
'checkbox' => isset($ngroups[$gid]),
'send_interval' => isset($ngroups[$gid]) ? $ngroups[$gid]->send_interval : $group_form['defaults']['#value']['send_interval'],
'send_method' => $ngroups[$gid]->send_method,
),
);
$types = $all + $types;
$form[$group_index] = array(
'#type' => 'fieldset',
'#title' => check_plain($group['title']),
'#collapsible' => TRUE,
'#collapsed' => !isset($ngroups[$gid]) && empty($ngrouptypes[$gid]),
);
// Reuse theme function.
$form[$group_index]['subscriptions'] = array(
'#tree' => TRUE,
'#parents' => array(
'groups',
$gid,
),
'#theme' => 'notifications_form_table',
'#header' => array(
theme('table_select_header_cell'),
t('Type'),
t('Send interval'),
t('Send method'),
),
);
foreach ($types as $key => $value) {
$form[$group_index]['subscriptions']['checkbox'][$key] = array(
'#type' => 'checkbox',
'#default_value' => $value['checkbox'],
);
$form[$group_index]['subscriptions']['title'][$key] = array(
'#value' => t('%type posts in this group', array(
'%type' => $value['title'],
)),
);
$form[$group_index]['subscriptions']['send_interval'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_intervals(),
'#default_value' => $value['send_interval'],
);
$form[$group_index]['subscriptions']['send_method'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_methods(),
'#default_value' => $value['send_method'],
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
else {
drupal_set_message(t('There are no active group subscriptions available.'));
}
return $form;
}