I'm trying to automate the process of building courses from an external system, by inserting records into the moodle database. My courses are fairly standard - they are topic based. My external system holds the names of the courses, the names of all the topics, and details about the activities for each topic. Each topic has a fairly standard block of html as its description, and has a set of activities that require each previous activity to be completed before the next one is made available. Building this through the interface tools is a tiresome process. The activities are like "Label, Page, Resource, Quiz" or "Label, Resource, Label, Resource, Quiz" or "Label, Resource, Assignment".
My current method is that I build a template course with more topics than I will need, manually set up all the activities for each topic, then manually adjust the conditions for each activity to require completion of its previous. When I need a new course, I clone (import from) the course from my template, then go through and delete the excess topics, which means deleting their activities too. Then going back through each page anyway and changing the text to match the topic text.
I'd much prefer to be able to either create the data directly in the database, or generate and run some SQL that builds my course (as there appears to be no import-from-csv or that type of plugin around).
I've studied a few ERD's for the database, and also fiddled around with blank databases watching what goes where when I add a course the way I want to structure it, and I'm finding some parts a little tricky to figure out. Finding and reading the PHP for a given tool doesn't always reveal how the data hangs together either. I've been finding /admin/tool/generator/locallib.php quite handy, but it's not the whole story for me.
here's what I know:
mdl_course_sections holds the topics. "section" indicates the order, and "sequence" indicates the id's of the mdl_course_modules records.
mdl_course_modules lists the activities in the course. "module" represents the mdl_module id. "instance" represents (I think) the row id for the particular type of table matching the "module" id. I'm not sure what "section" represents - it might be a backreference to the mdl_course_sections table's "id" column. Any one know?
mdl_module stores the type of activity. It seems that this matches loosely to a table named "mdl_" plus the value in the "name" column. So for type 13 (label) there would be a table named "mdl_label".
mdl_resources has a "displayoptions" column that stores some data that looks like this: a:2:{s:12:"printheading";i:0;s:10:"printintro";i:1;} - not really sure what any of it means but it's obviously structured.
I'd tried to put in some records in. For my blank course, I've put in some course_section records, matching them to course_module records and recording their "sequence" field. In the course_modules I've matched the "module" to the "modules" table for the type of activity I want, and added labels, resources and other rows for the matching tables (recording the id's in the course_modules.instance column. course_modules.section I'm still not sure about - I've put these in as the id of course_sections for now, since I can't see an obvious other table for them to match to. I've set course_modules_availability so that my activites all rely on the previous item to be completed (by setting coursemoduleid = current, sourcemid = previous item, requiredcompletion = 1).
In my course, I get to see the topics with their correct headers and descriptions. I get to see the "resource" activity for each of the topics, but don't see any other type of activity - in this case I've tried to put a label first, then a page with some custom html on it, then a resource which is a file. The data seems to indicate everything is ok. If I edit the topic and save it again, nothing appears to change in the db and the activities still do not appear. Purging the cache doesn't seem to make them appear either. So there must be a process that has to be run or a database field somewhere else that I have missed that makes these things work. Anyone have a clue about this?
Has anybody come up with an external way to build courses? The developer docs are particularly shy about talking about the structure of courses and their activities, as are most of the ERD's I've read.