Question/Idea: Award points and badge on behaviour
ronnyandre opened this issue · 2 comments
ronnyandre commented
I love how easy and simple it is to use this library, and to give points and bagdes to user. But I was wondering, would it be possible to use the library as is, to award badges based on, let's say "10 completed todos" or "Five day streak completing todos"?
If not, is this a feature you would be interested in developing?
saqueib commented
yes @ronnyandre you can do it. Every badged has a qualifier($user)
method which determines what badged to give to a user, you just need to return true from this method and badges will be given.
For example:
php artisan gamify:badge TenCompletedTodos
namespace App\Gamify\Badges;
use QCod\Gamify\BadgeType;
class TenCompletedTodos extends BadgeType
{
/**
* Description for badge
*
* @var string
*/
protected $description = 'Great! You have completed 10 todos. Keep it up!';
/**
* Check is user qualifies for badge
*
* @param $user
* @return bool
*/
public function qualifier($user)
{
return $user->todos()->completed()->count() >= 10;
}
}
You get the idea, this way you can check for five-day streak also and award a new badge.
ronnyandre commented
Of course! Why didn't I think of that before I asked... 😳