You are here

og_activity.module in Heartbeat 6.4

Same filename and directory in other branches
  1. 6.3 modules/og_activity/og_activity.module

File

modules/og_activity/og_activity.module
View source
<?php

// by Jochen Stals - Menhir - www.menhir.be
define('HEARTBEAT_OG_PUBLIC', 10);

/**
 *  Implementation of hook_form_alter().
 */
function og_activity_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'og_create_admin_confirm') {
    $form['#submit'][] = 'og_activity_create_admin_confirm';
  }
  if (in_array($form_id, array(
    'heartbeat_messages_edit',
    'heartbeat_messages_add',
  ))) {
    $form['perms']['#options'] += array(
      HEARTBEAT_OG_PUBLIC => t('Everyone if group is set to public'),
    );
  }
}

/**
 * Implementation of hook_heartbeat_message_info()
 */
function og_activity_heartbeat_message_info() {
  $info = array(
    'og_activity_0' => array(
      'message' => '!user is now a coadministrator of !group.',
      'message_concat' => '%user% is now a coadministrator of !group.',
      'message_id' => 'og_become_co_admin',
      'concat_args' => array(
        'type' => 'summary',
        'group_by' => 'node',
        'group_target' => 'user',
        'group_by_target' => '',
        'group_num_max' => '2',
        'merge_separator' => ', ',
        'merge_end_separator' => ' and ',
        'roles' => array(
          0 => '0',
          1 => '0',
          2 => '0',
          3 => '0',
          4 => '0',
        ),
      ),
      'description' => 'Become a coadministrator of a group',
      'perms' => '1',
      'custom' => '1',
      'variables' => array(),
    ),
  );
  return $info;
}

/**
 * Implementation of hook_heartbeat_register_access_types()
 */
function og_activity_heartbeat_register_access_types() {
  return array(
    0 => array(
      'name' => 'Organic group activity',
      'class' => 'OgHeartbeat',
      'path' => 'ogheartbeat.inc',
      'module' => 'og_activity',
    ),
    1 => array(
      'name' => 'Organic groups activity',
      'class' => 'GroupsActivity',
      'path' => 'groupsactivity.inc',
      'module' => 'og_activity',
    ),
    2 => array(
      'name' => 'Organic group member activity',
      'class' => 'MembersActivity',
      'path' => 'membersactivity.inc',
      'module' => 'og_activity',
    ),
  );
}

/**
 * Implementation of hook_token_list().
 */
function og_activity_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['ogname-title-link'] = t('title of top group with a link to it.');
    return $tokens;
  }
}

/**
 * Implementation of hook_token_values().
 */
function og_activity_token_values($type, $object = NULL, $options = array()) {
  switch ($type) {
    case 'node':
      if (!empty($object->og_groups) && is_array($object->og_groups)) {
        $gids = array_keys(array_filter($object->og_groups));
        $title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $gids[0]));
        $values['ogname-title-link'] = l(check_plain($title), 'node/' . $gids[0], array(
          'html' => TRUE,
        ));
        return $values;
      }
      break;
  }
}

/**
 * Implementation of hook_heartbeat_activity_log().
 */
function og_activity_heartbeat_activity_log($heartbeatactivity, $args) {

  // Most of the time nid is a group post and nid_target the group, sometimes nid_target left empty.
  // In some cases the nid is the group id, leaving the nid_target empty.
  $in_group = (int) db_result(db_query_range("SELECT 1 FROM {og_ancestry} WHERE (nid = %d OR group_nid = %d OR group_nid = %d)", $heartbeatactivity->nid, $heartbeatactivity->nid, $heartbeatactivity->nid_target, 0, 1));
  if ($in_group) {
    db_query("UPDATE {heartbeat_activity} SET in_group = 1 WHERE nid = %d AND nid_target = %d ", $heartbeatactivity->nid, $heartbeatactivity->nid_target);
  }
}

/**
 * Submit function to load the become og admin rule.
 */
function og_activity_create_admin_confirm($form, $form_state) {
  rules_invoke_event('og_become_co_admin', $form_state['values']['node'], $form_state['values']['account']);
}

Functions

Namesort descending Description
og_activity_create_admin_confirm Submit function to load the become og admin rule.
og_activity_form_alter Implementation of hook_form_alter().
og_activity_heartbeat_activity_log Implementation of hook_heartbeat_activity_log().
og_activity_heartbeat_message_info Implementation of hook_heartbeat_message_info()
og_activity_heartbeat_register_access_types Implementation of hook_heartbeat_register_access_types()
og_activity_token_list Implementation of hook_token_list().
og_activity_token_values Implementation of hook_token_values().

Constants