Skip to content

Plugin Overview

Adomas Ciplys edited this page Dec 8, 2024 · 10 revisions

Plugin Overview

The LiveQuiz plugin is a Moodle Activity Module, which means it can be added to any Moodle course section. To integrate with the Moodle system, the plugin must adhere to a specific folder structure and include certain pre-defined .php files. For a deeper understanding of how an Activity Module operates, you can refer to the documentation here: Moodle Activity Module Documentation.

Folder Structure

This is an overview of the most important folders and files in the LiveQuiz activity

./livequiz
├── amd
│   ├── build            # Contains linted, minified, and packaged JavaScript/CSS files from the src folder, ready to be served by Moodle. (MDL)
│   └── src              # Contains JavaScript used in Mustache templates to enable dynamic content display.  (MDL)
│       ...
│       └── repository.js # Contains functions that interact with external .php backend functions, essentially serving as our API.   (MDL)
├── attempt.php           # Handles quiz attempts, responsible for setting up the session, and querying quiz data from DB to use in templates
├── classes
│   ├── external         # Includes classes for defining web services. The functions we call when interacting with the backend from repository.js  (MDL)
│   ├── models           # Contains classes that define data models we use in the backend
│   ├── output           # Handles rendering and generating output for templates and UI elements.
│   ├── repositories     # Manages data retrieval and operations for the different model classes
│   └── services         # Provides reusable services for querying db. 
├── db                   # Contains database schema files  (MDL)
├── lang                 # Stores language files to support multi-language functionality in the plugin.  (MDL)
├── lib.php              # Contains the functions for creating, updating and deleting(DOES NOT WORK) an activity  (MDL)
├── mod_form.php         # Defines the settings form for configuring the activity when creating it in a course   (MDL)
├── results.php          # Handles querying DB for the specific participation, and hence the results of the student
├── settings.php         # Defines site-wide settings for the plugin in the Moodle administration interface.  (MDL)
├── style.css            # Defines custom styles for the WHOLE LiveQuiz plugin.
├── templates            # Contains Mustache template files used for rendering HTML output
├── tests                
│   ├── behat            # Stores Behat test cases for the UI
│   │   └── behat_mod_livequiz.php # Defines custom functions used for UI tests.
│   └── phpunit          # Contains PHPUnit test cases for unit testing the plugin's PHP code.
├── version.php          # Specifies the plugin's version   (MDL)
└── view.php             # Displays the main interface for users interacting with the LiveQuiz activity. The "entrypoint" for the plugin  (MDL)

Moodle Specific files

Some files are mandatory as per the Moodle documentation. We will try to explain in a human way what some of these files do, as some parts of the Moodle documentation are lacking in information. The rest of the docs should be fine to read

mod_form.php

This file is used when adding/editing a module in a course. It contains the elements that will be displayed on the form responsible for creating/installing an instance of the LiveQuiz module. Everything except from name are the standard Activity module elements in Moodle. The page looks like this:

image

view.php

The "entrypoint" for the plugin. The first .php file the user interacts with. Moodle passes a course module ID to the file, which can be used to fetch all remaining data for the activity instance.

db/access.php

Defines what roles in moodle are allowed to view the LiveQuiz. We allow all user roles to view the livequiz activity. It also defines at what context level you can add the activity. In this case we allow to use the activitiy in a course context

lib.php

Defines what happens when you create, update or delete a livequiz activity. MUST HAVE the functions:

  • livequiz_add_instance() - Responsible for creating a new record in the livequiz table in db and adding the corresponding course module id in Moodle of the LiveQuiz
  • livequiz_update_instance - Called when updating the LiveQuiz
  • livequiz_delete_instance - Should be called when deleting activity. DOES NOT WORK!. If you want to see if a quiz is deleted, you have to look in the mdl_course_modules table, with the course module id of the LiveQuiz and see if the column deletioninprogress has been set to 1