GithubHelp home page GithubHelp logo

dheia / wn-gamification-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunlabdev/wn-gamification-plugin

0.0 0.0 0.0 42 KB

Gamification plugin for WinterCMS

License: MIT License

PHP 73.31% CSS 2.61% HTML 24.08%

wn-gamification-plugin's Introduction

Gamification

This plugin allows you to reward your members when some actions are made. To increment the statistics, this plugin is using SunLab.Measures

How to use

From the backend, create all the needed badges. A badge need at least, a name.

Automatic attachment with SunLab.Measures

When filling measure name and amount needed: the users will automatically receive badges once the measure reach the amount needed. Refer to SunLab.Measures for measure incrementation.

Manually attaching/detaching badge

To attach or detach a badge manually, use attachBadge and detachBadge method, which accept a badge reference as string (its name), int (its id), or a Badge model.

\Winter\User\Models\User::extend(function ($user) {
    Event::listen('winter.user.activate', function($user) {
        $user->attachBadge('Verified User');
    });
});

Verify badge attachment

To simplify badge attachment verification, the plugin include a hasBadge method, which accept a badge reference as string (its name), int (its id), or a Badge model.

if ($user->haBadge('Verified User')) {
    // User has the 'Verified User' badge
}

Components

This plugin comes with two components:

BadgesList

Displays all the badge that can be rewarded, and the number of members of member who already won it.

UserBadges

Displays only the badges that a specific member won. The member could be the one actually logged in, or set by an url parameter.

Tree view

The Badge model implement SimpleTree. If you want to display the badges as a tree, use the components' property tree-displayed to optimize the database search.

The default query will load the badges ordered by their measure name and amount needed.

Measures reminder

SunLab.Measures is internally used by the plugin to increment some measures when some events are emitted. You can configure the most basic events from the backend using the generic event listener of Measures, but for complexes cases, you'll need to manually create the listener from a Plugin.php file.

A use case for this could be to give a badge rewarding immediately after the registration, because plugins' events are not supported by Measures as of today, we need to create it manually:

\Winter\User\Models\User::extend(function ($user) {
    $user->bindEvent('model.afterCreate', function () use ($user) {
        $user->incrementMeasure('registered');
    });
});

wn-gamification-plugin's People

Contributors

romainmazb avatar hitarrowlegend avatar dudy83 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.