Advanced: Creating and Using Badge Groups

Was this information useful?
Thank you for your feedback.

Version 5.7 of Concrete CMS introduced the ability to mark certain groups as "Badges." These are regular groups, with a few additional qualities:

  • Badges can have a "community point" value. Applying them to a user will give the user that number of community points.
  • Since they are meant to be displayed, badges can have a public image.

In general, badges are useful if you're using Concrete to run a community website, with public user profiles.

Adding a Badge Programmatically

Adding a badge programmatically is as easy as adding a group, and setting some custom properties. In this example "10" is the file ID for the image I've uploaded for my badge.

$badge = \Group::add('Sheriff');
$badge->setBadgeOptions(10, 'The sheriff is cleaning up this town!', 100); // 100 Community points assigned when you get this badge.

Don't want a group to be a badge any longer? Clear its options:

$badge->clearBadgeOptions();

Getting a User's Badges

Getting a list of a user's badges is as simple as calling a method on the UserInfo object:

$user = \UserInfo::getByName('andrew');
$badges = $user->getUserBadges();

Getting a List of Badges

Getting all the available badges in the system is simple:

$badges = \Group::getBadges();