function user_relationshipsactivity_block in Activity 6
Same name and namespace in other branches
- 5.4 contrib/user_relationshipsactivity/user_relationshipsactivity.module \user_relationshipsactivity_block()
Implementation of hook_block().
File
- contrib/
user_relationshipsactivity/ user_relationshipsactivity.module, line 278
Code
function user_relationshipsactivity_block($op = 'list', $delta = 0, $edit = array()) {
global $user;
switch ($op) {
case 'list':
$blocks = array();
foreach (user_relationships_types_load() as $type) {
$blocks[$type->rtid] = array(
'info' => t("Activity - User Relationships: show activity by current user's !type.", array(
'!type' => $type->plural_name,
)),
);
}
return $blocks;
break;
case 'configure':
$form['items'] = array(
'#type' => 'select',
'#title' => t('Number of activity items to display'),
'#default_value' => variable_get('user_relationshipsactivity_block_' . $delta, 5),
'#options' => drupal_map_assoc(range(1, 50)),
);
return $form;
break;
case 'save':
variable_set('user_relationshipsactivity_block_' . $delta, $edit['items']);
break;
case 'view':
$type = user_relationships_type_load($delta);
// we need to check the relationship type
$params = array(
'user' => $user->uid,
'rtid' => $delta,
);
if ($type->requires_approval) {
$params['approved'] = 1;
}
$relationships = user_relationships_load($params);
$uids = array();
foreach ($relationships as $relationship) {
if ($type->is_oneway) {
$uids[] = $relationship->requestee_id;
}
else {
// user can be requester or requestee if it isn't oneway relationship
$uids[] = $relationship->requestee_id != $user->uid ? $relationship->requestee_id : $relationship->requester_id;
}
}
if ($uids) {
$activity = activity_get_activity($uids, NULL, variable_get('user_relationshipsactivity_block_' . $delta, 5) + 1);
drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
if (count($activity) > variable_get('user_relationshipsactivity_block_' . $delta, 5)) {
$more_link = theme('activity_more_link', 'activity/' . preg_replace('/\\s/', '_', drupal_strtolower($type->plural_name)));
array_pop($activity);
}
$activities = array();
foreach ($activity as $item) {
$activities[] = theme('activity', activity_token_replace($item), $item) . activity_delete_link($item);
}
if (count($activity)) {
return array(
'subject' => t('My !name\' activity', array(
'!name' => $type->plural_name,
)),
'content' => theme('activity_block', $activities, $more_link),
);
}
}
break;
}
}