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: Difference between revisions

From MoodleDocs
Line 34: Line 34:
So we would have only one random question type, which could be further restricted by specifying a tag.
So we would have only one random question type, which could be further restricted by specifying a tag.


This impacts one of the user requirements for the project:
"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."
would have to be modified to:
"As a teacher, I can add a 'random question' to my quiz where the question is taken from a question category. The list of questions can be further restricted by specifying a tag."
----
----
Following a meeting between Tim / Damyon I'm saving a record of the chat conversation here. I'll then update this design page based on those notes and delete the notes (but they will exist in the history).
Following a meeting between Tim / Damyon I'm saving a record of the chat conversation here. I'll then update this design page based on those notes and delete the notes (but they will exist in the history).

Revision as of 02:28, 16 November 2017

Overview

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:

  • Tags 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.

Updates

16th Nov 2017

It was discussed that the "random question from a set of questions" is not ideal because it is hard to "manage" the set of questions, e.g. adding or deleting questions from a set would have to be done individually for every quiz instance using the set. Initially "random question from a tag" was discarded earlier because there are problems when users with different permissions are editing the question. If we add the questioncategory (context) to the information that would solve the ambiguity. So we would have only one random question type, which could be further restricted by specifying a tag.

This impacts one of the user requirements for the project: "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."

would have to be modified to: "As a teacher, I can add a 'random question' to my quiz where the question is taken from a question category. The list of questions can be further restricted by specifying a tag."


Following a meeting between Tim / Damyon I'm saving a record of the chat conversation here. I'll then update this design page based on those notes and delete the notes (but they will exist in the history).


Damyon, [08.11.17 21:06] thanks - here are my notes (sorry they are rough - feel free to add more detail / correct them)

Damyon, [08.11.17 21:06]

  1. drop random question from set, replace with random question from tag + context, that makes to manage multiple questions from the same tag + context and we can store it all in the slots table
  1. plugin vs classes - much easier to do the ui and if it's all in one table classes makes sense.

structure.php could contain the classes.

correct to move category to this new model. upgrade is scary.

OU has 40,000 questions - need progress bar.

possible to have one random question from category in 2 quizes.

need to ensure that 3 random questions in a row do not get the same question.

mobile needs to duplicate this a bit.

use existing hooks


How much re-work for AMD?

re-do edit quiz page using templates + AMD + webservices - need to investigate how much work.

Move tagging UI into the question bank - not in the quiz.

Tim Hunt, [08.11.17 23:53] Re: structure.php could contain the classes - Better to say: Classes could go in a new namespace corresponding to mod/quiz/classes/local/structure/. Should rpobalby move the existing classes/structure.php & repaginate.php in there. (There is no good reason why those are two separate classes. Feel free to change.)

Tim Hunt, [08.11.17 23:54] Re structure.php could contain the classes - I would say that the fact that the OU only has 40,000 questions is a sign that this upgrade is not a scary as it might have been. No need for excessive measures, just a progress bar.

Tim Hunt, [08.11.17 23:55] Re: possible to have one random question from category in 2 quizes - this certainly exists in the data, but really only because of past bugs. THe upgrade needs to deal with this, but that shoudl be possible.

Tim Hunt, [08.11.17 23:56] Re: mobile needs to duplicate this a bit. - sorry, I was not clear. Mobile does not need to duplicate this. It calls a start attempt function, which uses the same sever-side PHP to build the quiz attempt, and returns a list of questions, so no worries there.

Tim Hunt, [08.11.17 23:59] Both startattempt.php and mobile web service call quiz_prepare_and_start_new_attempt, which calls quiz_start_new_attempt, which is where the randomisation is currently done, so that is the key code to read. The other key class to understand is random_question_loader, used there.

Tim Hunt, [08.11.17 23:59] I hope those clarifications are helpful. Other than that, good complete notes.


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 question category + tag

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.

The slot type can be determined from the fields in the quiz_slots table. After these changes there will only be 2 possible slot types (single question, or random question). The random question will require a questioncategoryid and an optional tag.

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.
  • Display of UI to configure this slot type (JS and non-JS).

When the slottype is "single" - the slot_type_single class is loaded directly from the quiz (not a sub-plugin). When the slottype is "random" the slot_type_random class is loaded directly from the quiz (also not a sub-plugin).

DB changes

Make questionid allow null and add 1 new fields to the quiz_slots table.

quiz_slots(id, slot, quizid, page, requireprevious, question, maxmark, category, tagid)

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 add columns to the quiz_slots table for questioncategoryid and tagid. (Quick update, columns will be initially null).
  • We will need to search for all "random" questions in the question bank and for each one - move the configuration data to the quiz_slots table. This will be the slow part of the upgrade and will require a progress bar.
  • We will then need to delete all "random" questions.

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

Architecture

This will be implemented by defining a new "tag area" for "course questions". The itemtype will be question and the component will be core_course. We will still have to implement the UI for adding and deleting "course question tags", and make sure that searching for questions by tags returns results from both the question tags, and the course question tags. We will add this new tag area to the backup/restore and ensure questions tagged in a course are included in the course backup file. Viewing the coursetags for a question will be controlled by a new capability: "moodle/course:viewquestiontags". Changing the course tags for a question will be controlled by a new capability "moodle/course:managequestiontags".

UI Changes

Question shows course tags icon
Edit the course tags for a question