You are here

function ogactivity_block in Activity 6

Same name and namespace in other branches
  1. 5.4 contrib/ogactivity/ogactivity.module \ogactivity_block()

create a block for display

@returns block HTML

Parameters

op:

delta:

File

contrib/ogactivity/ogactivity.module, line 183

Code

function ogactivity_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;
  switch ($op) {
    case 'list':
      $block['og']['info'] = t("Activity - Groups: show activity in user's groups.");
      return $block;
      break;
    case 'configure':
      $form['items'] = array(
        '#type' => 'select',
        '#title' => t('Number of items'),
        '#default_value' => variable_get('activity_block_' . $delta, 5),
        '#options' => drupal_map_assoc(range(1, 50)),
      );
      return $form;
      break;
    case 'save':
      variable_set('activity_block_' . $delta, $edit['items']);
      break;
    case 'view':
      switch ($delta) {
        case 'og':
          $result = db_query("\nSELECT \n  DISTINCT(og.uid) \nFROM \n  {og_uid} og \nINNER JOIN \n  {og_uid} og2 ON og.nid = og2.nid AND \n  og.uid != %d AND \n  og2.uid = %d \nINNER JOIN \n  {activity_targets} at ON og.uid = at.target_uid \nINNER JOIN \n  {activity} a ON at.aid = a.aid \nWHERE \n   at.target_role = 'author'", $user->uid, $user->uid);
          while ($row = db_fetch_object($result)) {
            $users[] = $row->uid;
          }
          $activity = array();
          if ($users) {
            $activity = activity_get_activity($users, NULL, variable_get('activity_block_' . $delta, 5) + 1);
          }
          if ($count = count($activity)) {
            drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
            if ($count > variable_get('activity_block_' . $delta, 5)) {
              $more_link = theme('activity_more_link', 'activity/og');
              array_pop($activity);
            }
            $activites = array();
            foreach ($activity as $item) {
              $activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);
            }
            return array(
              'subject' => t('My groups activity'),
              'content' => theme('activity_block', $activities, $more_link),
            );
          }
          break;
      }
      break;
  }
}