moodle 2.1 question engine :: renderer info

moodle 2.1 question engine :: renderer info

by Joseph Rézeau -
Number of replies: 31
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Tim. In the course of re-factoring my REGEXP question type for the new 2.1 question engine I have the following problem...

For each REGEXP question, a "Hint button" feature enables the student to "buy" a letter. Once that Hint button has been pressed and a letter added to the question input field, the Hint button is disabled until the student presses the Check button. That is to prevent successive clicks on the Hint button without incurring penalties...

In the Question preview mode and in quiz mode with ONE question per page, this works fine. However, I have a problem when there are more than one question per page (either of the REGEXP type or any other type).

When the Hint button has been pressed and disabled, the only Check button that I want to re-activate that Hint button is of course the one pertaining to the (REGEXP) question with the disabled Hint button. I cannot achieve this, because in my question renderer.php I see no way to find out which of the Check buttons on the page has been pressed. The question_attempt parameter passed to the formulation_and_controls that I over-ride in my renderer does not contain that info.

What should I do?

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: renderer info

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In reply to Tim Hunt

Re: moodle 2.1 question engine :: renderer info

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Tim,

Which part of that discussion should I be looking at, more specifically? And do you mean that what I wish may be possible ... or not?

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: renderer info

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, all of it.

It sounds like you want to have exactly the same conversation that I had with Oleg.

You need to understand the division of responsibility between question types and behaviours.

In reply to Tim Hunt

Re: moodle 2.1 question engine :: renderer info

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Tim,

I have read the discussion with Oleg on the Quiz forum. With the help of Jean-MIchel I have set up a special "regexp" behaviour, based on Adaptive, and put my "Hint" button in that behaviour's renderer.php file. My "Hint" feature will add the next correct letter to the student's actual input. It has nothing to do with the "Hint" feature used by the Interactive behaviour.

So far everything is working as expected, except for the following.

When a student clicks on the Hint button to "buy" a letter, I would like this submit action to do 2 things, besides adding the next correct letter to the input:

  1. Deduct a penalty from the student's current potential "score";
  2. Display in the outcome div something similar like "Buying this letter attracted a penalty of 0.10."

At the moment I am stumped as to what my next step should be. There are - at the moment - no behaviours using that kind of submit button (besides the normal Check button) so I do not know how to "intercept" my Hint button in order to do the calculations and get the display mentioned above.

Help welcome!

Joseph

PS.- the current state of my regexp question for 2.1 is available at: https://github.com/rezeau/moodle-qtype_regexp/tree/wip_behaviour_21

and the associated behaviour at: https://github.com/rezeau/moodle-qbehaviour_regexp

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: renderer info

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Did you see the 'adaptivewithhint' behaviour code I attached to one of the posts in that thread?

Also, look at the way adaptive uses a -_try variable to track the number of times the student has clicked check, and then uses that in the score calculation. You probably need a -_hintsused variable.

In reply to Tim Hunt

Re: moodle 2.1 question engine :: renderer info

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

I had indeed seen the 'adaptivewithhint' behaviour code you had attached to your post here.

Unfortunately, when I install it on my 2.1 moodle and go to moodle/admin/qbehaviours.php it gives an error:

Fatal error: Cannot redeclare class qbehaviour_adaptive in Unknown on line 0.

Diagnostic and fix: in file adaptivewithhelp/behaviour.php, the first line:

class qbehaviour_adaptive extends question_behaviour_with_save {

shoud read:

class qbehaviour_adaptivewithhelp extends question_behaviour_with_save {

I know you mentioned in your post that that code was untested. I will try anyway to get inspiration from it and report here my findings & questions...

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: renderer info

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Tim!

Finally managed to understand how to use your 'adaptivewithhint' behaviour. It's doing (almost) exactly what I want, for my REGEXP question type.

I had however to make a few modifications to your files, and am attaching them for you to see. I do not understand why one would need

interface question_automatically_gradable_with_help extends question_automatically_gradable

and I have changed

class qbehaviour_adaptivewithhelp extends question_behaviour_with_save

to

class qbehaviour_adaptivewithhelp extends qbehaviour_adaptive

because I think the Adaptive behaviour is the most suited to base adaptivewithhint behaviour on.

In my regexp/question.php file I have added (thanks to Jean-Michel):

public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
        if ($preferredbehaviour == 'adaptive') {
            return question_engine::make_behaviour(
                    'adaptivewithhelp', $qa, $preferredbehaviour);
        }
        return question_engine::make_archetypal_behaviour($preferredbehaviour, $qa);
    }

and, of course the 2 needed functions:

public function get_help_penalty()

and

public function get_extra_help()

I will shortly update my github repository to reflect the current state of the regexp question.

Many thanks for your help! I hope Oleg will find it useful as well.

Joseph

PS.- Feel free to rename this discussion and move it to the Quiz forum if you think it would be better placed there.

In reply to Joseph Rézeau

Re: moodle 2.1 question engine :: renderer info

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes. class qbehaviour_adaptivewithhelp extends qbehaviour_adaptive is right, and the rest sound plausible. Well done. Sorry, I have not looked at the code yet.

P.S. It woud be good to move this thread to the quiz forum, but I don't have moderator permissions here.

In reply to Tim Hunt

Re: moodle 2.1 question engine :: renderer info

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thread moved from the general developer forum to the quiz forum as requested.

In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Tim,

I have finished updating my regexp question type for 2.1 and, based on the adaptivewithhelp behaviour files you kindly provided, I have created 2 new behaviours: regexpadaptivewithhelp and regexpadaptivewithhelpnopenalties. I went for the solution of behaviours dedicated to the regexp question type for 2 reasons: a) easier to maintain for me and b) easier to understand for those moodlers who will want to install the regexp question type plus its two associated behaviours.

