Lesson

Batch conversion of question pages to content pages

 
 
Picture of Adam Dudczak
Batch conversion of question pages to content pages
 

Dear all,

I have a quite large course which consists of more than 30 lessons. Each lesson contains several question pages which does not end-up with a question. Course was originally developed using Moodle 1.98. Some time ago, we've migrated to Moodle 2.4, conversion from the legacy format went quite smoothly with one exception.

When I want to modify question page without the real question, Moodle asks me to provide answers. I know that I can create a new Content Page and copy the content of old question page there, but I cannot imagine doing this for several hundreds of question pages without questions in the whole course.

Is there a way to perform batch, automated conversion of question pages without answers to content pages? 

Thanks in advance.

 
Average of ratings: -
Picture of Joseph Rézeau
Re: Batch conversion of question pages to content pages
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Adam,

I think your question is related to this discussion: Create Content Page link missing from lesson edit 1.9.

Unfortunately there is no easy solution for your problem.

Joseph

 
Average of ratings: -
Picture of Adam Dudczak
Re: Batch conversion of question pages to content pages
 

Thanks for linking to this post.

You wrote that there is no easy solution, but is there any hard one? (apart from performing conversion manually).

Maybe it would be possible to tweak db a bit and change module type in db, do you think this is possible?

 

 
Average of ratings: -
Picture of Joseph Rézeau
Re: Batch conversion of question pages to content pages
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

I'm afraid there is no "hard way" either...

 
Average of ratings: -
Picture of Adam Dudczak
Re: Batch conversion of question pages to content pages
 

Do you have an idea what is the easiest way to implement such a conversion? 

It seems to me that it would be best to make it a part of backup restoration. If Question Page does not have associated answers restoration should create a content page instead. 

Can you (or anyone else) point me to the relevant Moodle module, were this kind of tweaks can be made?

 
Average of ratings: -
Picture of Adam Dudczak
Re: Batch conversion of question pages to content pages
 

Ok, I have come up with the following steps which solves my problem. I will try to write a small app which will process moodle backup file and convert all question pages without answers into content pages.

1. for all ./activities/lessson*/lesson.xml look for <page> element with qtype = 3 and empty answers tag

2. for each selected page element change qtype = 20, layout = 1, display = 1 and paste the following markup into answers.

<answer id="[seq()]">
  <jumpto>-1</jumpto>
  <grade>0</grade>
  <score>0</score>
  <flags>0</flags>
  <timecreated>[now()]</timecreated>
  <timemodified>0</timemodified>
  <answer_text>[i18n - continue]</answer_text>
  <response>$@NULL@$</response>
  <answerformat>0</answerformat>
  <responseformat>0</responseformat>
<attempts>
</attempts>
</answer>

seq() - returns a number which is used for id. I start with analyzing the whole dump in order to get info about the highest id used for <answer tag.

I've checked this aproach on my course by making manual changes and it seems to work well with moodle 2.4. 

What do you think about this kind of solution?

 

 
Average of ratings: -