Sunday, April 28, 2013

How to customize you community site badges

In my previous two posts I have shown you how to customize  level achievements of your members on your community site, but there is one more achievement your members can receive - badges.

Badges are special awards that administrators of community sites can give to those members they feel have given extra efforts in the community. Once a member receives a badge it is displayed throughout the site like this:

Badges are nothing more then items in a list that contain just one field (Badge name). Administrators can add new badges or modify existing ones in that list. The list is also called Badges and is created automatically in your community site.

For example my Badges list contains two badges:
Now lets modify their looks. Once again you should find those images that you would like to represent your badges.
For example:

Then upload them somewhere to SharePoint where you can reach them from your community site (I have uploaded them to the Site Assets library of my community site). To make the solution more generic be sure to name your images with the same name of the badge they are representing (like Professional and Expert in my case).

To make those images appear as our badges we will add some javascript and CSS styles. Open your site in SharePoint designer and add this following javascript to your page header

Be sure to match your image extension if it is different from .jpg.
Also we will override two css styles, one for the image (.ms-comm-giftedBadgeIcon) and one for the text of the badge (.ms-comm-giftedBadgeText) to make any necessary adjustments (most likely image size).

This are my styles (I have also added them to my site master):

And here is my end result:

Thursday, April 25, 2013

How to customize your achievement level representation in community site (Part 2)

In the previous part of this post I showed you how you can  customize your achievement level representation
with CSS styles. In this post we will customize it using javascript code  in a way that will allow us to display different images for each level.

First you will need 5 images for each level. For example I will be using these images

each one representing a level of achievements. Upload your images to a place where you can reach them from your community site, I'll upload them to the SiteAssets library of my community site.

Now go to your Community Reputation Settings page
(Site settings -> Communitiy Administration -> Reputation settings)  and under Achievement level representation group select that you wish to diplay your achivement levels as text.

Under the titles for levels we will enter  html tags that will represent our images like this :
  <img src="/mcs/SiteAssets/Rank1.png" alt="" />

Here you can see how my reputation settings look after i have modified them:

If we look how our achievement level is represented now we will see it is still displayed as plain text, not as image.

To display this tags we will have to add some javascript.
Again open your master page in SharePoint Designer and add this script just above </head> tag:

And under the script add this following CSS style to override the default style that comes with the text represantation:


As you can see I did this to change the height and width of the container that will hold my image so that my image is displayed entirely.

My end result looks like this:

Wednesday, April 24, 2013

How to customize your achievement level representation in community site (Part 1)

In a Community site, as member accumulates points, they reach specific levels as milestones of achievement. Those levels are represented across you site and can be displayed in two ways.

You can display them as :

Images Text

The way levels are displayed can be set through your Community Reputation Settings page
(Site settings -> Communitiy Administration -> Reputation settings) under Achievement level representation group.

We can see that you can choose only what way levels are represented and if they are represented through text, you can specify a title for each level.

But what if you want to change images that represent different levels?

I will show you two different ways to accomplish this.

In my first example I will  replace those little blue squares with an image of  a four leaf clover so when a user achieves another level he will get another clover to represent his new status.

For this I will need two images, one to represent awarded  levels and one to represent remaining levels. I will use this two:

When you create your own  images you will have to upload them somewhere on your SharePoint site where they will be reachable. I've added my images to SiteAssets library of my community site.

If we inspect default images for displaying levels we can see they are nothing more then <div> tags that have some CSS styles that makes them look like blue squares. We will  simply override those styles to represent levels with our own images.

For this we will edit our community site master page in SharePoint designer. To do this open your site in SharePoint Designer and choose Master Pages from the left navigation. If you are not sure which master page you should edit, select each file and the one that has Set as Default button in your designers ribbon greyed out is the one your site is currently using.

When you have opened your master page in designer, you just have to insert this style script above your </head> tag:

Be sure to modify the script so that you point to your images and if needed adjust your height and width. Also you can save this styles to a file and just reference that file in your master page (that would be the proper way to do this).

This is my end result:

I will show you the second way to customize your achievement level representation in part 2 of this post.

Sunday, April 21, 2013

How to change Community Reputation Settings from code

Community site is one of  the new SharePoint 2013 social features that provides your users with a forum like site where they can collaborate and share their knowledge.

If you are new to this feature and want to learn more about it I suggest you check out this site :
Overview of communities in SharePoint Server 2013 .

To me one of the most interesting components it offers is the ability to track your users engagement on the site and to assign them with reward points for their efforts.

When you create a community site you can change different settings that are connected with the way people are awarded with points and the way this points are presented to others.  You can access this settings from the "Community Tools" web part on the default start page of the community site or you can go to
Site Settings -> Community Administration. From here you can access Community Reputation Settings page.On this page you can change:
  • Member achievements point system - Amount of points users will receive for their actions
  • Achievement level points - Specify the number of points required for members to reach each achievement level.
  • Achievement level presentation - Specify whether achievement levels are represented as a series of boxes or as a textual title. you can also change the textual title for each level.
This is the way you can change this settings through administration but how to change them from code?
Well for this we will first have to look what makes a Community Site.
We can see that Community Site contains several list:
  • Badges - here you can define badges that you can award then to your members
  • Categories - categories for your discussions
  • Community Members - list with all your users that will be involved in your community
  • Discussions List - place where you actually save your discussions
Badges and Categories are pretty simple SharePoint lists and there isn't much special about them. For reputation system Community Members  and Discussions List hold the key information.

Community Members holds users that are part of the community but it also stores their reputation information in these fields:
  • Discussions - number of discussions user started
  • Replies - number of replies user made
  • Best replies - number of times users replies where marked as best 
  • Reputation Score - current score that user has
  • Badge - badge that user was awarded with 
So we see this is the place where users reputation status is stored, but where are the reputation settings? Well they are stored within your Discussions List, more specifically in its property bag.

And this is how you can access them from code:

using (SPSite site = new SPSite("http://sp2013/"))
                using (SPWeb web = site.AllWebs["community"])
                    SPList disscussion = web.Lists["Discussions List"];

                    //Get achievement point that are awarded to user based on his action.; they are returned as a string with values like this:
                    //Creating a new post;Replying to a post;Member's post or reply gets liked;Member's reply gets marked as 'Best Reply' 
                    //for example : 10;5;10;20
                    string achievementPoints = disscussion.RootFolder.GetProperty("AchievementPoints").ToString();

                    //Get the text that describes levels user can achieve; there are 5 levels; to access eac text justchange the text in the property name 
                    //for example : Level2Text, Level3Text etc.
                    string level1Text = disscussion.RootFolder.GetProperty("Level1Text").ToString();

                    // Get the numbers at which users reach another level; it is returned as string that look like this
                    // Level1Threshold;Level2Threshold;Level3Threshold;....
                    // for example : 100;1000;2000;5000;10000
                   string levelThresholds = disscussion.RootFolder.GetProperty("LevelThresholds").ToString();

                    //Get the property that tells us are the levels displayed as text or as image (blue squares)
                    // It returnes a string specifiying True or False
                   string displayAchievementAsImage = disscussion.RootFolder.GetProperty("DisplayAchievementAsImage").ToString();
You can also change their values with SetProperty method like this :

  using (SPSite site = new SPSite("http://sp2013/"))
                using (SPWeb web = site.AllWebs["community"])
                    SPList disscussion = web.Lists["Discussions List"];

                    // be sure to formt your string correctly
                    string newAchievementsPoints = "1;20;50;200";

                    disscussion.RootFolder.SetProperty("AchievementPoints", newAchievementsPoints);

                    //dont forget to update