In the new Moodle plugins repository, however, things are complicated for plugins which are comprised of more than a single folder. I am going to have to register 3 separate "plugins": my regexp question type (for 2.1); the regexpadaptivewithhelp plugin and the regexpadaptivewithhelpnopenalties plugin.

Regarding the behaviours plugins, the standard moodle behaviours do not contain a version.php file, which is required when registering a plugin. I expect I'll have to add a version.php file to both of my behaviours' folder?

What's your advice?

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The behaviours should have a version.php file. (Actually all plugins should, and they will probably start enforcing that soon. I have MDL-29808 to remind me to do that before the 2.2 release.)

See also MDL-29474. There should soon be a way for you to declare that your plugins require other plugins to be installed, and the install/upgrade code will verify that.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks, Tim. I registered my 2 behaviours and am waiting for approval.

Now I have encountered another problem, when trying to register my regexp question type. I get this strange warning:

Table(s) names question_regexp defined in db/install.xml do not start with qtype_regexp.

Why should my question_regexp table name start with qtype_regexp ???

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It is about making sure that two different plugins do not try to define a DB table with the same name. The way to do that is to say that the tables for each plugin must start with the internal plugin name. In this case that is qtype_regex.

I know that, historically, question types have used tables with names starting question_, but we should change that. You will not that in Moodle 2.1, the essay question type uses a table called qtype_essay_options.

Some time, I will rename all the core question type tables to match the new naming scheme, but I am going to wait until they say something like "to upgrade to Moodle 2.3, you must already have Moodle 2.2", because that gives us a clean break in the upgrade process at which to make the change.

To make your plugin obey the rules, you should just have to:

  1. Search-and-replace question_regex -> qtype_regex_options where it is the table name.
  2. Write an upgrade step in db/upgrade.php to rename the existing table.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks Tim,

I'll do that,

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

By the way, Joseph, did you publish any articles (or book, or whatever except Internet sites) on you question type? I would like to add references on them to my articles when comparing our questions...

In reply to Oleg Sychev

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Sorry, Oleg, I do not have anything published in Journals about the regexp question type. But I used a similar type of question with analysis of the student's response when I was writing my PhD thesis. My thesis (in French) can be found:

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

The latest version of the regexp question type, with "help" feature based on question behaviour is now available from the new moodle plugins repository here:

http://moodle.org/plugins/view.php?plugin=qtype_regexp

and the two associated question behaviours from here:

http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelp

and

http://moodle.org/plugins/view.php?plugin=qbehaviour_regexpadaptivewithhelpnopenalty

Looking forward to tester's remarks, bug reports, suggestions, etc.

Note.- Needs Moodle 2.1.2 version 2011070102.03

In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Jean-Michel Védrine -

Hello Tim,

This is rather bad news for people working on a lot of question types because it means we must spend some time on perfectly working plugins just to satisfy this new rule and I don't beleive the issue of "2 plugins using the same table name starting with "question_" has anything real !

In reply to Jean-Michel Védrine

Re: moodle 2.1 behaviour for regexp question type

by Jean-Michel Védrine -

Tim,

Is this rule about qtype tables names also valid for Moodle 2.0 questiosn types ?

If yes I have some trouble to find a way that upgrade works from all 2.0 versions (both with question_ and qtype_ names) to all 2.1 versions (both with question_ and qtype_ names) ?

Of course $dbman->table_exists can be used, but even with that, if people using a 2.0 version with qtype_ names try to upgrade to a 2.1 version with question_ names it will make a big havoc !!

I see no perfect solution.

 

In reply to Jean-Michel Védrine

Re: moodle 2.1 behaviour for regexp question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

We should probably get them to relax the rules for qtype plugins. If you file a MDLSITE bug in the tracker, I will vote for it.

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

Joseph, you don't seem to make any new behavours inherited from the interactive behavour.  Why? Does hinting and hinting penalties works  OK with interactive without writing new behavour, or you didn't think hinting should work in interactive mode, or why?

That's no idle question, I'm still looking to continue porting preg question for 2.1 when I got all urgent busyload dropped on me this October off.

In reply to Oleg Sychev

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

@Oleg,

My regexpadaptivewithhelp (and regexpadaptivewithhelpnopenalty) behaviours are based on adaptive behaviour, and developed from the adaptivewithhelp sample behaviour posted by Tim.

