Skip to content

Question Bank

When developing a Qbank plugin in Moodle, the most important aspect is managing how the question bank (the repository of quiz questions) is enhanced or extended. This type of plugin allows developers to customize how questions are created, viewed, stored, searched, categorized, or manipulated within Moodle's question bank system.


Key Aspects of Developing a Qbank Plugin

  1. Plugin Structure and Location A Qbank plugin extends or modifies the behavior of the question bank. The plugin is located in the /question/bank/ directory. When you create a new Qbank plugin, you place it under the following structure:

    /question/bank/yourpluginname/
    

    The plugin structure typically includes the following essential files: - classes/local/yourpluginname.php: Core functionality, often defining classes or extending base classes. - lang/en/qbank_yourpluginname.php: Language strings. - db/services.php: Defining any services or APIs. - version.php: Plugin version and metadata.

  2. Modifying Question Bank Functionality Qbank plugins are used to extend or customize how users interact with the question bank. You might add new tabs, filtering options, sorting functionality, bulk actions, or even custom question types.

    • Core classes: Extend the base question bank classes, such as question_bank_view or question_bank_search to customize how questions are viewed, searched, or categorized.

    For example, if you want to add a new feature to filter questions by difficulty level: - You would extend question_bank_search_condition to create a custom filtering mechanism.

  3. Modifying the User Interface (UI) The user interface is a critical element of Qbank plugins, as the plugin should provide an intuitive way for users to interact with the question bank. This involves:

    • Custom tabs: You may want to add additional tabs or menus in the question bank interface to allow access to new features.
    • Custom forms: Adding or modifying forms (e.g., adding new fields for question metadata).
    • JavaScript enhancements: Use JavaScript to add dynamic behavior to the UI, like loading search results without refreshing the page.

    Example of adding a new tab:

    class myplugin_question_bank_view extends question_bank_view {
        public function get_tabs() {
            $tabs = parent::get_tabs();
            // Add your new tab here.
            $tabs[] = new my_custom_tab();
            return $tabs;
        }
    }
    
  4. Handling Question Metadata Depending on your plugin's purpose, you might need to handle additional question metadata. For instance, if you are adding features like question tagging, categorization by difficulty, or custom fields, you'll need to manage this additional metadata in a way that integrates smoothly with Moodle's core data structures.

    This involves: - Modifying the question creation/editing forms. - Ensuring that this metadata is stored in Moodle’s database. - Making sure your metadata is displayed and used correctly in question searches and sorting.

  5. Database Integration Qbank plugins often require modifications to Moodle’s database to store custom data related to questions. You’ll need to carefully define the necessary database tables in db/install.xml to handle any new data fields, such as tags, difficulty levels, or question statistics.

    Example for adding a new database table:

    <table name="qbank_difficulty">
        <field name="id" type="int" length="10" unsigned="true" notnull="true" sequence="true" />
        <field name="questionid" type="int" length="10" unsigned="true" notnull="true" />
        <field name="difficulty" type="int" length="10" unsigned="true" notnull="true" />
        <key name="primary" primary="true" fields="id"/>
    </table>
    
  6. Permission and Capability Handling One of the key aspects when extending the question bank is managing permissions and capabilities. You might want certain actions to be limited to specific roles or users.

    You’ll need to define these capabilities in db/access.php, ensuring that only authorized users can perform certain actions (e.g., viewing certain questions, performing bulk actions).

    Example:

    $capabilities = array(
        'qbank/myplugin:view' => array(
            'captype' => 'read',
            'contextlevel' => CONTEXT_COURSE,
            'archetypes' => array(
                'teacher' => CAP_ALLOW,
                'editingteacher' => CAP_ALLOW,
            ),
        ),
    );
    
  7. Custom Bulk Actions One of the strengths of the Qbank plugin system is the ability to introduce new bulk actions. You can allow users to perform actions on multiple questions at once, such as bulk moving questions, tagging, or even exporting.

    • Extend the question_bank_bulk_action class to define custom bulk actions.
    • Ensure that the bulk action integrates with the existing question bank interface and respects the permissions of users.
  8. Performance Considerations The question bank can contain thousands of questions, so performance is a key concern. When developing a Qbank plugin, ensure that your code efficiently handles large datasets and doesn’t degrade Moodle's performance.

    • Implement efficient database queries.
    • Avoid unnecessary page loads by utilizing AJAX for actions like search or filtering.
    • Cache common queries or data when possible to minimize database load.
  9. Testing Testing your plugin is crucial to ensure that it works across different question types, courses, and contexts. Consider writing unit tests and Behat tests to verify that the plugin behaves as expected.

    • Ensure that the plugin handles edge cases, such as missing data or incorrect user input.
    • Test that your plugin integrates smoothly with Moodle’s backup/restore system and handles questions correctly when restored.

Conclusion

The most important aspect of developing a Qbank plugin in Moodle is customizing how questions are displayed, searched, or managed within the question bank, while maintaining performance and ensuring seamless user interaction. By extending core classes, handling custom metadata, ensuring proper permissions, and optimizing for large datasets, you can create a powerful plugin that enhances Moodle’s question management system.