Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Backup 2.0 course report data

From MoodleDocs
Revision as of 11:39, 23 May 2011 by sam marshall (talk | contribs) (Created page with "{{Template:Development:Backup 2.0}}{{Moodle_2.0}} == Introduction == In Moodle 2, course reports can have data tables and files which can be backed up with a course. (To create...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Development:Backup 2.0Moodle 2.0


Introduction

In Moodle 2, course reports can have data tables and files which can be backed up with a course. (To create data tables in a course report, use the standard db folder.)

None of the standard course reports have any course-related data so it is not obvious how to code the backup and restore for them. This page gives an example theme as a case study which you can use to implement your own backup code for a course report which contains per-course data.

Note: Course report data backup requires Moodle 2.0.4 or later.

Example: the 'lazystudents' report

As an example I am using a theoretical report which checks the time that each user visits Moodle on each day over the past week. The report produces a list of students who did not access Moodle before a certain time on any day last week. For example, this might include all students who never accessed Moodle before 10:00 on any day last week.

The report has two configuration options which can both be set per-course:

  • The hour after which students are considered 'lazy' (e.g. 10).
  • A custom image to display with the report (e.g. some courses might prefer a tortoise picture while others prefer a sloth).

The hour is stored in the table coursereport_lazystudents which has 3 fields id, courseid, and lazyhour.

The image file is stored using the Moodle file API at the course context, in the coursereport_lazystudents component and the image file area.

Backup

The backup code is in the file course/report/lazystudents/backup/moodle2/backup_coursereport_lazystudents_plugin.class.php. Leaving out the headers, this file looks like:

(WORK IN PROGRESS)