Moodle

errors in continue.php cause failure to correctly process regular expressions and to display correct classes for responses

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.3
  • Fix Version/s: 1.9.4, 2.0
  • Component/s: Lesson
  • Labels:
    None
  • Environment:
    Windows 2000, apache 2.2.8, php 5.2.5, postgresql 8.3.4, Moodle 1.9.3 build 20081027
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE, MOODLE_20_STABLE

Description

In the lesson module it is possible to specify incorrect answers with their own response, with scores of 0 or less, and to set them to jump to a page other than "this page".

However even with the following settings for the lesson (there appears to be a known problem with incorrect answers failing to display their response text if review is enabled)

allow student review = no
display review button = no
display default feedback = no

The use of regular expressions to evaluate the lesson fails as line 125 of moodle/mod/lesson/action/continue.php treats all pages that jump to somewhere other than "this page" as possible correct responses.

if (lesson_iscorrect($pageid, $answer->jumpto) or ($lesson->custom && $answer->score > 0) ) {

The result is that responses that include the use of ++ to define words that must not appear or – to identify words that must appear are processed without any testing for the use of ++ or – and a php error is generated.

preg_match() [function preg-match]: compilation failed: nothing to repeat at offset 1 in ...

The solution to this appears to be to change the "or" operator to an "and" operator in line 125, after which the test performs correctly.

if (lesson_iscorrect($pageid, $answer->jumpto) and ($lesson->custom && $answer->score > 0) ) {

Further down in continue.php, on line 688 a class for correct responses is defined.

$class = 'response correct'; //CSS over-ride this if they exist (!important)

I don't know a lot about style sheets but in my tests the use of a class name with a space resulted in the class "response correct" being recognised as "response", with the result that all responses were displayed in the class response.

Changing the class name in line 688 to response-correct and in line 692 to response-incorrect will resolve this.

Activity

Hide
Johnathan Kemp added a comment -

With respect to the comments regarding the class names.

I have been looking further into the use of style sheets and now understand how the intended classes are being used (i.e. separate classes for response, correct and incorrect). I can see that this is more flexible but at present it is resulting in some inconsistent markup.

Once the change from "or" to "and" referred to above is made, the processing of ++ and – answers can take place. However the use of classes in the way these answers are handled is inconsistent. If the ++ response is matched then the user answer is returned wrapped in a class "incorrect matches", which results in both the answer and the response text being returned to the user styled as incorrect.

However all other processing of the short answer question fails to wrap the answer in either a correct or incorrect class.

It might be useful to have correct and incorrect answers wrapped in appropriate classes, but if so would it not be better to be consistent in its application?

Kind regards

Johnathan

Show
Johnathan Kemp added a comment - With respect to the comments regarding the class names. I have been looking further into the use of style sheets and now understand how the intended classes are being used (i.e. separate classes for response, correct and incorrect). I can see that this is more flexible but at present it is resulting in some inconsistent markup. Once the change from "or" to "and" referred to above is made, the processing of ++ and – answers can take place. However the use of classes in the way these answers are handled is inconsistent. If the ++ response is matched then the user answer is returned wrapped in a class "incorrect matches", which results in both the answer and the response text being returned to the user styled as incorrect. However all other processing of the short answer question fails to wrap the answer in either a correct or incorrect class. It might be useful to have correct and incorrect answers wrapped in appropriate classes, but if so would it not be better to be consistent in its application? Kind regards Johnathan
Hide
Johnathan Kemp added a comment -

The attached file is a wink demonstration that shows my server environment, the lesson configuration and structure and the results of testing both using the standard Moodle lesson module files with no modifications. The latter part of the demonstration then runs the same tests after the discussed change in continue.php of the "or" to "and" on line 125 has been made.

Show
Johnathan Kemp added a comment - The attached file is a wink demonstration that shows my server environment, the lesson configuration and structure and the results of testing both using the standard Moodle lesson module files with no modifications. The latter part of the demonstration then runs the same tests after the discussed change in continue.php of the "or" to "and" on line 125 has been made.
Hide
Joseph Rézeau added a comment -

Johnathan
I have tested your wink demonstration and am glad to confirm that your diagnostic was correct and the fix you suggest does works, i.e.

in file moodle/mod/lesson/action/continue.php
in line 125
if (lesson_iscorrect($pageid, $answer->jumpto) or ($lesson->custom && $answer->score > 0) ) {
change the or condition to and

I do not have the necessary cvs rights to commit this bug fix myself but I expect the Lesson maintainers will be able to a) check the fix and b) commit it very soon to the various existing versions of Moodle.

Thanks for reporting,

Joseph

PS.- The "class for correct responses" issue you report is not a bug. There is no such thing as a class name with two words in CSS; there are in this case 3 classes: response, correct and incorrect. In one case we are using the 2 classes "response incorrect" and in the other case the 2 classes "response correct" to format the output.

Show
Joseph Rézeau added a comment - Johnathan I have tested your wink demonstration and am glad to confirm that your diagnostic was correct and the fix you suggest does works, i.e. in file moodle/mod/lesson/action/continue.php in line 125 if (lesson_iscorrect($pageid, $answer->jumpto) or ($lesson->custom && $answer->score > 0) ) { change the or condition to and I do not have the necessary cvs rights to commit this bug fix myself but I expect the Lesson maintainers will be able to a) check the fix and b) commit it very soon to the various existing versions of Moodle. Thanks for reporting, Joseph PS.- The "class for correct responses" issue you report is not a bug. There is no such thing as a class name with two words in CSS; there are in this case 3 classes: response, correct and incorrect. In one case we are using the 2 classes "response incorrect" and in the other case the 2 classes "response correct" to format the output.
Hide
Howard Miller added a comment -

I think I got my head around this That should be it fixed in CVS. Does one of you want to double check, please?

Show
Howard Miller added a comment - I think I got my head around this That should be it fixed in CVS. Does one of you want to double check, please?
Hide
Johnathan Kemp added a comment -

Hello Howard,

I have downloaded the latest files from CVS and run my test lesson with the new code.

I can't speak for every aspect of the lesson module, but as far as short answer questions using regular expressions are concerned the lesson module is now performing as I would expect it to.

Thanks for fixing it.

Johnathan

Show
Johnathan Kemp added a comment - Hello Howard, I have downloaded the latest files from CVS and run my test lesson with the new code. I can't speak for every aspect of the lesson module, but as far as short answer questions using regular expressions are concerned the lesson module is now performing as I would expect it to. Thanks for fixing it. Johnathan
Hide
Tim Hunt added a comment -

Closing. Thanks everyone for your help.

Show
Tim Hunt added a comment - Closing. Thanks everyone for your help.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: