Web services is still a work-in-progress. See MDL-29934 for the list of functions that are planned to be implemented some time. Perhaps more specifially, see MDL-30081 which seems to be being worked on now
More generally, see http://docs.moodle.org/dev/How_to_contribute_a_web_service_function_to_core for how you can help if there is a missing web service that you want so badly that you are prepared to implement it yourself.
Otherwise, if you need to create a course category, you may need to write it yourself. The general algorithm for solving this sort of problem is:
- Work out how you add a course category through the Moodle UI.
- Hence work out which PHP script does implements that.
- Read that code, stating from the UI script, to work out what it does.
- Pray that the back-end code is a nice library funtion that you can call, rather that just being a chunk of code you have to copy and paste.
I followed Tim's advice and rewrote uploadusersandcourses.php and uploadusersandcourses_silently.php you will find in these forums taking uploaduser.php already present and combining it with code out of cron.php to run it in silent mode during night.
So actually we export our course-names and teachers and students to enrol into a utf-8 CSV-file. We put it onto a windows-share that I mount in my SUSE Linux box. A cron job starts my uploadusersandcourses_silently.php once a night processing our csv-file as input like you would do in the GUI. Indeed my uploadusersandcourses.php can be used directly through the GUI like uploauser.php, as I integrated it into the admin/users/accounts menu and it does exactly the same thing that the _silently version does, which is handy for developing and testing until you are ready to launch the unattended job.
I developed for 1.9 but it could be rewritten for 2.x easily taking again uploaduser.php already present.
I will start migrating to 2.x by end of this year, if you want to wait until I finish my 2.x versions.
Rosario
My code does not create categories though, but puts the courses in already existing ones, as in our use-case the school administration system does not reflect the hierarchy we created in Moodle. Have a look here to get an idea:
https://moodle.fhnw.ch (use my siteNavigation Block which is open also to not logged in users)
But this code could be copied from the built in create category code.
Rosario
Hi,
this is certainly possible, though not well documented. In our installation, we're using the backup/restore API to programmatically create courses - there's a template course that is backed up, then restored as a new course. After restoring, we then modify some course settings directly in the DB.
We create categories by inserting the records directly into the DB. (Maybe not too sophisticated, but the table structure is quite simple.)
If you're interested, I can post our code, but it's not really prepared for redistribution (i.e., it may be full of dirty hacks as well).
Henning
Hi Henning, yes please post your codes so that we can all learn from each other here. Thanks a bunch!
By the way, a quick side question. Is there a quick and easy way to export all the course categories (and empty course shells) from one Moodle server to another? We spent a lot of time creating a lot of course categories on our testing server and most of the course shells right now under each course category are still empty. We would like to figure out a way to quickly migrate all the course categories from one server to another one. I'm thinking that we probably need to deal with the mdl_course_category and some other DB tables. Please let me know if anyone know of a quick and easy approach to get this task done. Thanks!
I've been making heavy use of the import & export (backup & restore) functions to support multiple offline Moodle servers. The easiest way I've found to do it, is to build a shell course and populate it with general content used across all courses and create a backup of it. Then using the restore function you can select everything within the backup, or individual pieces of content to be restored. The restore options also include merging the content into existing courses, or creating entirely new courses. Depending on how you arrange your content, it can be very easy to copy specific items between courses, or create whole new courses.
Be aware though, that anything by the same name that already exists within a course will cause problems if you try to merge a duplicate piece of content into an existing course. I've seen this particularly with user accounts that exist on each of the separate servers.