Difference between revisions of "User Points System"

(Created page with "JomSocial user point system allows any 3rd party developer or application to easily rewards "points" to any user action. The points system does not require an activity stream ...")
(No difference)

Revision as of 18:33, 17 January 2013

JomSocial user point system allows any 3rd party developer or application to easily rewards "points" to any user action. The points system does not require an activity stream item to be created and can be awarded at any event, deemed necessary.

The site admin will have the ability to modify the exact number of point to be awarded for each action and can also completely disable it if needed.

Calling the UserPoints API in your code

If you want to give points to user, you will need to call the API to do that by inserting the codes to where you want.

include_once JPATH_ROOT.'/components/com_community/libraries/userpoints.php';
CuserPoints::assignPoint('your.action.string');


The 'your.action.string' is the rule registered in db with how many points awarded to the current logged on user.
You will need to give a unique action string to your components such as 'com_name.profile.upload.avatar'.
In some situation, where you want to give points to other user instead of the current logged on user, you can call the API in this way :

include_once JPATH_ROOT.'/components/com_community/libraries/userpoints.php';
CuserPoints::assignPoint('your.action.string', 62);


By giving the userId as the second parameter, the API will give points to the specified user.

Register action rules into database

To register all the action rules that used in your component / module / plugins, you will need to create an xml file for this. Create one xml file and named it 'jomsocial_rule.xml'. You MUST named your file exactly or else the rule registration will failed.
You MUST include this file in your installer and put this file at root level in your front-end component folder. Your xml file should look like the below one :

<version="1.0" encoding="utf-8"?>
     <your component name>
	      <your action name>
	      <your description about the action>
	      <your unique action string.>
	      <whether to publish the rule or not. true or false>
	      <points given to this action.>
	      <user access level. For registered user, use 1.>


For example

<version="1.0" encoding="utf-8"?>
   <com_community>
     <Add Application>
	      <Give points when registered user add new application.>
	      <com_community.application.add>
	      <true>
	      <1>
	      <1>       
         <Remove Application>
	      <Deduct points when registered user remove application.>
	      <com_community.application.remove>
	      <true>
	      <0>
	      <1>


For the access_level, these are the value you should use.
   0 => Public
   1 => Registered
   2 => Special

Assuming you have included this ' jomsocial_rule.xml' into your installer.

Install your component through JOOMLA backend and your component folder 'com_xxx' should created in 'JOOMLA\components\com_xxx' and this xml should stay in 'JOOMLA\components\com_xxx\ jomsocial_rule.xml'.

Now go to your Jomsocial backend and you should see the icon 'UserPoints'.
Go into UserPoints and you should see screen below with some default / existing action rule displayed.