gstt/laravel-achievements

Locking

koxu1996 opened this issue · 4 comments

I am looking for a way to lock achievement. Is is possible?

Locking, as in making the achievement unable to be completed but allowing everyone that already has it to keep it?

Still not an existing feature. I'll set this as a feature request and work on it!

I meant opposite of unlocking. For example if user unlocked achievement for completing all exercises in category and there is new one added, then I want to revoke his achievement.

Currently the API does not expose a way to lock an achievement again. But I have a suggestion on how you should proceed in your use case.

The function that checks if an achievement is unlocked do the following checks:

  1. Is there a date for when this achievement was unlocked for this user? If yes, return true.
  2. Has this user already reached the required progress points to unlock the achievement? If yes, return true.
  3. Return false.

In your use case, you are adding a new exercise and want the users to reach this new progress point in order to unlock the achievement. Assuming that you're tracking the progress numerically (i.e. you have X exercises and set the achievement to be unlocked with X progress points) his is how I suggest you do it:

  1. Increment the amount of points required to unlock the achievement on the Achievement class (this change will automatically be synchronized to the database);
  2. Create a database migration that sets unlock_date = NULL for all records on achievement_progress that matches the database ID for the achievement.

If that's not clear, please let me know.