Writing a metacourse linking script

Writing a metacourse linking script

by Mike Worth -
Number of replies: 4
For my moodle installation I am looking to create a 2 level hierarchy from the data held in our MIS. This holds data about courses, within which are classes. I want to create metacourses for each MIS course and courses for each MIS class. This will allow a course manager (initially the head of department) to maintain a common resource base for course information while the teacher of each class can run the moodle for their class as they want.

I have found a 'bulk course upload tool' [url = http://moodle.org/mod/data/view.php?d=13&mode=single&page=40]here[/url] which will create the courses and metacourses and allocate teachers OK.

I want to have the courses (MIS classes) linked to the metacourses (MIS courses). I hae had a poke around in the DB and found the mdl_course_meta table which is what I want to play with. It looks like:
+---------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| parent_course | int(10) | NO | MUL | 0 | |
| child_course | int(10) | NO | MUL | 0 | |
+---------------+------------------+------+-----+---------+----------------+

I am thinking that I am going to have to write a script to upload a CSV into an array then lookup the id from the idnumber of each course then insert a row into this table for each link.

I am relatively comfortable with MYSQL and PHP (although it's been a while so I'm probably a bit rusty) but from what I've read it is dighly discouraged to use MYSQL directly to maintain flexibility. I will probably release this code when I'm finished and may well require help along the way so I think I'll try to stick to these guidelines.

What are the moodle functions for [select id from mdl_course where idnumber = $idnumber] and [insert into mdl_course_meta values(null,$parentid,$childid)]. I assume the mdl_ prefix is found in config.php somewhere


Thanks,
Mike
Average of ratings: -
In reply to Mike Worth

Re: Writing a metacourse linking script

by Mike Worth -
Well I decided to get on and write something- it's not a brilliant job but seems to work. It doesn't use any moodle functions- just directly accesses the mysql database directly. It takes a csv containing the idnumbers of parent,child with a new row for each link (and no header row).

Due to the lack of user authentication and validation it is a security risk- I used it and have now set permissions to 600 (user root) meaning that it is no longer available to the apache user; in order to use it this must be set back to 644.

Mike
In reply to Mike Worth

Re: Writing a metacourse linking script

by Mike Worth -
Well I've been doing more fiddling and have made a script that will take 3 CSVs that contain information regarding links between metacourses and their child courses, links between tutors and their tutees and to import attendance data. I am happy to provide this along with documentation if anyone is interested.

It is all still mysql only direct database access without authentication (I am planning to run from cron with CSVs being pulled in each night)

Mike
In reply to Mike Worth

Re: Writing a metacourse linking script

by Christoph Ruda -

Hi Mike,

I'm trying to implement a similar structure, and I had consoled myself to accept that I had to assign the child courses by hand at the beginning of the academic year. My thinking was, that once this was done I would keep the child courses up to date on a regular basis. What I found though is that the link between the child course and the meta course doesn't seem to be dynamic, meaning that adding students to or removing them from the child courses has no effect on the meta course.

Is this correct, and does you script deal with that issue?

Many thanks.

Christoph

In reply to Christoph Ruda

Re: Writing a metacourse linking script

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Christoph - Sorry for the delay in responding as I am playing catch up. I suspect you may have already discovered that once cron runs it should update the enrollment for the metacourse to match the children courses. So it may not seem instantaneous but it should happen reasonably quickly. If it is not, let me know. Peace - Anthony