betauserpoints:developer
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
betauserpoints:developer [2023/04/07 07:04] – admin | betauserpoints:developer [2023/04/07 09:32] (current) – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | --- // | + | ====== BetaUserPoints API documentation ====== |
- | Introduction BetaUserPoints - API integration in a Third party component (advanced) | + | |
- | + | Introduction BetaUserPoints - API integration in a Third party component (advanced) | |
- | This documentation is priorly | + | |
- | + | This documentation is dedicated to developers and anyone with a sufficient knowledge of the PHP language and Joomla 4 component development. | |
- | Licence: BetaUserPoints is released under license GNU/GPL License. Author: Bernard Gilly – Adrien Roussel - Martin Brampton. This project started as AlphaUserPoints back in 2008. | + | Licence: BetaUserPoints 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 ===== | ===== Plugin/Rule creation ===== | ||
- | Plugin | + | A plugin |
- | + | ||
=== Step1 - API insertion in a component === | === Step1 - API insertion in a component === | ||
- | Just insert the following API in the component code where needed. The best is to make it follow a user action that could give the users some points or take some. For example : in a comment system component or in a forum, just add the API after the comment or topic INSERT query in the database. | + | Just insert the following API in the component code where needed. The best way is to make it follow a user action that could give the users some points or take some. For example : in a comment system component or in a forum, just add the API after the comment or topic INSERT query in the database. |
=== Basic API === | === Basic API === | ||
+ | |||
<code php> | <code php> | ||
- | $api_AUP | + | |
- | if ( file_exists($api_AUP)) | + | if ( file_exists($api_BUP)) |
- | { | + | { |
- | require_once $api_AUP; | + | require_once $api_BUP; BetaUserPointsHelper:: |
- | | + | } |
- | } | + | |
</ | </ | ||
- | function\_name | + | function_name |
- | + | ||
- | example: | + | example: |
- | + | ||
- | It is convenient to keep the same name syntax for third party components plugin as follows: | + | It is convenient to keep the same name syntax for third party components plugin as follows: |
- | + | ||
- | plgaup\_functionname | + | plgbup_functionname |
- | + | ||
- | Example: | + | Example: |
- | + | ||
- | 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. |
- | + | ||
=== 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 BetaUserPoints (AUPID) 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 anothe user than the one connected, only the user id is required. To get his BetaUserPoints (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. |
- | + | ||
- | `$api_AUP = JPATH_SITE.'/ | + | |
- | === Prevent from attributing points more than once for the same action === | + | <code php> |
+ | $api_BUP | ||
+ | if ( file_exists($api_BUP)) | ||
+ | { | ||
+ | require_once $api_BUP; | ||
+ | $bupid | ||
+ | if ( $bupid ) BetaUserPointsHelper:: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Avoid attributing points more than once for the same action === | ||
+ | |||
+ | To avoid a user getting points many times for something already done, we can add a reference key. When calling the BetaUserPointsHelper:: | ||
+ | |||
+ | <code php> | ||
+ | $api_BUP = JPATH_SITE.'/ | ||
+ | if ( file_exists($api_BUP)) | ||
+ | { | ||
+ | require_once $api_BUP; | ||
+ | $keyreference = BetaUserPointsHelper:: | ||
+ | BetaUserPointsHelper:: | ||
+ | } | ||
+ | </ | ||
- | To avoid that a user would get points many times for something allready done, we can add a reference key. When calling the BetaUserPointsHelper:: | ||
- | | ||
- | `$api_AUP = JPATH_SITE.'/ | ||
- | | ||
- | | ||
=== Adding information datas === | === Adding information datas === | ||
- | To add information datas to be displayed in the action details, just add a new parameter as follows: | + | To add information datas to be displayed in the action details, just add a new parameter as follows: |
- | + | ||
- | `$api_AUP | + | <code php> |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
=== 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' | + | 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' |
- | + | ||
- | `$api_AUP = JPATH_SITE.'/ | + | |
- | === Get the result from a successfull operation === | + | <code php> |
+ | $api_BUP | ||
+ | if ( file_exists($api_BUP)) | ||
+ | { | ||
+ | require_once $api_BUP; | ||
+ | $keyreference | ||
+ | BetaUserPointsHelper:: | ||
+ | } | ||
+ | </ | ||
- | In a more advanced code, if the component routine needs to know if the operation has been successfull | + | === Get the result from a successful operation === |
- | + | ||
- | `$api_AUP | + | In a more advanced code, if the component routine needs to know if the operation has been successful |
+ | |||
+ | <code php> | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
=== Remove the constraint on the type of user === | === Remove the constraint on the type of user === | ||
- | 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, | + | 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, |
=== Display an additional system message on frontend === | === Display an additional system message on frontend === | ||
- | 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 on frontend by adding the parameter frontmessage=”You custom message”. API full implementation |
- | + | ||
- | `BetaUserPointsHelper:: | + | <code php> |
- | + | | |
- | 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 BetaUserPoints component. This xml file has to be utf-8 encoded (required). All developers of third party extensions for Joomla! can add directly at the root of their frontend component a unique xml file containing all the rules for a single component. Deveoper has to respect the ordering and tags: structure example: [betauserpoints\_rule.xml](images/ | + | Then developers have to create an xml file to make easier the installation process in the BetaUserPoints component. This xml file has to be utf-8 encoded (required). All developers of third party extensions for Joomla! can add directly at the root of their frontend component a unique xml file containing all the rules for a single component. Deveoper has to respect the ordering and tags: structure example: [betauserpoints_rule.xml](images/ |
- | Administrator of the website which install a third component with this xml file can autodetect directly from the button “auto-detect plugins” in control panel of BetaUserPoints. | + | Administrator of the website which install a third component with this xml file can autodetect directly from the button “auto-detect plugins” in control panel of BetaUserPoints. |
- | This xml file has to be utf-8 encoded (required) but not be zipped! Just put this file at the root of frontend component folder or plugin or module and include this file in your installer extension. This file must be named exactly as follows: | + | This xml file has to be utf-8 encoded (required) but not be zipped! Just put this file at the root of frontend component folder or plugin or module and include this file in your installer extension. This file must be named exactly as follows: |
=== Code list for categories : === | === Code list for categories : === | ||
- | ar -> articles | + | < |
- | cd -> coupons | + | ar -> articles |
- | co -> community | + | cd -> coupons |
- | fo -> forums/ | + | co -> community |
- | li -> links | + | fo -> forums/ |
- | mu -> music | + | li -> links |
- | ot -> other | + | mu -> music |
- | ph -> photo | + | ot -> other |
- | po -> polls | + | ph -> photo |
- | pu -> purchase | + | po -> polls |
- | re -> recommend/ | + | pu -> purchase |
- | sh -> shopping | + | re -> recommend/ |
- | su -> private | + | sh -> shopping |
- | sy -> system rules | + | su -> private |
- | us -> users | + | sy -> system rules |
- | vi -> video | + | us -> users |
- | + | vi -> video | |
+ | </ | ||
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 ' | 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 ' | ||
- | ===== Plugin/Rule installation | + | ==== Plugin/Rule installation ==== |
- | \- auto-detect xml file at the root of frontend component: | + | - auto-detect xml file at the root of frontend component: |
- | Click on the button “Auto-detect plugins” in the control panel of BetaUserPoints after installation of third component, plugin or module. Check regularly or periodically by clicking on this button. | + | Click on the button “Auto-detect plugins” in the control panel of BetaUserPoints after installation of third component, plugin or module. Check regularly or periodically by clicking on this button. |
+ | ==== Using BetaUserPoints information in a third party component ==== | ||
- | ===== Using BetaUserPoints | + | You can use easily the profil |
+ | => Before using a function, you must include the API at least once in your page like this: | ||
- | You can easily use the profile information of a user directly in a third component. | + | <code php> |
- | \=> Before using a function, you must include the API at least once in your page like this: | + | $api_BUP |
- | + | </ | |
- | `$api_AUP | + | |
=== Profile information === | === Profile information === | ||
- | To get the entire | + | To get the entire |
- | Just use the referreid of BetaUserPoints user or the Joomla | + | Just use the referreid of BetaUserPoints user or the joomla |
- | + | ||
- | Use the first method with the referreid to get user Information profile like this : | + | Use the first method with the referreid to get user Information profile like this : |
- | + | ||
- | `BetaUserPointsHelper:: | + | <code php> |
- | + | BetaUserPointsHelper:: | |
- | + | </ | |
- | If you do not have the referreid, you can use the ID of user in the second parameter like this : | + | |
- | + | If you do not have the referreid, you can use the ID of user in second parameter like this : | |
- | `$user = JFactory:: | + | |
- | + | <code php> | |
- | Then you can get the following user informations: | + | $user = JFactory:: |
- | $profil-> | + | </ |
- | $profil-> | + | |
- | $profil-> | + | Then you can get the following user informations: |
- | $profil-> | + | |
- | $profil-> | + | < |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
- | $profil-> | + | $profil-> |
+ | $profil-> | ||
+ | $profil-> | ||
+ | $profil-> | ||
+ | $profil-> | ||
+ | $profil-> | ||
$profil-> | $profil-> | ||
+ | </ | ||
- | === Get AUP avatar of user === | + | === Get BUP avatar of user === |
- | Display the image of avatar from BetaUserPoints. | + | Display the image of avatar from BetaUserPoints. |
- | + | ||
- | `$avatar = BetaUserPointsHelper:: | + | |
- | + | ||
- | if $linktoprofil set to 1, display avatar with the link to the AUP profil of this user. | + | |
- | | + | |
- | === Get link to AUP user profile | + | <code php> |
+ | $avatar | ||
+ | </ | ||
- | Get the url to show the profile | + | if $linktoprofil set to 1, display avatar with the link to the BUP profil |
- | + | ||
- | `$linktoAUPprofil = BetaUserPointsHelper:: | + | |
- | === Get link to AUP users list === | ||
- | Get the url to show the list of users with points etc… | + | === Get link to BUP user profile === |
- | + | ||
- | `$linktoAUPusersList | + | Get the url to show the profil of user. |
- | + | ||
- | + | <code php> | |
+ | $linktoBUPprofil = BetaUserPointsHelper:: | ||
+ | </ | ||
+ | |||
+ | === Get link to BUP users list === | ||
+ | |||
+ | Get the url to show the list of users with points etc… | ||
+ | |||
+ | <code php> | ||
+ | $linktoBUPusersList | ||
+ | </ | ||
=== Get avatar Path of a user === | === Get avatar Path of a user === | ||
- | Get the avatar path of a specific user | + | Get the path avatar path of a specific user |
- | + | ||
- | `$avatarPath = BetaUserPointsHelper:: | + | <code php> |
- | + | $avatarPath = BetaUserPointsHelper:: | |
- | + | </ | |
=== Get avatar Live Path of a user === | === Get avatar Live Path of a user === | ||
- | Get the live url avatar path of a specific user | + | Get the live url avatar path of a specific user |
- | + | ||
- | `$avatarLivePath = BetaUserPointsHelper:: | + | <code php> |
+ | $avatarLivePath = BetaUserPointsHelper:: | ||
+ | </ | ||
=== Get the medals list of a user === | === Get the medals list of a user === | ||
- | `$medalslistuser = getUserMedals($referrerid); | + | <code php> |
- | or | + | $medalslistuser = getUserMedals($referrerid); |
- | `$medalslistuser = getUserMedals('', | + | </ |
- | + | or | |
- | return $medallistuser-> | + | <code php> |
- | return $medallistuser-> | + | $medalslistuser = getUserMedals('', |
- | return $medallistuser-> | + | </ |
- | return $medallistuser-> | + | |
- | return $medallistuser-> | + | < |
- | + | return $medallistuser-> | |
- | `$user = JFactory:: | + | return $medallistuser-> |
- | + | return $medallistuser-> | |
+ | return $medallistuser-> | ||
+ | return $medallistuser-> | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | $user = JFactory:: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
=== Get the ReferreID of any user === | === Get the ReferreID of any user === | ||
- | `$referreid = BetaUserPointsHelper:: | + | <code php> |
- | + | $referreid = BetaUserPointsHelper:: | |
- | + | </ | |
- | + | ||
+ | |||
=== Get the current total points of any user === | === Get the current total points of any user === | ||
- | Use the first method with the referreid to get the total points | + | Use the first method with the referreid to get the total of points |
- | + | ||
- | `$totalPoints = BetaUserPointsHelper:: | + | <code php> |
- | + | $totalPoints = BetaUserPointsHelper:: | |
- | `$user = JFactory:: | + | </ |
- | + | ||
+ | If you have not the referreid, you can use the ID of user (joomla) in second parameter like this : | ||
+ | |||
+ | <code php> | ||
+ | $user = JFactory:: | ||
+ | </ | ||
=== Get the list of activities === | === Get the list of activities === | ||
- | `$listActivities = BetaUserPointsHelper:: | + | <code php> |
- | $params $type = all | positive | negative | + | $listActivities = BetaUserPointsHelper:: |
- | $params $userid = all or unique userID | + | </ |
- | $params $limit = int (0 by default) | + | |
- | example-1 -> ------------------------------------------------------------------------- | + | < |
- | example-1 -> $listActivities = BetaUserPointsHelper:: | + | $params $type = all | positive | negative |
- | example-1 SAME AS -> $listActivities = BetaUserPointsHelper:: | + | $params $userid = all or unique userID |
- | example-1 -> show all activities with pagination, positive and negative points of activity for all users | + | $params $limit = int (0 by default) |
- | \----------------------------------------------------------------------------------- | + | example-1 -> ------------------------------------------------------------------------- |
- | example-2 -> ------------------------------------------------------------------------- | + | example-1 -> $listActivities = BetaUserPointsHelper:: |
- | example-2 -> $user = JFactory:: | + | example-1 SAME AS -> $listActivities = BetaUserPointsHelper:: |
- | example-2 -> $userID = $user-> | + | example-1 -> show all activities with pagination, positive and negative points of activity for all users |
- | example-2 -> $listActivities = BetaUserPointsHelper:: | + | ----------------------------------------------------------------------------------- |
- | example-2 -> show only positive points of activity for the current user logged in and show only 20 rows of recent activities | + | example-2 -> ------------------------------------------------------------------------- |
- | + | example-2 -> $user = JFactory:: | |
- | Returns an array or $rows | + | example-2 -> $userID = $user-> |
- | List of available fields : | + | example-2 -> $listActivities = BetaUserPointsHelper:: |
- | insert\_date | + | example-2 -> show only positive points of activity for the current user logged in and show only 20 rows of recent activities |
- | referreid | + | </ |
- | points (of this activity) | + | |
- | datareference | + | Returns an array or $rows |
- | rule\_name | + | |
- | plugin\_function | + | List of available fields : |
- | category | + | |
+ | < | ||
+ | insert_date | ||
+ | referreid | ||
+ | points (of this activity) | ||
+ | datareference | ||
+ | rule_name | ||
+ | plugin_function | ||
+ | category | ||
+ | </ | ||
=== Get the next user rank === | === Get the next user rank === | ||
- | `$nextrankinfo = BetaUserPointsHelper:: | + | <code php> |
- | + | $nextrankinfo = BetaUserPointsHelper:: | |
- | return $nextrankinfo-> | + | </ |
- | return $nextrankinfo-> | + | |
- | return $nextrankinfo-> | + | < |
- | return $nextrankinfo-> | + | return $nextrankinfo-> |
- | return $nextrankinfo-> | + | return $nextrankinfo-> |
- | return $nextrankinfo-> | + | return $nextrankinfo-> |
- | return $nextrankinfo-> | + | return $nextrankinfo-> |
- | === Get version of AUP === | + | return $nextrankinfo-> |
+ | return $nextrankinfo-> | ||
+ | return $nextrankinfo-> | ||
+ | </ | ||
+ | |||
+ | === Get version of BUP === | ||
+ | |||
+ | <code php> | ||
+ | $num_bup_version = BetaUserPointsHelper:: | ||
+ | </ | ||
+ | |||
+ | Returns the current version of BetaUserPoints like -> 4.0.0 | ||
+ | |||
+ | |||
+ | |||
+ | ==== BetaUserPoints is open for third component ==== | ||
+ | |||
+ | Create your own plugin for BetaUserPoints ! | ||
+ | Plugins provide functions which are associated with trigger events. | ||
+ | |||
+ | Available events in BetaUserPoints: | ||
+ | |||
+ | < | ||
+ | - onBeforeInsertUserActivityBetaUserPoints - onUpdateBetaUserPoints | ||
+ | - onAfterUpdateBetaUserPoints | ||
+ | - onChangeLevelBetaUserPoints | ||
+ | - onUnlockMedalBetaUserPoints | ||
+ | - onGetNewRankBetaUserPoints | ||
+ | - onResetGeneralPointsBetaUserPoints | ||
+ | - onBeforeDeleteUserActivityBetaUserPoints | ||
+ | - onAfterDeleteUserActivityBetaUserPoints | ||
+ | - onBeforeDeleteAllUserActivitiesBetaUserPoints | ||
+ | - onAfterDeleteAllUserActivitiesBetaUserPoints | ||
+ | - onBeforeMakeRaffleBetaUserPoints | ||
+ | - onAfterMakeRaffleBetaUserPoints | ||
+ | </ | ||
+ | |||
+ | You can see the example file / | ||
+ | |||
+ | [betauserpoints](/ | ||
+ | |||
+ | * Created on 15 January 2016. | ||
+ | |||
+ | * Last updated on 05 April 2023. | ||
- | `$num_aup_version = BetaUserPointsHelper:: | ||
- | | ||
- | Returns the current version of BetaUserPoints like -> 1.0.0 | ||
- | | ||
- | | ||
- | ===== BetaUserPoints is open to third party component ===== | ||
- | Create your own plugin for BetaUserPoints ! | ||
- | Plugins provide functions which are associated with trigger events. | ||
- | | ||
- | Available events in BetaUserPoints: | ||
- | | ||
- | \- onBeforeInsertUserActivityBetaUserPoints - onUpdateBetaUserPoints | ||
- | \- onAfterUpdateBetaUserPoints | ||
- | \- onChangeLevelBetaUserPoints | ||
- | \- onUnlockMedalBetaUserPoints | ||
- | \- onGetNewRankBetaUserPoints | ||
- | \- onResetGeneralPointsBetaUserPoints | ||
- | \- onBeforeDeleteUserActivityBetaUserPoints | ||
- | \- onAfterDeleteUserActivityBetaUserPoints | ||
- | \- onBeforeDeleteAllUserActivitiesBetaUserPoints | ||
- | \- onAfterDeleteAllUserActivitiesBetaUserPoints | ||
- | \- onBeforeMakeRaffleBetaUserPoints | ||
- | \- onAfterMakeRaffleBetaUserPoints | ||
- | | ||
- | You can see the example file / | ||
- | [betauserpoints](/ | ||
- | * | ||
- | * Last updated on 5 April 2023. |
betauserpoints/developer.1680851089.txt.gz · Last modified: 2023/04/07 07:04 by admin