How to Create a Karma Source

Overview

Karma is created using the KarmaService. This service handles storing and retrieval of Karma, as well as summation and caching. All karma earned is stored as objects of the KarmaLedger class, but this class and the KarmaLedgetRepository should not normally be accessed directly.

All Karma has a Source, Issuer, and Issuer Action.

  • Source: This is the top-level Karma type. A karma source can have multiple issuers and is issuer-agnostic. For example, "Code Contribution" can be the source of karma covering code contribution on any platform, such as GitHub, Bitbucket, GitLab, etc. We show badges and totals calculated per karma source and do not mention the issuer. Each karma source has a <=16 char alphanumerical identifier called the karma source code.

  • Issuer: A karma issuer is mostly interesting from a developer perspective. It is a specific interface to a platform where karma is generated. For example, an interface to GitHub could be a karma issuer. Each karma issuer has a <=32 char alphanumerical identifier.

  • Issuer Action: A specific action that generates a specific karma amount. For example, a commmit or merge on GitHub could be an issuer action. Each karma issuer action has a <=32 char alphanumerical identifier.

TypoScript Definition

Karma sources, issuers, and issuer actions are defined in TypoScript. Sources should ideally be defined in the Karma extension itself, and issuers and issuer actions in their own extensions.

 1   plugin.tx_karma.settings {
 2      issuers {
 3         # The issuer code is "userProfileChange"
 4         userProfileChange {
 5            # The issuer action code is "newUserWasCreated"
 6            newUserWasCreated {
 7               # Each issuer action is related to a karma source
 8               sourceCode = useraction
 9               label = Created User
10               valueEarned = 10
11            }
12         }
13      }
14
15      sourceCodes {
16         # The karma source code is "useraction"
17         useraction {
18            label = typo3.org User
19            # This is an example for future use. Badges have not yet been implemented
20            badges {
21               # >=100 karma points from this source will give the user an "Active User" badge
22               100 {
23                  icon = EXT:karma/Resources/Public/Icons/ActiveUserBadge.svg
24                  label = Active User
25               }
26               # >=500 karma points from this source will give the user an "Eclectic User" badge
27               500 {
28                  icon = EXT:karma/Resources/Public/Icons/EclecticUserBadge.svg
29                  label = Eclectic User
30               }
31            }
32         }
33      }
34   }

PHP Implementation

An example implementation of a karma issuer can be found in T3oKarmaUtilityUserProfileChangeKarmaIssuerUtility.

1   $this->karmaService->triggerKarmaIssuerActionForUser(
2      self::ISSUER_CODE,
3      __FUNCTION__,
4      $frontendUser
5   );

It is recommended to make the issuer code into a lower camel case version of the class name. In this case, the issuer code for UserProfileChangeKarmaIssuerUtility is userProfileChange. The issuer action name is the method name, i.e. newUserWasCreated.

SOAP API

We should create a SOAP API.