qcod / laravel-gamify

Gamify your Laravel app with Reputation Points & Achievements Badges support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Point expiration

phiter opened this issue · comments

Hey!

I found this package by googling for laravel gamification and it has some nice features but the one it lacks which is essential to my use case is that the points should have an expiration date.

In order to do this, basically when fetching points we should only get those with dates superior to the expiration time.

The reason I need this is because the user will be able to exchange points for prizes, and we don't want them to keep getting lots of points and just buy lots os prizes at once.

I noticed that there is a point column in the user table, and this would need to be updated too when the points expire. So I think just having a reward history and fetching a sum of the non-expired points would work.

What do you think?

Hi again!

I made my own implementation, quite simple actually:

    /**
     * Get user reputation point
     *
     * @param bool $formatted
     * @return int|string
     */
    public function getPoints($formatted = false)
    {
        $expiry_time = config('gamify.point_expiry_days');

        $expiry = Carbon::now()->subDays($expiry_time)->toDateString();
        $points = $this->reputations()
            ->where('created_at', '>', $expiry)
            ->sum('point');

        if ($formatted) {
            return short_number($points);
        }

        return (int) $points;
    }

But still, it would be nice to have this built-in.

Thanks for this, I will definitely try to incorporate this in next release

Hey!

I found this package by googling for laravel gamification and it has some nice features but the one it lacks which is essential to my use case is that the points should have an expiration date.

In order to do this, basically when fetching points we should only get those with dates superior to the expiration time.

The reason I need this is because the user will be able to exchange points for prizes, and we don't want them to keep getting lots of points and just buy lots os prizes at once.

I noticed that there is a point column in the user table, and this would need to be updated too when the points expire. So I think just having a reward history and fetching a sum of the non-expired points would work.

What do you think?

+1

we also needed this

Hi @saqueib , is there a plan to add expiry of points here?

maybe reopen this issue, so PR make this close if does merge with new feature, and notify developer to this suggestion?