Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Improved Question Bank Tags

From MoodleDocs

Overview

This document is "under construction" (really!)

This document is the technical design for a set of features proposed by the Moodle Users Association for Moodle 3.5.

The project proposal is here: https://moodleassociation.org/mod/page/view.php?id=465

The requirements / user stories have been written by the MUA - a copy is included here for clarity

User Stories / Requirements

Must:

  • As a teacher, I can add tag(s) to a question bank question for use in my course for organizational and search/filtering of questions.
  • As a teacher, I can filter my questions in courses based on tags.
  • As a teacher, I can see tags on questions at higher category assigned by Question sharer role holder.
  • As another teacher in the same course, I have access to the question tags on the questions in that course context.
  • As a teacher in a course, I do not see tags of other in contexts I do not have access to. (Instructor 1’s “midterm 1” question set would not be relevant to Instructor 2)
  • As a teacher, I am able to add/modify/remove tags on questions.
  • As a teacher, I should not have to copy a question into my course from higher category contexts to include it in a ‘random question from question set’ question type.
  • As a teacher, I can add a 'random question from question set' question type to my quiz where the question set is a selectable list of questions. These questions can be searched for and filtered by tag but the set itself is not defined by specifying a tag.

Nice to have:

  • Labels can contain any visible ASCII characters including characters such as apostrophes, slashes, and colons. Exception of Comma.
  • As a teacher, when searching for questions to add to a ‘random question from question set’ I see the question with its context clearly visible.
  • As a teacher, I can export/import questions with their tags.
  • As a Question sharer role holder, I can add a tag(s) to a question bank questions that exist at the category context.
  • As a Question sharer role holder, I can search/filter all the questions I have access to and see them along with their context.

Design

The requirements listed above can be met by implementing the following changes (which are described in detail further down):

  • New question type "Random question from a set of questions"
  • Enhanced question search allowing search/filter by tag everywhere
  • Allow adding course level tags to questions that exist in a category

Random question from a set of questions

Architecture

Currently the quiz_slots DB table has a questionid column that directly links to the question for that slot. We will change this table to abstract the logic for determining the question from the slot.

We would add a new slottype column to the quiz_slots table that indicates the class which contains the logic for determining the question from the slot.

We will introduce a new abstract class "mod_quiz\slot_type".

The slot_type subclass will be responsible for:

  • Determining a specific question id from a quizid + slotid + userid. A new question id is only queried when a new attempt is started, or a question is re-attempted.
  • Storing slottype specific data from the configuration of the question slot in it's own DB tables.
  • Backup of it's own slottype specific data.
  • Restore of it's own slottype specific data and upgrade data from previous backup file versions.
  • Display of UI to configure this slot type (JS and non-JS).
  • Remove data when a question or slot is deleted

When the slottype is "single" - the slot_type_direct class is loaded directly from the quiz (not a sub-plugin). When the slottype is any other type - the slot_type_TYPE class will be loaded from the quizslot_TYPE sub-plugin.

DB changes

Add slottype to the slots table, make questionid allow null and add 2 new tables (one per slot type). quizslot_randomfromcategory(id, quizslotid, includesubcategories, questioncategoryid) (foreign key quizslotid unique, foreign key questioncategoryid) quizslot_randomfromset(id, quizslotid, questionid) (foreign key quizslotid, foreign key questionid)

Note: For upgrades, it will be simpler to keep the questionid column on the slots table for the most common usage of question slots. This means a much smaller upgrade step and because the 'single' slottype is not implemented as a sub-plugin it makes sense to keep the data in the table belonging to the quiz component.

Note: It was considered to store the list of questions in a single text field as a list. This was not chosen because it would cause performance issues on some DBs, and would introduce a hard limit on the number of random questions that could be added.

DB structure changes

UI changes

These images are mockups for illustration only and are not to be taken as the final UI design.

Random question from list added to quiz structure menu
Dialog to edit the list of random questions
Question picker to add questions to the random list
Random question from list added to a quiz

Upgrade Steps Required

  • We will need to change the questionid column of the quiz_slots table to allow null. (Quick DB update, no conflicts to resolve).
  • We will need to search for all "random" questions in the question bank and for each one - move the configuration data to the quizslot_randomfromcategory table and delete the question from the question bank.

Search for question by tag

Architecture

There are 2 places we could (should) be able to search questions by tag.

The first is from the tag management page. This work has been started on https://tracker.moodle.org/browse/MDL-59781, all that remains to complete it is to create a moodle page that can show a single question from a question bank (so the tag search results page can link to the question).

The second is to be able to search for questions by tag in the question picker while adding questions to a quiz. There is an existing API to extend this search form and an example in the local plugin https://github.com/MorrisR2/moodle_local_searchquestions. This would just require adding a new plugin that implements the get_question_bank_search_conditions callback to return an instance of core_question\bank\search\condition for searching tags. The search field for tags should just be a text field. The current API does not allow javascript to be used in search conditions, if a full "autocomplete" element is required for the tags search we will need to extend the question bank API.

UI Changes

Search for questions from global tag search
Search by tags while picking questions from the question bank

Course level tags for questions

- Describe list of changes