Tim (and Jean-Michel) convinced me that using a new behaviour was the best way to deal with a hint/help button (to add a letter "bought" by the student.

Just today I am registering my newly updated regexp question type (using those behaviours) and the behaviours themselves in the new moodle plugin repository. When those 3 plugins are approved (any time soon, I hope) you will be able to experiment with them and - hopefully - get some idea how to use the behaviours or base your own behaviours on them for your preg question type upgrade to 2.1.

Or you can go to my github:

https://github.com/rezeau/moodle-qbehaviour_regexpadaptivewithhelp

https://github.com/rezeau/moodle-qbehaviour_regexpadaptivewithhelpnopenalty

https://github.com/rezeau/moodle-qtype_regexp/tree/MOODLE_21_STABLE

Joseph

In reply to Joseph Rézeau

Re: moodle 2.1 behaviour for regexp question type

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

Joseph, what I am trying to ask is did you consider interactive behavour that is supposed to take over adaptive (which is somewhat deprecated judging by Tim's remarks) ?

If I understand correctly, interactive behavour also allows multiple attempts at a question and so hint functionality should work there too. But you seem to work only on adaptive. Why?

In reply to Oleg Sychev

Re: moodle 2.1 behaviour for regexp question type

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Well, interactive behaviour is using Hints, but in a totally different meaning than what you and I call "hints", which are actually letters "bought" by the student by clicking on a "hint" or "help" button.

So I found that "adaptive" was the best suited behaviour to base a "help button" feature on.

Joseph

In reply to Oleg Sychev

Re: moodle 2.1 behaviour for regexp question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think it was reasonable for Joseph to start with making Adaptive work, because that was working in 1.9/2.0.

I do hope that in time, we can abstract the adaptivewithhints behaviour, so that it can by used by any appropriate question type, but it is perfectly reasonable to something that works in one specific case before we try to generalise it. At least, that is one way to end up with a general solution.

I hope that in time we can build a version that works with interactive mode too. The issue is that interactive is built around teacher-entered hints, and regex uses automatic hints. The two will have to be reconciled somehow. I am sure that is possible but it is not as simple as adaptive, where there was already a working system that just had to be copied in 2.1.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

Tim wrote "I do hope that in time, we can abstract the adaptivewithhints behaviour, so that it can by used by any appropriate question type" - yes, I'm feeling a bit weird about developing similar behavour to ship with my qtype....

By the way, didn't that lead to us that qtype should have possibility to harbour it's own behavours in it's folder? If any new qtype would add it's own version of adaptive behavour, behavours folder may become quite clattered on big sites. And it'll be easier to install such qtypes too.

In reply to Oleg Sychev

Re: moodle 2.1 behaviour for regexp question type

by Jean-Michel Védrine -

Rather than having plugin hosts other plugins in their folder wich would IMHO lead to a lot of problems because of the way Moodle manage plugins, and given all the good work that is currently done on plugins dependancies (see for instance MDL-29474 and MDL-29945) a far better solution would be to have the ability to upload a zip file containing not only a plugin but also a collection of plugins and an admin function that would unzip it and install the proper files in the proper location. A lot of softwares do that (since many years), why not Moodle (most probably because of the false assumption that Moodle is for administrators that knows what they are doing and would certainly not put a file in the wrong place wink) ?

It would help a lot of Moodle users and save a lot of threads in the forum where an user ask for help and we need first to make sure files are in the right place !

In reply to Jean-Michel Védrine

Re: moodle 2.1 behaviour for regexp question type

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If Moodle code can modify other Moodle code (which is what the admin function you suggest requires) then many security problems suddenly have a much more serious possible outcome.

What is being talked about is a an admin tool that will contact the modules and plugins database, and tell you all the plugins you need to update. It may even download the required new files into moodledata for you. However, the final step of copying the new files into the moodle folder should remain something done by a separate agent with correct access rights to the code on the server, not by Moodle code.

Of course, if someone wants to write a riskly automatic-update script, then they can, by making a third-party admin tool plugin.

In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Jean-Michel Védrine -

Hello Tim,

I know well that following "Moodle etiquette" when a developper says "No ! security risk !" I should no insist wink.

But I am quite sure that we both know very respectables php/MySQL softwares that does this and does it in a very secure way. As always security is more a matter of how you do things than a matter of things you do.

The tool to look after updates will be very usefull, but I stay convinced it would be possible to improve a lot plugin installation and to do so in a secure way. The number of messages in these forums from users having trouble installing plugins supports this.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: moodle 2.1 behaviour for regexp question type

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers

I don't think there is a reason to add automate script for it. Admin could done it manually.

All you should actually do is allowing to upload zip's that duplicates necessary part of moodle folder tree, so I could put my questions in question/type/ subfolder of zip and behaviours in question/behaviour.

Than you just could unpack this archive in root folder and get all. It would be sensible to let validator check that such archive contains files only in subfolders specifically created to hold plugins.