Welcome to the Course Portal Achievement System documentation. This system is designed to provide users with achievements and badges based on their activities within the Course Portal. Achievements are unlocked when users complete certain milestones, such as watching lessons or writing comments, while badges are earned based on the number of achievements unlocked.
It however does not include a front end component. It only has the backend code for the application.
To implement the Course Portal Achievement System, you need to integrate it into your Laravel project. Follow these steps to get started:
-
Clone this repository to your local environment.
-
Run
composer install
to install the necessary dependencies. -
Configure your database settings in the
.env
file. -
Run database migrations and seed the database with initial data:
php artisan migrate --seed
-
Make sure to set up the event listeners for
LessonWatched
andCommentWritten
events as described in the Listening for Events section below. Default event listeners have already been provided. You can also add on to these listeners to unlock additional achievements and badges.
In your Laravel application, you should have event listeners for the LessonWatched
and CommentWritten
events. When these events are fired, the Course Portal Achievement System will automatically listen for them and unlock relevant achievements and badges for users.
Here's an example of how to set up event listeners in Laravel:
protected $listen = [
LessonWatched::class => [
// Add your listener for LessonWatched event here
],
CommentWritten::class => [
// Add your listener for CommentWritten event here
],
];
Ensure that these listeners call the appropriate methods to unlock achievements and badges.
The Course Portal Achievement System has several achievements and badges that users can unlock:
- First Lesson Watched
- 5 Lessons Watched
- 10 Lessons Watched
- 25 Lessons Watched
- 50 Lessons Watched
- First Comment Written
- 3 Comments Written
- 5 Comments Written
- 10 Comments Written
- 20 Comments Written
- Beginner: 0 Achievements
- Intermediate: 4 Achievements
- Advanced: 8 Achievements
- Master: 10 Achievements
Achievements and badges are unlocked automatically when users meet the criteria. When an achievement is unlocked, an AchievementUnlocked
event is fired with the relevant information. Similarly, when a user earns a new badge, a BadgeUnlocked
event is fired.
To simulate user activities and test the Course Portal Achievement System, you can use Laravel console commands. These commands allow you to simulate watching lessons and writing comments for testing purposes.
Here are some example commands you can run:
-
Simulate watching a lesson:
php artisan app:watch-lesson {--lesson=1: Lesson ID to watch} {--user=1: User ID of the watcher}
Replace the IDs with the user id of the user watching the lesson and lesson id for the lesson being watched respectively.
-
Simulate writing a comment:
php artisan app:write-comment {--user=1} {--comment=This is a comment}
You can use these commands to test the unlocking of achievements and badges based on user activities.
That's it! You now have the Course Portal Achievement System integrated into your Laravel project. Users can earn achievements and badges as they engage with the Course Portal, and you can monitor their progress through the provided commands.
- Run
php artisan serve
to start the server
- Run
php artisan test
to run the tests - Run
php artisan test --coverage-html coverage-report
to generate a coverage report