PHPackages                             tiagogouvea/phpgamification - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. tiagogouvea/phpgamification

ActiveLibrary[Framework](/categories/framework)

tiagogouvea/phpgamification
===========================

PHPGamification are a Generic Gamification PHP Framework that clains to be simple and objective.

346414[1 issues](https://github.com/TiagoGouvea/PHPGamification/issues)PHP

Since Dec 7Pushed 10y ago7 watchersCompare

[ Source](https://github.com/TiagoGouvea/PHPGamification)[ Packagist](https://packagist.org/packages/tiagogouvea/phpgamification)[ RSS](/packages/tiagogouvea-phpgamification/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPGamification
===============

[](#phpgamification)

**PHPGamification** is a **Generic Gamification PHP Framework** that claims to be simple and objective.

Forked from [jfuentesa/gamification](https://github.com/jfuentesa/gengamification).

Features
========

[](#features)

- Quickly integrate a **full gamification engine** to your projects
- Handle **Points**, **Levels** and **Bagdes**
- Access stored user **alerts** and **logs** to easy understand user scores
- Use your own **user database** with no need to change your tables structures
- Create Callbacks to use when user receives Points or Badges

Sample code
===========

[](#sample-code)

```
/** Instantiate **/
$gamification = new PHPGamification::getInstance();
$gamification->setDAO(new DAO('my_host', 'my_databse', 'my_user', 'my_pass'));

/** Badges definitions */
$gamification->addBadge('newbee', 'Newbee', 'You logged in, congratulations!');
$gamification->addBadge('addict', 'Addict', 'You have logged in 10 times');
$gamification->addBadge('professional_writer', 'Professional Writer', 'You must write a book! 50 posts!!');

/** Levels definitions */
$gamification->addLevel(0, 'No Star');
$gamification->addLevel(1000, 'Five stars', 'grant_five_stars_badge');// Execute event: grant_five_stars_badge
$gamification->addLevel(2000, '2K points!');

/** Events definitions */

// Welcome to our network! (disallow reachRequiredRepetitions)
$event = new Event();
$event->setAlias('join_network')
    ->setEachPointsGranted(10)
    ->setAllowRepetitions(false); // Just one time
$gamification->addEvent($event);

// Each Login/Logged in 10 times (25 points each time, 50 points when reach 10 times)
$event = new Event();
$event->setAlias('login')
    ->setEachPointsGranted(25)
    ->setEachBadgeGranted($gamification->getBadgeByAlias('newbee'))
    ->setReachRequiredRepetitions(10)
    ->setReachPointsGranted(50)
    ->setReachBadgeGranted($gamification->getBadgeByAlias('addict'));
$gamification->addEvent($event);

// Each post to blog/You wrote 5 post to your blog (100 points each + badge, 1000 points reach)
$event = new Event();
$event->setAlias('post_to_blog')
    ->setEachPointsGranted(150)
    ->setEachCallback("MyOtherClass::myPostToBlogCallBackFunction")
    ->setReachRequiredRepetitions(50)
    ->setReachBadgeGranted($gamification->getBadgeByAlias('professional_writer'));
$gamification->addEvent($event);

/** Using it */

$gamification->setUserId(1);
$gamification->executeEvent('join_network');
$gamification->executeEvent('login');
for ($i=0; $iexecuteEvent('login');
$gamification->executeEvent('post_to_blog', array('YourPostId'=>11));

/** Getting user data */
echo "";
var_dump($gamification->getUserAllData());
echo "";

/** Getting users ranking */
echo "";
var_dump($gamification->getUsersPointsRanking();
echo "";
```

Installing
==========

[](#installing)

Clone, download or just add to your composer.json file:

```
{
    "require": {
        "tiagogouvea/phpgamification": "*"
    }
}
```

Or call:

```
composer require tiagogouvea/phpgamification
```

Using
=====

[](#using)

In /sample/ folder you can see a simple intuitive code. It must be you start point to use PHPGamification.

Setup your gamification rules
-----------------------------

[](#setup-your-gamification-rules)

Get the PHPGamification engine to construct the object:

```
$gamification = new PHPGamification::getInstance();
$gamification->setDAO(new DAO('my_host', 'my_databse', 'my_user', 'my_pass'));
```

You can set your own DAO: implement DAOInterface and set your instance with $gamification-&gt;setDAO();

### Levels and badges

[](#levels-and-badges)

Just tell what levels and badges have your game, like in sample file.

### Events

[](#events)

A event may occur a just time or many times. When creating a event you can setup Points and Badge to be granted **each** time it occurs and/or when user **reach** the required repetitions.

- Each: occurs every time a event is called
- Reach: occurs only when user reach the required reachRequiredRepetitions
- You can also use setAllowRepetitions(false) to tell the event can be called just one time by user.

### Callbacks

[](#callbacks)

Use callback methods to improve the user interation with your gamification system or validate if a user really need receive points/badges. The callbacks can be called in two moments:

- Each Callback: will run every time and event are executed
- Reach Callback: will run just when user reach the required event repetions

When using your callback methods, remember to return **true** to the event continue, or **false** to event don't grant Points nor adges. It can be used to cerify some data in your business logic before giving points or badges to the user.

Running your gamification engine
--------------------------------

[](#running-your-gamification-engine)

Start the engine setting the **User Id** that you are working with:

```
$gamification->setUserId($yourUserId);
```

Every time you want to something happen in your gamification enviroment you must **execute a event** calling:

```
$gamification->executeEvent('login',array('more_data'=>'to_your_callback'));
```

All information you can need about the some user can be retrieved calling getUserScores(), getUserBadges(), showUserLog() and getUserEvents(), or $gamification-&gt;getUserAllData() to return all togheter:

```
var_dump($gamification->getUserScores());
```

Keep your users engajed
-----------------------

[](#keep-your-users-engajed)

Take advantage of events callback to send emails to user user when some great happend, like, win a new badge or growing by the levels.

Todo
====

[](#todo)

If you want to colaborate, make a fork and do your pull requests!

- Allow Callbacks when your conquest a new level (move ReachCallback to badge and level?)
- Fix autoload to work just with composer
- Create a iframe call to people show their points and badges on their blogs

Contact
=======

[](#contact)

Tiago Gouvêa

[Blog](http://www.tiagogouvea.com.br) | [Twitter](https://twitter.com/TiagoGouvea) | [Facebook](https://www.facebook.com/tiagogouvea)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/29a83cbda74a7f68781e63ec84f1c8d257223f71cd062d84fa4009bf99108074?d=identicon)[TiagoGouvea](/maintainers/TiagoGouvea)

---

Top Contributors

[![TiagoGouvea](https://avatars.githubusercontent.com/u/2242549?v=4)](https://github.com/TiagoGouvea "TiagoGouvea (11 commits)")[![jfuentesa](https://avatars.githubusercontent.com/u/6414996?v=4)](https://github.com/jfuentesa "jfuentesa (2 commits)")

### Embed Badge

![Health badge](/badges/tiagogouvea-phpgamification/health.svg)

```
[![Health](https://phpackages.com/badges/tiagogouvea-phpgamification/health.svg)](https://phpackages.com/packages/tiagogouvea-phpgamification)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
