Web Development Blog, WordPress

Building a competition engine

A while ago, we were requested to build a competition website. The requirements were:
- Only registered & logged in users will be able to enter competitions.
- A competition may be a game of skill or a game of chance.
- A competition has a start date and end date.
- Users will be able to veiw competitions that they have entered from their dashboard.
- Competition entries may be private or public.
- Competition entries may be exported into a csv format (per competition).
- Admin will be able to pick a winner (random) using the system.
- Winners list will be published and updated automatically whenever a new winner is chosen.
- There will be normal articles and blog posts on the website.

After analysing the requirements, we decided to use WordPress and build necessary plugins on top. This way, we can take advantage of all the features that WordPress already has, such as Blog, Membership (login/registration) and Admin Console.

Competition Plugin in WordPress
Our competition plugin consists of the followings:
- Competitions (Create/Edit/Delete)
- Entries
- Export
- Winners

Competitions

When creating a competition, the admin will need to fill in the following information:
- Title
- Description
- Start Date
- End Date
- Featured (if ticked, this competition will appear on homepage)
- Excerpt
- Thank You message (This is the thank you message that gets displayed when a user enters competition. The thank you message can be a simple text/HTML message or a URL. If it's a URL, the user will be redirected to the URL.)
- Image
- Entry Form (This is the life line of competition engine. Admin can create a customised competition form with any number of fields and of any type (Text, Textarea, Checkbox, Radio, Select, Address, Date, Email, Phone, Plain Text, and Public Entry). The front-end will then decide what layout will be used based on the field type. This is very powerful because it gives admins a complete control of the form without having to dabble with HTML code.)

Entries

Admin will be able to view all entries for every competition. This is linked to membership data and therefore, each entry will have member information such as Full Name, Address, Email Address, Phone Number and so on.

Export

Export allows Admin to export entries by competition. Admin can also specify start and end dates when exporting entries to only obtain entries that were submitted during the time period specified.

Winners


Admin can pick one or more random winners from all entries received from a competition. This is very useful for game of chance competitions. Admin can also view all winners for all competitions to get a idea of the most winning members.

WordPress Database Changes
We decided not to use custom post type due to complexity with competition form. There were 3 new tables created for the competition plugin. They are competitions_fields, competitions_forms and competitions_entries. A form may contain multiple fields and multiple entries. Each row in competitions_fields and competitions_entries have a foregin key of form_id which is the primary key in competitions_forms.

To be continued.

Twitter
LinkedIn
YouTube
Instagram