You are here

function og_notifications_notifications in Organic groups 6.2

Same name and namespace in other branches
  1. 5.8 og_notifications/og_notifications.module \og_notifications_notifications()
  2. 5 og_notifications/og_notifications.module \og_notifications_notifications()
  3. 5.3 og_notifications/og_notifications.module \og_notifications_notifications()
  4. 5.7 og_notifications/og_notifications.module \og_notifications_notifications()
  5. 6 modules/og_notifications/og_notifications.module \og_notifications_notifications()

Implementation of hook_notifications().

File

modules/og_notifications/og_notifications.module, line 317
Provide notifications and messaging support for organic groups.

Code

function og_notifications_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['grouptype'] = array(
        'event_type' => 'node',
        'title' => t('Content type in group'),
        'access' => 'subscribe to content in groups',
        'page callback' => 'og_notifications_user_page',
        'user page' => 'user/%user/notifications/group',
        'fields' => array(
          'group',
          'type',
        ),
        'description' => t('Subscribe to specific content within a group.'),
      );
      return $types;
    case 'subscription fields':
      $fields['group'] = array(
        'name' => t('Group'),
        'field' => 'nid',
        'type' => 'int',
        'options callback' => 'og_notifications_groups',
        'format callback' => 'notifications_node_nid2title',
      );

      // Notifications does not allow custom callbacks for overlapping fields.
      // This is resolved via a form_alter refines the field to only displsy
      // authorised node types.
      $fields['type'] = array(
        'name' => t('Content type'),
        'field' => 'type',
        'type' => 'string',
        'options callback' => 'notifications_content_types',
      );
      return $fields;
    case 'query':
      $query = array();
      if ($arg0 == 'event' && $arg1 == 'node' && ($node = $arg2->node)) {
        if (!empty($node->og_groups)) {
          $query[]['fields']['group'] = $node->og_groups;
        }
      }
      else {
        if ($arg0 == 'user' && $arg1 == 'node') {

          // Called by notifications_autosubscribe; $arg2 holds the nid.
          $query[]['fields']['group'] = $arg2;
        }
      }
      return $query;
    case 'node options':
      return _og_notifications_node_options($arg0, $arg1);
    case 'event load':

      // Piggy-backing on notifications_content.
      break;
    case 'event types':

      // Piggy-backing on notifications_content.
      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;
  }
}