Quiz questions available to other modules

Quiz questions available to other modules

by Gustav W Delius -
Number of replies: 37
Last summer we re-organised the quiz module to separate the code dealing with questions from the code dealing with quizzes. This has now made it possible for other modules to use the quiz questions. I have written a very simple demonstration of how that works in the module contrib/questiondemo. The first modules that should profit from this are the lesson module and the questionnaire module. Besides the advantage for the module developers not to have to write new code to handle questions there would be the most important advantage for the teacher of being able to use the questions from a single question bank in lessons, questionnaires and quizzes.

The functions and the database tables that deal with questions still all start with quiz_. While working with the code I found that this makes it very easy to get confused. I would therefore like to go ahead and rename all database tables and all functions that belong to the questions to start with question_ instead. At the same time it would make sense to move the question code to a central location. How about moving them to a top-level directory called 'question/'?

The reason why I am posting this request here is that anyone who is already using the question code from within their own code or who is using their own questiontype plug-ins would have to perform the renaming in their code as well when upgrading to Moodle 1.6. However I believe that this does not affect so many people yet. It is important that we do this before the release of Moodle 1.6.
Average of ratings: Useful (1)
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Art Lader -
So, a teacher who had created, say, 500 questions for her French course would be able to re-use those questions in her lessons? Wow, that is fantastic, Gustav!

Thank you for that. smile

-- Art
In reply to Art Lader

Re: Quiz questions available to other modules

by John Rodgers -
I will second that hurrah.  I've generated a sizable bank with this change in mind.

Nice to see you around the forums again Gustav.
In reply to John Rodgers

Re: Quiz questions available to other modules

by Gustav W Delius -
Thank you all for your enthusiastic response. I am glad that you find this idea of a central question bank useful. However I hope my post was not too misleading: we are not there yet. While the possibility is there for other modules to use the same questions as the quiz module, none do yet.

It will require a lot of work to make the lesson module use the central questions. Mark Nielsen has started this and he too will be encouraged by your enthusiastic responses. But it will not be ready in time for Moodle 1.6.
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I am very excited about the work you are doing with the quiz module. I like the idea of separating out the questions. Thanks for all you are doing and if there is anything I can do to help just let me know. I will be giving a Moodle presentation to our faculty on Friday of this week but after that I hope to have more time for testing. Peace.
In reply to Anthony Borrow

Re: Quiz questions available to other modules

by Gustav W Delius -
Dear Anthony, thank you for your offer of help. The quiz module will need a lot of testing and bug fixing over the next few weeks, especially because Moodle 1.6 beta is expected for the end of this month. 
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Great idea. I really hope you can get this in to 1.6.

Tim.

In reply to Gustav W Delius

Renaming question tables and functions

by Gustav W Delius -
I haven't received any objections yet to my proposal, hidden in my first post in this thread, to rename all database tables and all functions that belong to the questions and are independent of the quiz module to start with question_ instead of quiz_. If you have any third-party code out there that works with Moodle 1.5 and uses the quiz tables or functions, then please speak up. My renaming plans will break it until you do the same renamings in your code. So: are there any objections?

What are the advantages of renaming you may ask. The advantage is that the code of the quiz module as well as that of future modules using questions will be easier to read and understand. There will be no danger of confusing quiz-specific functions with generic functions, less danger of people who are tweaking the quiz module by mistake putting some quiz-specific code into the generic functions.

I think that simple, easy-to-read code for handling question banks and question attempts is very important because I am hoping that we will in future have a lot of people writing plug-ins for the quiz module: question types, report types, import/export formats. This will only happen if the current code is cleaned up.
In reply to Gustav W Delius

Re: Renaming question tables and functions

by Mark Nielsen -
I vote Yes; please rename the prefix of functions and tables related directly to questions to question_ instead of quiz_

You also said: "How about moving them to a top-level directory called 'question/'?"

Please do this as well.  This will help to further emphasize what belongs to question and what belongs to quiz.  Also, helps to simplify the use of the question types.

Another important issue is backup/restore.  Will the question type class contain the necessary information for backing up and restoring the question?  Or perhaps a different solution?

