User Tools

Site Tools


userpoints:developer

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
userpoints:developer [2024/01/10 17:52] adminuserpoints:developer [2024/04/02 18:39] (current) admin
Line 1: Line 1:
-====== UserPoints API documentation ======+====== UserPoints Integrations and API ======
  
  
-Introduction UserPoints - API integration in a Third party component (advanced)+This is an introduction to UserPoints integrations with Joomla or third party extensions. It is dedicated to developers and anyone with a sufficient knowledge of the PHP language and Joomla 4/5 extension development. There is a UserPoints API which has recently been simplified.
  
-This documentation is dedicated to developers and anyone with a sufficient knowledge of the PHP language and Joomla 4/5 component development. 
 Licence: UserPoints is released under license GNU/GPL License. Author: Bernard Gilly – Adrien Roussel - Martin Brampton. This project started as AlphaUserPoints back in 2008. Licence: UserPoints is released under license GNU/GPL License. Author: Bernard Gilly – Adrien Roussel - Martin Brampton. This project started as AlphaUserPoints back in 2008.
  
-===== Plugin/Rule creation =====+===== Basic Operation of UserPoints =====
  
-A plugin creation (new rule creation for a 3rd party component) is done in 2 steps+UserPoints provides a way to award users points for specific actions on Joomla based web site. Points can also be "spent" in order to permit other actions. The actions involved are specific to whatever applications are appropriate for the site. It is possible, but not necessary, to equate points to monetary value.
  
 +The handling of points is determined by what are called **rules** in UserPoints. A rule is triggered by something happening as a result of user action. The rule determines what happens in the way of awarding or deducting points. UserPoints automatically installs some plugins and rules that support actions triggered by standard Joomla extensions. These include actions to do with content (articles) and to do with user registration.
  
-=== Step1 - API insertion in component ===+Unfortunately, for historic reasons, rules are identified by plugin name. It is often not necessary for there to be an actual plugin corresponding to the name. The term plugin name should be understood as being the rule name.
  
-Just insert the following API in the component code where needed. The best way is to make it follow user action that could give the users some points or take someFor example : in a comment system component or in a forum, just add the API after the comment or topic INSERT query in the database.+===== Ways to Connect Software to UserPoints ===== 
 + 
 +The approach is different, depending on whether the author of the software to be connected is implementing code to help the integration. If this is the case, then any rules needed for the integration can be specified by an XML file in the root of the component involved. The software then uses the API described below to interact with UserPoints. No new plugin is needed for this kind of integration. 
 + 
 +Alternatively, it may be possible to achieve integration without modifying the relevant software. If it provides plugin hooks, then plugin can be written that will be triggered by events in the third party softwareThe plugin can use the API. The administrator UI of UserPoints provides the ability to create and modify rules to manage the integration.
  
 === Basic API === === Basic API ===
  
 +The UserPoints code has been fully namespaced and will autoload when used correctly. In addition, for Joomla 3.x, UserPoints automatically installs and enables a plugin that will establish the namespacing. This is not necessary with Joomla 4+ which takes account of the namespace in the UserPoints packaging XML.
 +
 +Given the above, use of the API becomes in its simplest form:
    
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php'+    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP)+    if (class_exists(UserPoints::class) { 
-    +        UserPoints::newpoints('rule_name');
-        require_once $api_UP; UserPoints::newpoints( 'function_name' );+
     }     }
 </code> </code>
  
-function_name is the name of the rule that will be used to attribute points to the current user (if logged in). For each UserPoints integrated rule (system rules), names syntax is as follows:+rule_name is the name of the rule that will be used to attribute points to the current user (if logged in). For each UserPoints integrated rule (system rules), names syntax is as follows:
  
 example: sysplgbup_newregistered for new users points attribution example: sysplgbup_newregistered for new users points attribution
  
-It is convenient to keep the same name syntax for third party components plugin as follows: +You should select names for rules that are unlikely to conflict with other integrations.
- +
-plgbup_functionname +
- +
-Example: plgbup_newcomment or plgbup_newtopic for a comment system or forum API integration. To name a rule that would give points when adding a new topic in Kunena: plgbup_kunena_topic_create.+
  
 Keep in mind that this method only gives points to the current user logged in. This is the Basic API. Keep in mind that this method only gives points to the current user logged in. This is the Basic API.
Line 42: Line 44:
 === Attribute points to another user than the current user === === Attribute points to another user than the current user ===
  
-To give points to anothe user than the one connected, only the user id is required. To get his UserPoints (BUPID) Identity, we just need to use the getAnyUserReferreID(). This method is the one used to give points to an article author when the article is being read by someone on the site.+To give points to another user than the one connected, only the rule and user ID is required. To get his UserPoints (BUPID) Identity, we just need to use the getAnyUserReferreID(). This method is the one used to give points to an article author when the article is being read by someone on the site.
  
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php';  +    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP)+    if (class_exists(UserPoints::class) { 
-    {  +        $upid = UserPoints::getAnyUserReferreID( $userID ); 
-        require_once $api_UP; +        if ( $bupid ) UserPoints::newpoints( 'rule_name', $upid );
-        $bupid = UserPoints::getAnyUserReferreID( $userID ); +
-        if ( $bupid ) UserPoints::newpoints( 'function_name', $bupid ); +
     }     }
 </code> </code>
Line 59: Line 59:
  
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php'+    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP)+    if (class_exists(UserPoints::class) { 
-    { +        $keyreference = UserPoints::buildKeyreference('rule_name', 'item id' );   
-        require_once $api_UP;   +        UserPoints::newpoints( 'rule_name', '', $keyreference);
-        $keyreference = UserPoints::buildKeyreference('function_name', 'item id' );   +
-        UserPoints::newpoints( 'function_name', '', $keyreference);  +
     }     }
 </code> </code>
  
