In This Tutor ial you will learn how to build a Event reminder app with yii2 framework . Our Event reminders project can be broken down into four main components:
- Users who will create events and reminders
- Events that the user wants to be reminded of
- Reminders for the actual event (of which there could be many)
- A command-line task to process and send out the reminders to the user via e-mail
Here is The Preview Of our app
The first component of our application is the users who will be using it. Users will be responsible to create both events and reminders for themselves. The users will also be the recipients of the reminder e-mails that they created. Using this information, we can simplify our database schema to the following structure:
ID INTEGER PRIMARY KEY email STRING password STRING created INTEGER updated INTEGER
In Tutorial 1, A Task-management Application, we created a very primitive user authentication system that we’ll be reusing and expanding upon and reusing in later Tutorials. In this Tutorial, we’ll develop a system to create, delete, and manage the passwords of users with our application. We’ll also cover several basic guidelines for properly securing, storing, and working with our users’ credentials.
The second component of our application is events. Events are things that a particular user wants to be reminded of and will occur at a given time on a given date. Events should be easy to search through and intuitive to find. Additionally, events can have one, many, or no reminders associated with them. We can express this in our database schema, as follows:
ID INTEGER PRIMARY KEY user_id INTEGER title STRING data TEXT time INTEGER created INTEGER updated INTEGER
A new concept that we’ll be introducing in this Tutorial is the concept of database relations. Many times, data in our database will be associated with an attribute or data in another table of our database. In this case, an event is something that belongs to a given user. The relations that we create in this application will allow us to easily represent data in our tables without having to store that data in multiple places.
A reminder is a time-sensitive event that belongs to a user-created event and acts as an indicator to our task runner to notify the user of the details of the event itself. This can be expressed in our simplified database schema, as follows:
ID INTEGER PRIMARY KEY event_id INTEGER title STRING offset INTEGER time INTEGER created INTEGER updated INTEGER
When we set up our Reminders model, we’ll define a relationship between a reminder and the event. As events are already bound to a user, we can transitively determine the user a reminder should be sent to without having to add the
user_id field to the reminder itself.
The final piece of our reminders has to do with how we handle timestamps. In previous Tutorials, timestamps served only as metadata to specific records. Our reminders, however, will have to take into account the time that an event will be triggered, which means that we’ll be involving time zones. While using UTC solves a lot of the issues when dealing with time, our reminders have to be aware of what the time offset is for a particular reminder.
For our application, that means we’ll need to store the time that the end user will see in addition to either the time zone offset of the user or a conversion of that time into the real UTC time.
The task runner
The final component of our application is the task runner that will find reminders that need to be sent out and actually send them out to the user. While there are many ways to go about creating this task runner, we will be creating a command-line task that will run repeatedly after n minutes and will process all events between the trigger time and the provided interval in minutes. This approach will allow us to define how frequently or infrequently we want our reminders to be processed without having to rewrite code.