Cheers,
Mark
In reply to Mark Nielsen

Re: Renaming question tables and functions

by Gustav W Delius -
Hi Mark,
yes, the idea is that each question type will contain its own backup/restore code. This question type plug-in architecture is really a separate issue from the separation of questions from the quiz and I have started discussing it in a thread in the Quiz module forum. Once the separation has been accomplished we should have a separate Question types forum but for now discussions will take place in the Quiz module forum.
In reply to Gustav W Delius

Re: Renaming question tables and functions

by Mark Nielsen -
"yes, the idea is that each question type will contain its own backup/restore code"

Excellent to hear.
In reply to Gustav W Delius

Re: Renaming question tables and functions

by N Hansen -
I presume this will affect the flash card module? As long as you document what you have done, I don't think it will be a problem for me to change the necessary code in the flash card module to keep it running. I would say to go ahead but put the documentation in a very obvious place as you know there will still be some people who won't read it and these forums will be full of "Help! My XYZ module stopped working when I upgraded to 1.6!"

And yes, Gustav has been doing quite a good job tackling the existing bugs in the quiz lately.
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
While I like the idea of cleaning up smile I see two major problems sad

  - it could break a lot of hacks out there where people depend on the quiz table structure.  I know of a few of these, and there must be many more around.  Name changes for that sake alone usually cause a lot of short-term problems that were unforseen.  However, sooner is usually better with these things if the result is worth it.

  - 1.6 beta really needs to be sorted out in three weeks, by which I mean all the main work done and just bug fixing happening.  

Some big problems you would encounter:
  1. One big issue is the Unicode upgrade which processes all the tables in Moodle to correct the character set.  If you make this major change to the quiz module now, then you need to commit to fixing the upgrade process (see db/utf8migrate.php) as well.
  2. The second big issue is the upgrades.  You need to build in an upgrade process to the core admin/index.php because quiz will no longer be handling the table upgrades.
  3. Thirdly, you need to handle backup and restore, so that any course from 1.5 or 1.4 or 1.3 can be restored in 1.6 smoothly.  This means that the old information from quiz_questions is restored nicely.
There's probably more I haven't thought of just now (there always is!)

I don't really believe all this is worth it just to improve naming in the code for 1.6 at this late stage ... the time spent creating and fixing these new problems could be better spent tackling the existing bugs in the bug tracker.  wink

I think we should leave this for 2.0 instead.   If you insist on doing it, I need from you a complete committment to making this happen within a week without creating new problems.
In reply to Martin Dougiamas

Re: Quiz questions available to other modules

by Gustav W Delius -
O.k., compromise solution: I will make the transition in small steps. Rather than renaming all tables at once I will do one after the other and after each step make sure I clean up after myself. I will leave the upgrading of the question tables as well as their backup/restore to the quiz module for now and will also leave the question code in the quiz directory. I can quite undertand your worries about the lack of time before the 1.6 release.

As a first step I will be renaming one particularly badly named table. The table quiz_newest_states will become question_sessions. I'll do this today. I will then wait until the weekend to see if this created any problems before making any further changes.

As far as bug fixing goes, I have made quite good progress over the last few days. One of the bugs (to do with random questions) requires the introduction of a new table which I will now give its proper question_ name from the outset.
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hmm, well..... if you think you can do it.

1) make sure you also upgrade the unicode upgrade code mod/quiz/db/migrateutf8.* ... you need to change all the function names.

2) make sure this works on PostgreSQL!!!

It's terrific to see you working on Quiz again!   approve

In reply to Martin Dougiamas

Re: Quiz questions available to other modules

by Gustav W Delius -
Thanks for the go-ahead. My test balloon, the renaming of quiz_newest_states into question_sessions, seems to have gone smoothly. So unless some problem surfaces before the weekiend I intend to continue to do the migration at a carefully slow pace over the course of the next week.

Currently I am busy with the backup and restore code. Many thanks go to Eloy for long discussions about this.
In reply to Gustav W Delius

Re: Quiz questions available to other modules

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Hi Gustav -

You know my thoughts on this - we spoke about in Savannah.