-=== Adding information datas ===+=== Adding information data ===
  
-To add information datas to be displayed in the action details, just add a new parameter as follows:+To add information data to be displayed in the action details, just add a new parameter as follows:
  
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php'+    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP))  +    if (class_exists(UserPoints::class) { 
-    { +        $keyreference = UserPoints::buildKeyreference('rule_name', 'item id' );   
-        require_once $api_UP;   +        UserPoints::newpoints( rule_name','', $keyreference,'information_data');
-        $keyreference = UserPoints::buildKeyreference('function_name', 'item id' );   +
-        UserPoints::newpoints( function_name','', $keyreference,'information_datas');  +
     }     }
 </code> </code>
Line 84: Line 80:
 === Using different amounts of points on the same rule === === Using different amounts of points on the same rule ===
  
-A component might also need to add or to take points for different amounts. For example, when buying goods with points. Products have different prices, a fixed amount in the rule would'nt make it. The API $randompoints parameter comes instead of the amount of points set in the rule. It can be negative in case of purchases or penalities.+A component might also need to add or to take points for different amounts. For example, when buying goods with points. Products have different prices, a fixed amount in the rule would not work. The API $randompoints parameter comes instead of the amount of points set in the rule. It can be negative in case of purchases or penalities.
  
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php'+    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP)+    if (class_exists(UserPoints::class) { 
-    { +        $keyreference = UserPoints::buildKeyreference('rule_name', 'item id' );   
-        require_once $api_UP;   +        UserPoints::newpoints( 'rule_name','', $keyreference,'',-1450);
-        $keyreference = UserPoints::buildKeyreference('function_name', 'item id' );   +
-        UserPoints::newpoints( 'function_name','', $keyreference,'',-1450);  +
     }     }
 </code> </code>
Line 98: Line 92:
 === Get the result from a successful operation === === Get the result from a successful operation ===
  
-In more advanced code, if the component routine needs to know if the operation has been successful or not, (enough amount of points for a purchase in a user account), we can add a 'feedback' parameter. It has a Boolean type value. Code example:+In more advanced code, if the new software needs to know if the operation has been successful or not, (enough amount of points for a purchase in a user account), we can add a 'feedback' parameter. It has a Boolean type value. Code example:
  
 <code php> <code php>
-    $api_UP = JPATH_SITE.'/components/com_userpoints/helper.php'+    use BlackSheepResearch\Component\UserPoints\Site\UserPoints
-    if ( file_exists($api_UP)+    if (class_exists(UserPoints::class) { 
-    { +        $keyreference=UserPoints::buildKeyreference('up_purchasewithvirtuemart', $transactionID ); 
-        require_once $api_UP; +        if (UserPoints::newpoints( 'up_purchasewithvirtuemart', '', $keyreference, 'Product reference: AM-5245', -1290, true))
-        $keyreference=UserPoints::buildKeyreference('plgbup_purchasewithvirtuemart', $transactionID ); +
-        if (UserPoints::newpoints( 'plgbup_purchasewithvirtuemart', '', $keyreference, 'Product reference: AM-5245', -1290, true))+
         {         {
-            [... code continued ...]+            [... code for successful operation ...]
         }         }
     }     }
Line 117: Line 109:
 In a customized code component, you can force and remove the constraint on a rule to the user level by adding the parameter _force = 1_. The existing rule will be available now for _guest, registered_ and _special_. In a customized code component, you can force and remove the constraint on a rule to the user level by adding the parameter _force = 1_. The existing rule will be available now for _guest, registered_ and _special_.
  
-=== Display an additional system message on frontend ===+=== Display an additional system message to the user ===
  
-you can display a specific message on frontend by adding the parameter frontmessage=”You custom message”. API full implementation+you can display a specific message to the user by adding the parameter frontmessage=”You custom message”. API full implementation
  
 <code php> <code php>
-    UserPoints::newpoints( +    use BlackSheepResearch\Component\UserPoints\Site\UserPoints; 
-        string$pluginfunction, +    if (class_exists(UserPoints::class) { 
-        [string$BUPIDotheruser = ''], +      UserPoints::newpoints( 
-        [string$keyreference = ''], +        string $pluginfunction, 
-        [string$data = ''], +        [string $BUPIDotheruser = ''], 
-        [integer$randompoints = 0], +        [string $keyreference = ''], 
-        [boolean$feedback = false], +        [string $data = ''], 
-        [integer$force=0], +        [integer $randompoints = 0], 
-        [string$frontmessage=''+        [boolean $feedback = false], 
-    );+        [integer $force=0], 
 +        [string $frontmessage=''
 +      ); 
 +    }
 </code> </code>
  
-Note: If the operation is a points substraction, the account has to have at least the same amount of points. If not, a notice warns the user that he doe'snt have enough points to complete the action (by default). You can set up general parameter in the configuration of UserPoints, in backend administrator to allows your users to have a negative account.+Note: If the operation is a points substraction, the account has to have at least the same amount of points. If not, a notice warns the user that he does not have enough points to complete the action (by default). You can set up an option in the configuration of UserPoints, as administrator to allow your users to have a negative account.
  
 ==== Step 2 - XML file creation ==== ==== Step 2 - XML file creation ====
Line 433: Line 428:
 * Created on 15 January 2016. * Created on 15 January 2016.
  
-* Last updated on 05 April 2023.+* Last updated on 7 February 2024.
  
  
  
  
userpoints/developer.1704909150.txt.gz · Last modified: 2024/01/10 17:52 by admin