Change color of username based on badge

NeoID - March 12, 2009 - 09:12
Project:User Badges
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

Would it be possible to extend this module (or code snippet), that changes the colour of the username if he/she has a certain badge?

#1

Nuno Veloso - March 13, 2009 - 14:05

Well you can do that within your theme when printing usernames. Just give it a class and then simply define which colour for which role / badge into your css file.

Cheers!

#2

NeoID - May 26, 2009 - 09:00

Thought I had found a solution some time ago, but I'm not happy with it..

Anyway, I've this function, anyone knows why the $badges->name isn't printed at all?

<?php
function phptemplate_username($object) {
return
'<span class="'. strtolower($badges['name']) .'">'.theme_username($object).'</span>';
}
?>

#3

Likeless - August 6, 2009 - 14:26
Status:active» fixed

Try this. I've not tested it, but it should add classes based on the badge id number.

<?php
function phptemplate_username($object) {
  if (
$object->uid && $object->name) {
   
$output = '<span class="';
   
$badges = user_badges_get_badges($object->uid);
    foreach (
$badges as $bid => $badge) {
     
$output .= " userbadge_$bid";
    }
   
$output .= '">' .theme_username($object). '</span>';
    return
$output;
  }
  else {
    return
theme_username($object);
  }
}
?>

#4

System Message - August 20, 2009 - 14:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.