function user_badges_block_view in User Badges 7.3
Same name and namespace in other branches
- 6.2 user_badges.module \user_badges_block_view()
- 6 user_badges.module \user_badges_block_view()
- 7 user_badges.module \user_badges_block_view()
- 7.2 user_badges.module \user_badges_block_view()
Implements hook_block_view().
File
- ./
user_badges.module, line 1369 - @brief User Badges module file
Code
function user_badges_block_view($delta = 0) {
$block = array();
switch ($delta) {
case 'current_node':
$arg2 = arg(2);
if (arg(0) == 'node' && is_numeric(arg(1)) && empty($arg2)) {
$node = menu_get_object();
// Make sure we actually got a node.
if (!$node || !is_object($node)) {
watchdog('user_badges', 'Block failed to get proper node, got: @type.', array(
'@type' => gettype($node),
), WATCHDOG_WARNING);
break;
}
if (in_array($node->type, variable_get('user_badges_current_node_types', array()))) {
$account = user_load($node->uid);
$result = isset($account->badges) ? $account->badges : array();
$images = array();
foreach ($result as $badge) {
$images[] = theme('user_badge', array(
'badge' => $badge,
'account' => $account,
));
}
$block['subject'] = t("@name's Badges", array(
'@name' => $node->name,
));
$block['content'] = theme('user_badge_group', array(
'badgeimages' => $images,
));
}
}
break;
case 'my_badges':
//This block should only display for logged in users
if (user_is_logged_in()) {
global $user;
if (!isset($user->badges_all)) {
$user = user_load($user->uid);
}
if (variable_get('user_badges_my_badges_limit', 1)) {
$result = $user->badges;
}
else {
$result = $user->badges_all;
}
$images = array();
foreach ($result as $badge) {
$images[] = theme('user_badge', array(
'badge' => $badge,
'account' => $user,
));
}
$block['subject'] = t('My Badges');
$block['content'] = theme('user_badge_group', array(
'badgeimages' => $images,
));
}
break;
case 'all_badges':
$result = user_badges_load_badges();
$items = array();
foreach ($result as $badge) {
$items[] = theme('user_badge', array(
'badge' => $badge,
)) . ' <span class="all-badges-name">' . check_plain($badge->name) . '</span>';
}
$block['content'] = theme('item_list', array(
'items' => $items,
));
break;
}
return $block;
}