Basic example of Block plugin for database queries. The plugin contains only skeleton structure. Except output of SQL results, it also adds two tables:
-
seminars (table 1)
- id (auto increment integer)
- starttime int(10)
- endtime int(10)
- title char(255) (not unique)
- description text (Moodle longtext)
-
seminars_bookings (table 2)
- id (auto incremented integer)
- userid int(10)
- seminarid int(10)
- status int(1)
Moodle prefix: mdl_
In seminars_bookings table for userid field foreign key points to mdl_user.id table, and seminarid has foreign key pointing to mdl_seminars.id
The tables were created using Moodle interface: XMLDB Editor which creates install.xml file in db directory. Moodle uses the file during plugin installation to create tables.
#Additional Video Resources:
- How to create Moodle simple plugin
- How to create Moodle tables with plugin
- How to use Moodle block plugin for SQL output
The code contains both install.xml file and query used in the last video.