function activity_block in Activity 5.3
Same name and namespace in other branches
- 5.4 activity.module \activity_block()
- 5 activity.module \activity_block()
- 5.2 activity.module \activity_block()
- 6 activity.module \activity_block()
create a block for display
@returns block HTML
TODO: Add "more activity" link to blocks which goes to activity table page.
Parameters
op:
delta:
File
- ./
activity.module, line 396 - Activity module: Allow users to see their friends' activity on the site.
Code
function activity_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
if ($op == 'list') {
$block['my']['info'] = t("Activity: Mine: show the current user's activity.");
$block['all']['info'] = t("Activity: All: show all recent activity");
return $block;
}
elseif ($op == '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;
}
elseif ($op == 'save') {
variable_set('activity_block_' . $delta, $edit['items']);
}
elseif ($op == 'view') {
switch ($delta) {
case 'my':
if (user_access('view own activity')) {
// Grab the number of requested activities plus one. We use this one
// to determine whether or not to show the "more" link and only display
// the correct number of items.
$activity = activity_get_activity($user->uid, NULL, variable_get('activity_block_' . $delta, 5) + 1);
if ($count = count($activity)) {
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity/mine');
array_pop($activity);
}
$activites = array();
foreach ($activity as $item) {
$activities[] = theme('activity', activity_token_replace($item), $item);
}
return array(
'subject' => t('My activity'),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
case 'all':
if (user_access('view public activity')) {
$activity = activity_get_activity(ACTIVITY_ALL, NULL, variable_get('activity_block_' . $delta, 5) + 1);
if ($count = count($activity)) {
if ($count > variable_get('activity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity');
array_pop($activity);
}
$activites = array();
foreach ($activity as $item) {
$activities[] = theme('activity', activity_token_replace($item), $item);
}
return array(
'subject' => t('Recent activity'),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
}
}
}