I'm all for this, especially if we come up with a way to separate out the display code of the questions so that a module can decide to display things differently.

I think this would also necessitate creating a completely separate question manager, in such a way that it can be accessed from any module that uses it.

mike
In reply to Mike Churchward

Question bank manager

by Gustav W Delius -
Mike, it was really nice to meet you in Savannah.

I think the question display should be handled by simple html templates, similar to what Moodle already does with the question editing page. The print_question() function could then be given an optional argument that gives the path to an alternative html template.

You are right, we need a question bank manager that can be used by any module. This will not be so difficult to achieve. In fact we just have to modify a bit the function that is currently printing the right-hand side of the quiz editing page so that it can be called by any module.
In reply to Gustav W Delius

Re: Question bank manager

by Gustav W Delius -
As a first step towards a central question bank in Moodle there is now in 1.6 a link to the question bank editing page in the course administration block, just above the link to the scales editing page. Please let me know if you think that is not such a good idea and I'll take it out of the admin block again.
In reply to Gustav W Delius

Re: Question bank manager

by A. T. Wyatt -
Greetings Gustav!

I think it would be a GREAT idea.  I often want to work on my question pools separately from the quizzes, especially when I am building them up prior to using them in any quizzes.  I would very much like a direct link.

atw
In reply to A. T. Wyatt

Re: Question bank manager

by Ray Lawrence -
I can't see anything wrong with this either, however, it's prompted me to flag up what I consider a weakness in the questions area.

At present to review a question bank one must click on each question to view it or click preview. This makes reviewing a lot of questions quite an onerous task.

The option to display all questions in a category in their entirety (not just the question name but the question as displayed in the preview window too) in a single page would be a tremendous step forward in question bank management.

This would not only allow for speedy reveiw of the questions in a category but would also allow make it much easier to organise editng of questions by a panel e.g. the panel looks a the screen together or the page is printed off for review off-line.

A simple one page view would suffice, if it could be paginated even better. smile

Whilst typing it's also occured to me that such a page would be even more useful if it could display the date/time the question was last edited and by whom  - this sort of thing is a basic feature in many areas in Moodle. In this way the management and audit trail for question editing would be greatly enhanced.

Is this a step too far for v1.6?

What do others think about this as an idea?

In reply to Ray Lawrence

Re: Question bank manager

by Gustav W Delius -
Ray, this is a very good suggestion. This preview feature has been requested before. The user interface could be a "Preview" button below the table of questions which would open a preview page with all the selected questions. I have entered enter it in the bug tracker as bug 4793 as a feature request with a high priority setting? (The bug tracker now has a new component "Questions" for any bugs or feature requests to do with the question types or the question bank editing interface.)
In reply to Gustav W Delius

Re: Question bank manager

by Ray Lawrence -
Thanks. I think the additional suggestion of the category preview displaying selected questions from the category is a good one too.

If there was an edit icon next to each one this would also be very handy. Voting for the category preview feature now!
In reply to Ray Lawrence

Re: Question bank manager

by Ray Lawrence -
Just a quick thought (and back on topic), by removing the link between quizzes and question categories, what is the impact on publishing categories and ownership of categories (for subsequent editing of questions) - if any?
In reply to Ray Lawrence

Re: Question bank manager

by Gustav W Delius -
The questions and question categories were already owned by the course, not a particular quiz. So there will be no change in this. As before, any editing teacher in the course can edit all question categories and questions owned by that course. There is also no change to how published question categories work.
In reply to Gustav W Delius

Re: Question bank manager

by Ger Tielemans -
Before the quiz grow into Moodle, I toyed with phptest and liked the question overview pages (just the interface, not the backend that stored the images also in the database)
In reply to Ger Tielemans

Re: Question bank manager

by Gustav W Delius -
Yes, one of the advantages of having a central question bank is that we can pool development effort from all modules using it into improving the question bank user interface. It will be useful to get ideas from other programs like phptest.

I registered myself on the site that you linked to but unfortunately I appear not to be able to edit questions. Apparenty I have student privileges only.
In reply to Gustav W Delius

Where to put the questions code

