userpoints:developer
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
userpoints:developer [2024/01/10 17:52] – admin | userpoints:developer [2025/03/07 14:28] (current) – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== UserPoints API documentation | + | ====== UserPoints |
- | Introduction | + | This is an introduction to UserPoints |
- | 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 | + | UserPoints provides a way to award users points |
+ | 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 a component === | + | Unfortunately, |
- | Just insert | + | ===== Ways to Connect Software to UserPoints ===== |
+ | |||
+ | The approach is different, depending on whether | ||
+ | |||
+ | Alternatively, | ||
=== 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> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | UserPoints:: |
- | | + | |
} | } | ||
</ | </ | ||
- | function_name | + | rule_name |
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 | + | 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 | + | To give points to another |
<code php> | <code php> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | $upid = UserPoints:: |
- | | + | if ( $bupid ) UserPoints:: |
- | $bupid | + | |
- | if ( $bupid ) UserPoints:: | + | |
} | } | ||
</ | </ | ||
Line 59: | Line 59: | ||
<code php> | <code php> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | $keyreference = UserPoints:: |
- | require_once $api_UP; | + | UserPoints:: |
- | $keyreference = UserPoints:: | + | |
- | UserPoints:: | + | |
} | } | ||
</ | </ | ||
- | === Adding information | + | === Adding information |
- | To add information | + | To add information |
<code php> | <code php> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | $keyreference = UserPoints:: |
- | require_once $api_UP; | + | UserPoints:: |
- | $keyreference = UserPoints:: | + | |
- | UserPoints:: | + | |
} | } | ||
</ | </ | ||
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> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | $keyreference = UserPoints:: |
- | require_once $api_UP; | + | UserPoints:: |
- | $keyreference = UserPoints:: | + | |
- | UserPoints:: | + | |
} | } | ||
</ | </ | ||
Line 98: | Line 92: | ||
=== Get the result from a successful operation === | === Get the result from a successful operation === | ||
- | In a more advanced code, if the component routine | + | In more advanced code, if the new software |
<code php> | <code php> | ||
- | | + | |
- | if ( file_exists($api_UP)) | + | if (class_exists(UserPoints:: |
- | | + | $keyreference=UserPoints:: |
- | require_once $api_UP; | + | if (UserPoints:: |
- | $keyreference=UserPoints:: | + | |
- | if (UserPoints:: | + | |
{ | { | ||
- | [... 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 | + | === Display an additional system message |
- | you can display a specific message | + | you can display a specific message |
<code php> | <code php> | ||
- | UserPoints:: | + | |
- | string$pluginfunction, | + | if (class_exists(UserPoints:: |
- | [string$BUPIDotheruser = '' | + | |
- | [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='' | ||
+ | ); | ||
+ | } | ||
</ | </ | ||
- | Note: If the operation is a points substraction, | + | Note: If the operation is a points substraction, |
==== Step 2 - XML file creation ==== | ==== Step 2 - XML file creation ==== | ||
- | Then developers have to create an xml file to make easier the installation process in the UserPoints component. This xml file has to be utf-8 encoded | + | To complete the integration of an application with UserPoints, |
- | Administrator of the website which install a third component | + | |
- | This xml file has to be utf-8 encoded (required) but not be zipped! Just put this file at the root of frontend | + | An example of userpoints_rule.xml is the file for Remository which reads: |
+ | |||
+ | < | ||
+ | <?xml version=" | ||
+ | < | ||
+ | <component> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
=== Code list for categories : === | === Code list for categories : === | ||
Line 163: | Line 186: | ||
</ | </ | ||
- | NOTE : Optionally, you can avoid this step manually by filling all the fields in the creation of a new rule directly in the rule manager (button ' | + | === Code list for methods: === |
+ | |||
+ | You can add a < | ||
+ | |||
+ | < | ||
+ | 1 -> Only once | ||
+ | 2 -> Once a day per user | ||
+ | 3 -> Once a day for a single user on all users | ||
+ | 4 -> Whenever | ||
+ | 5 -> Once per week | ||
+ | 6 -> Once per month | ||
+ | 7 -> Once per year | ||
+ | </ | ||
- | ==== Plugin/Rule installation ==== | + | NOTE : It is possible to create new rules manually by filling all the fields in the creation of a new rule directly in the rule manager (button ' |
- | - auto-detect xml file at the root of frontend component: | ||
- | Click on the button “Auto-detect plugins” in the control panel of UserPoints after installation of third component, plugin or module. Check regularly or periodically by clicking on this button. | ||
- | ==== Using UserPoints information in a third party component ==== | + | ===== Using UserPoints information in a third party component |
You can use easily the profil informations of a user directly in a third component. | You can use easily the profil informations of a user directly in a third component. | ||
Line 433: | Line 467: | ||
* Created on 15 January 2016. | * Created on 15 January 2016. | ||
- | * Last updated on 05 April 2023. | + | * Last updated on 25 November 2024. |
userpoints/developer.1704909150.txt.gz · Last modified: 2024/01/10 17:52 by admin