In order to do this in a sane way, I cleaned up a lot of old mess,
inclduing:
1. Previously, qtype_calcuated used ->answeres when importing, and
->answer when saving the form. This was crazy, so I fixed it, and
stripped out the code that made the alternative variable name work.
2. Similarly, it could handle ->answer being either an array, such as
you would get form the HTML editor, or a simple string, which is what
you get form the form. I simplified that too.
3. Finally, I made import use a transaction around saving each
question, so we don't get half questions in the database when an error
occurs.
Adds a set of options to the essay question type which implement
the following new features:
-Adds an input format which accepts only file uploads, and no
inline text.
-Adds an option to make the inline text response optional when
attachments are enabled, so students can choose to upload
an essay file.
-Adds an option to make attachments required, so essays without
attachments will be marked incomplete.
The problem was with the non-UTF-8-safe way that a question name
was being constructed from the question text.
I have done a proper fix with methods in the base class to
carefully construct a question name that is reasonable, and
which will fit in the database column. Then I have changed all
importers to use the new methods.
I also remembered not to break the lesson in the process.
Using consants to refer to plugin names is crazy. The whole point of
plugins is that you can install more, hence the list of constants will
never be complete.
Sadly, this involves a small API change, but I don't believe anyone was
using the argument I had to remove (because we were sometimes passing a
wrong value, and there is not way to compute the right value at that
point in the code.)
Also sadly, the code to compute the context we are importing into is now
rather spaghetti-like, but it works.
This applies to:
1. Upgrade from 1.9,
2. Import of questions exported from 1.9, and
3. Restore of courses backed-up from 1.9.
It also applies to the calculated question type.
The new logic is that the questiontext defaults to HTML if the format is
not specified, then all other fields default to the same format of the
question text.
However, good practice is that the XML file should specify the format
for each bit of text content.
This code is not 100% backwards-compatible, since some methods have new
arguments, however for question types that have not been updated, it
will just generate a PHP Warning, which is, I think, and OK way to let
qtype developers know that they need to update their question types.
This commit also includes a lot of useful tidying up of some of the unit
test helper code. I turned out that I could not use all the helper code
in my new tests, but despite that it will be useful in the future, so I
am committing it here.