by Gustav W Delius -
I propose to move mod/quiz/questionlib.php to lib/questionlib.php and mod/quiz/editlib.php to lib/questioneditlib.php.

I also propose moving the script for the questionbank editing page out of mod/quiz/edit.php to a new course/questions.php (similar to the editing page for course scales which is at course/scales.php).
In reply to Gustav W Delius

Re: Where to put the questions code

by Gustav W Delius -
And there are more quiz-independent scripts that are currently in the quiz module folder and should be moved. Here is the complete list (for the moment):

category.php to course/questioncategories.php
export.php to course/questionexport.php
import.php to course/questionimport.php
question.php to course/question.php
preview.php to course/questionpreview.php
part of edit.php to course/questions.php

questionlib.php to lib/questionlib.php
editlib.php to lib/questioneditlib.php
format.php to lib/questionimexportlib.php

And finally the whole directory mod/quiz/questiontypes should be moved, probably to a top level directory called 'qtypes' or 'questiontypes'.
In reply to Gustav W Delius

Re: Where to put the questions code

by N Hansen -
Gustav-A related issue that has always bothered me is that when I go to create (or edit an existing quiz), the first category of questions I ever created is shown by default-in my case questions for 'exercise 3'. I would rather no category is shown at all by default as if I open exercise 9's quiz to edit it, I am shown the exercise 3 questions. I may not be paying attention, and I start creating new quesitons for exercise 9, only to realize later that I am creating them in the category for exercise 3. Being forced to choose the category each time would stop this problem.
In reply to N Hansen

Re: Where to put the questions code

by Gustav W Delius -
Nicole, I can't see how your suggestion is related to the issue of where to put the questions code. I think it would be better if you started a new thread with your suggestion.
In reply to Gustav W Delius

Re: Where to put the questions code

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I'm all for rationalization, but please, please try to scope out all the possible problems before starting on CVS. If Moodle 1.6 is delayed considerably because of problems raised by renaming these things I'll be unhappy.

Of course if it's delayed by the stuff I'm working on then you get off scot-free. wink

On the location, I don't think "course" is appropriate. You're adding "question" to all these filenames to make them separate from the other files. It would be much better to have moodle/question I think.

lib/questionlib.php would be fine for all the core and the API stuff that modules use.
In reply to Martin Dougiamas

Re: Where to put the questions code

by Gustav W Delius -
Great, moodle/question/ is a good place for the question scripts. I was worried you might not want to have another top-level directory.

One thing I never understood is how to decide where the library files go. Grades have their library in grade/lib/ and calendar in calendar/lib/ so I think it would be appropriate to keep the question code libraries in question/lib/. Do you agree?

I am going to make the move in small steps so that every night things will be back to working order. This may mean that we may not achieve the most rational location for all code already for Moodle 1.6. But things will have moved in the right direction.
In reply to Gustav W Delius

Re: Where to put the questions code

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Calendar and Grade were both developed by others and mistakenly put those libs there. We should fix those eventually.

Please put all the interface code in lib/questionlib.php (ie the API that other modules need to use questions) and help me set a good example. smile Any local libraries that questions use INTERNALLY only should be in moodle/question/lib.php
In reply to Gustav W Delius

Re: Where to put the questions code

by Ne Nashev -
simple rule: lib used in only one module is in /mod/module/lib folder, but if library will be used more then one module - it must go to moodle /lib/ folder. Is it correct?
Average of ratings: Useful (1)
In reply to Martin Dougiamas

Re: Where to put the questions code

by Gustav W Delius -
I am now almost ready to move the quiz-independent question code to moodle/question/ and moodle/lib/questionlib.php. I am planning to simply delete the files in the old location and add them in the new ones. That is not ideal as there will be a break in the CVS history, but as I understand CVS there is no mechanism for moving files. Is that correct?
In reply to Gustav W Delius

Re: Where to put the questions code

by Gustav W Delius -
In Moodle 1.6 the quiz-independent question code has now been moved to the new moodle/question/ directory and the question library functions are in moodle/lib/questionlib.php. Clearly this will have an impact on other projects that have been using quiz module code. There will be more such changes in the coming days. I will then summarize the changes to make it easier to adapt other code accordingly.