'admin/notifications/settings/group', 'title' => t('Group Subscriptions'), 'type' => MENU_LOCAL_TASK, 'callback' => 'drupal_get_form', 'callback arguments' => array('notifications_group_settings_form'), ); } else { if ($user->uid && arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'notifications' && ($user->uid == arg(1) || user_access('administer notifications'))) { $account = ($user->uid == arg(1)) ? $user : user_load(array('uid' => arg(1))); $items[] = array( 'path' => 'user/'. $account->uid .'/notifications/group', 'type' => MENU_LOCAL_TASK, 'access' => user_access('subscribe to content'), 'title' => t('Groups'), 'callback' => 'notifications_group_user_page', 'callback arguments' => array($account), 'weight' => 10, ); } } return $items; } /** * Implementation of hook_perm() */ function notifications_group_perm() { return array('subscribe to content in groups'); } /** * Admin settings form */ function notifications_group_settings_form() { // General content settings $select = array(); $nodetypes = node_get_types(); foreach ($nodetypes as $ntype => $nname) { $select[$ntype] = $nname->name; } $form['notifications_group_content_types'] = array( '#type' => 'checkboxes', '#title' => t('Allowed content types'), '#default_value' => variable_get('notifications_group_content_types', array()), '#options' => $select, '#description' => t('Select specific content types which should be allowed for group subscriptions.'), '#multiple' => TRUE, ); $form['notifications_group_link_teaser'] = array( '#type' => 'checkbox', '#title' => t('Show subscribe link with teaser'), '#default_value' => variable_get('notifications_grouplink_teaser', 1), '#description' => t('Uncheck to show link only in group view.'), ); return system_settings_form($form); } /** * Implementation of hook_notifications(). */ function notifications_group_notifications($op, &$arg0, $arg1 = NULL, $arg2 = NULL) { switch ($op) { case 'names': $subs = &$arg0; if ($subs->event_type == 'node') { if (!empty($subs->fields['group']) && ($group = node_load($subs->fields['group']))) { $subs->names['group'] = t('Group: %name', array('%name' => $group->title)); } } break; case 'subscription types': $types['group'] = array( 'event_type' => 'node', 'title' => t('Groups'), 'access' => 'subscribe to content in groups', 'page' => 'notifications_group_user_page', 'fields' => array('group'), ); $types['grouptype'] = array( 'event_type' => 'node', 'title' => t('Content type in group'), 'access' => 'subscribe to content in groups', 'fields' => array('group', 'type'), ); return $types; case 'query': // $arg0 = 'event' and $arg1 = 'node' and $event = $arg2 // $arg0 = 'user' and $arg1 = 'noe' and $node = $arg2 if ($arg0 == 'event' && $arg1 == 'node' && ($node = $arg2->node) || $arg0 == 'user' && $arg1 == 'node' && ($node = $arg2)) { $query = array(); if ($node->og_groups) { $query[] = array( 'join' => "LEFT JOIN {og_ancestry} og ON f.field = 'group' AND f.value = og.group_nid", 'where' => 'og.nid = %d', 'args' => array($node->nid), ); } if ($arg0 == 'user' && og_is_group_type($node->type)) { $query[]['fields']['group'] = $node->nid; } return $query; } break; case 'node options': return _notifications_group_node_options($arg0, $arg1); case 'event load': // $arg0 is event // Nothing to load here, the user may be subscribed through one of many parent groups break; case 'event types': // Event types for this are defined in notifications_content module break; case 'access': $type = $arg0; $account = &$arg1; $object = &$arg2; if ($type == 'subscription' && !empty($object->fields['group'])) { if (($group = node_load($object->fields['group'])) && og_is_group_type($group->type) && notifications_content_node_allow($account, $group)) { return array(TRUE); } else { return array(FALSE); } } break; } } /** * Options to display for node subscriptions */ function _notifications_group_node_options($account, $node) { // If node is a group type if (og_is_group_type($node->type)) { $options[] = array( 'name' => t('To all posts in this group'), 'type' => 'group', 'fields' => array('group' => $node->nid), ); foreach (array_filter(variable_get('notifications_group_content_types', array())) as $type) { $options[] = array( 'name' => t('To %type posts in this group', array('%type' => node_get_types('name', $type))), 'type' => 'grouptype', 'fields' => array('group' => $node->nid, 'type' => $type), ); } } // If node is part of a group user may be subscribed to the node through one of the groups if ($node->og_groups) { foreach ($node->og_groups as $index => $gid) { // Content type $options[] = array( 'name' => t('To posts in group %name', array('%name' => $node->og_groups_names[$index])), 'type' => 'group', 'fields' => array('group' => $gid), ); $options[] = array( 'name' => t('To %type posts in this group', array('%type' => node_get_types('name', $node->type))), 'type' => 'grouptype', 'fields' => array('group' => $gid, 'type' => $node->type), ); } } return $options; } /** * Menu callback. User subscriptions to groups. */ function notifications_group_user_page($account = NULL) { global $user; $account = $account ? $account : $user; // Query for group subscriptions. // @ TO DO Retrieve also grouptype subscriptions $query = "SELECT s.*, f.value AS nid, n.type AS node_type, n.title FROM {notifications} s INNER JOIN {notifications_fields} f ON s.sid = f.sid LEFT JOIN {node} n ON f.value = n.nid WHERE s.uid = %d AND s.type = 'group' AND s.conditions = 1 AND f.field = 'group' ORDER BY node_type, n.title"; $results = db_query($query, $account->uid); $subscriptions = $list = array(); while ($sub = db_fetch_object($results)) { $subscriptions[$sub->nid] = $sub; $list[$sub->nid] = $sub->title; } if (!$subscriptions) { $output = t('There are no active group subscriptions.'); } else { $defaults = array('type' => 'group', 'event_type' => 'node'); $options = array('title' => t('Group')); $output = drupal_get_form('notifications_user_form', $account, 'group', $subscriptions, $list, $defaults, $options); } return $output; }