Copy of course

Copy of course

by Honorata Xyz -
Number of replies: 14

Hi all it is possible to make a copy of existing course? I DONT wanna make:

- a new course on a new Moodle or

- change name of course when I'am replicating on an existing Moodle and then restore it as a new course or

a new course, then  create new blank course, then import the files of the previous course.

I need a new instance/copy of course - example: all student are enroll to course A, but I wanna that each one of them get his own copy of course A, so I can change order of section in this course. Student 1 has order of section 1,2,3 ; Student 2 has order 2,3,1 and Student 3 has order 3,2,1. All students are in this same group and can see eachother and communicate like in normal course. What should I make to do this? Any clues?

Average of ratings: -
In reply to Honorata Xyz

Re: Copy of course

by Rosario Carcò -

I do it with a script I developed fo rmy needs: uploadusersandcourses.php

But technically speaking you have to:

- create a blank course

- import an existing cours-backup-zip-file

Those two steps combined in my script gives the illusion of creating a copy on the fly. But theoretically there is the possibility to use the restore-backup-API with all the needed parameters you choose in the GUI to restore a given course to a NEW COURSE in a CATEGORY you select there.

Rosario

Average of ratings: Useful (1)
In reply to Rosario Carcò

Odp: Re: Copy of course

by Honorata Xyz -

Tnx for reply, but you are writting about mine 3rd solution which doesn't solve my problem. Fortunately I found good solution.

In reply to Honorata Xyz

Re: Odp: Re: Copy of course

by Rosario Carcò -

HOW do you do it? In the GUI manually or with a script like mine? Using a script means automating a process, so using my script you will not notice whether it which of your ways it goes, you will only notice the finished result, which is the course copy you want.

Rosario

In reply to Rosario Carcò

Re: Copy of course

by Jocelyn Ireson-Paine -

Hi Rosario,

I'm going to need to do something similar. In our Moodle, we will have a collection of courses written by experts and saved as course backups. We want new Moodle users (teachers or managers) to be able to copy these, then add their own teachers and students. We'd be doing this via Web services. So am I right in saying that there is no built-in Web service that copies a course from a backup, and nothing in OKTech's Web services either? At least, I've looked in both and couldn't see any relevant functions.

So I need to write my own Web service. I read the latest version of your script, and from it, I see that my Web service has to call import_backup_file_silently from /backup/lib.php. Its specification being:

* import_backup_file_silently($pathtofile,
* $destinationcourse,
* $emptyfirst=false,
* $userdata=false,
* $preferences=array())
*
* From the corresponding X-REF:
* this function will restore an entire backup.zip into the specified course
* using standard moodle backup/restore functions, but silently.
* @param string $pathtofile the absolute path to the backup file.
* @param int $destinationcourse the course id to restore to.
* @param boolean $emptyfirst whether to delete all coursedata first.
* @param boolean $userdata whether to include any userdata that may be in the backup file.
* @param array $preferences optional, 0 will be used. Can contain:
* metacourse
* logs
* course_files
* messages

Cheers,
Jocelyn

In reply to Jocelyn Ireson-Paine

Re: Copy of course

by Rosario Carcò -

Yes, that's the piece of API I use also in my script. I know that for Moodle 2.x sort of a Web-Service is planned, but I have no clue how far this is developed yet. I continue to use 1.9 for other reasons I explained in other posts.

Rosario

In reply to Rosario Carcò

Re: Copy of course

by Rosario Carcò -

Ahhh, by the way: you do not need to write a whole web-service to simply call a Moodle-php-script.

Either you do it by a cron job, like I do, to call my uploadusersandcourses.php script, which is simply using an import-cvs-file to create/copy courses or you call it by web.

Of course, if you call it by web like this: https://yourMoodle.com/admin/yourscript.php, you may want to set up some security measures, so that not everybody is able to call it.

In my case it does not even matter, because my script tests whether the courses already exist and then doesn't do nothing. And the courses to create are read from a windows-share I mount on my linux server. So if there are courses in this file, my script will create them, no matter who calls the script. And if no courses are there, nothing happens at all.

Rosario

In reply to Rosario Carcò

Re: Copy of course

by Jocelyn Ireson-Paine -

That's interesting. Suppose I have courses in backup files F1, F2, F3, ... . Then I want a user U to be able to go to a Moodle control, select one of these files, and copy it into a new course. I can see how to implement that as a Web service; but I'd not thought about doing so via cron. I suppose the cron job would have to run every few seconds. When U requests file F, this would set a flag. The next cron job to run would then detect this, and restore the course. And unset the flag.

Jocelyn

In reply to Jocelyn Ireson-Paine

Re: Copy of course

by Rosario Carcò -

Ok, lets first plan a little bit:

a) you construct a simple GUI piece directly integrated in to Moodle or (as Web-service) on any kind of web-server. Then you need:

  • some kind of list/export of the backup-file-Names your admins or teachers can choose from the courses they want to restore as copies in Moodle
  • the web-gui you would program
  • an interface from your web-service on separate web-server to the Moodle server, the very simplest and oldest way to implement inter-process communication being A FILE with data to process. And that's what I implemented with my uploadusersandcourses.php script: One process (scheduled) exports Courses and Students and Teachers out of our School-Administration-System (which has no standardized format we could exploit in Moodle) into a simple cvs-file in utf8-format. Another process (scheduled) on the Moodle server, i.e. uploadusersandcourses_silently.php reads the data and creates the courses. The columns in my cvs-file are nothing else you need to call uploadusers.php directly in your Moodle GUI extended with other columns to hold data you need to create a course like courseshortname, coursefullname, etc. I integrated even uploadusersandcourses.php into the Moodle GUI, so that you can call it manually directly from Moodle. Here a screenshot:

    uploadusersandcourses

  • hope I didn't forget anything

b) you do not construct any GUI piece, you simply generate your input cvs-file in Excel or any other Sofware. Then you need:

  • Someone administering your backup-file-names and the requests of your teachers (e.g. by sending an email to this person). When there are requests from the teachers to restore a copy of a course, this person writes your cvs-export-file into an area accessible also by a cron-job of Moodle or on any local disk.
  • depending on the workflow of this process, a cron-job (scheduled) reads in the names of the course-backup-files to restore or you click in Moodle on the GUI-integrated script (like my uploadusersandcourses.php in the screenshot)
  • hope I didn't forget anything, ah I was: there is a course request form already integrated in Moodle. You simply have to turn it on and then your Teachers can use it to request courses. This form could display also the list of available course-backup-files, if you really want to program a piece of GUI. The Admins can then trigger the creation of the desired courses manually, or if you tweak this piece of GUI to display the list of available courses, then you could make it write the needed data into a cvs-file, my uploadusersandcourses_silently.php would process every night OR the admins could import using the GUI uploadusersandcourses shown in my screenshot.
  • hope I didn't forget anything now

I guess even that you do not have to program anything if you go to use my uploadusersandcourses.php or uploadusersandcourses_silently.php scripts and do adapt your workflow to anything similar I proposed in a) and b)

Rosario

In reply to Rosario Carcò

Re: Copy of course

by Jocelyn Ireson-Paine -

That's very helpful, Rosario. Thanks for taking the trouble to explain it. Unfortunately, it seems that Moodle 2 doesn't have import_backup_file_silently(). In reply to a post by David Lorente about this, backup_course_silently() and import_backup_file_silently() in Moodle 2.2, Tim Hunt says that backup has changed a lot, because the API has been improved. He tells us to read Backup 2.0 general architecture for an example of code that does backups. I found some code that does restores, in the Moodle directory backup\restore.php , and it no longer calls an import function. One needs, I think, to create a "restore controller", similar to the backup controller shown near the end of Backup 2.0 general architecture. Unfortunately, this does seem to be more complicated... 



Jocelyn

In reply to Jocelyn Ireson-Paine

Re: Copy of course

by Jocelyn Ireson-Paine -

Hi again,

Tim Hunt has just recommended a plugin made by "sam": see http://moodle.org/mod/forum/discuss.php?d=193187&mode=-1 . I'm going to try that.

Jocelyn

 

In reply to Jocelyn Ireson-Paine

Re: Copy of course

by Rosario Carcò -

As I just wrote in the thread where Tim made his recommendations, the file system of Moodle 2.x is certainly for the better (security, consistency, etc.) but it is also for THE WORSE for us programmer and system administrators, as we no longer find the uploaded and backup-zip- files in a course-related directory as it was before.

So everything is more complicated now. I know I will have a lot of headaches when I must rewrite my code for Moodle 2.x (one reason more we stick at 1.9 for the moment)

Rosario

In reply to Rosario Carcò

Re: Copy of course

by Jocelyn Ireson-Paine -

Hi Rosario,

I've started doing this for Moodle 2.2. See http://moodle.org/mod/forum/discuss.php?d=193187&parent=846114 and following posts.

Jocelyn

In reply to Jocelyn Ireson-Paine

Re: Copy of course

by Rosario Carcò -

Thanks for this. I will remember to read it again, when I will port my uploadusersandcourses.php to 2.x

As I said, a lot of headaches...

OOP is great, but you have to pay a big big price until understanding how it works with a certain API. The first API I studied was programming Apple Macintosh GUI with pascal from 1984 on to 1996 when I did it with C/C++. Then I repeated the experience with MS Windows API in C/C++. It was a great experience to write a text editor with mouse support, windows, events. etc. etc. but it was hard to learn. I like the procedural API of Moodle 1.9 a lot even if some OOP Gurus laughed at it and made pressure for Moodle to switch to OOP making it modern and up to date. But I am sure, this will make things very hard for us to learn the OOP-Moodle-API.

You would have to study the built in backup procedures to see how Moodle identifies

a) the course to back up

b) the directories to work in

c) and the restore of a course using a backup-zip-file

In the new file system of Moodle 2.x everything is hashed and saved as metadata in a file-table I guess. So your code has to read and possibly write metadata from and to this file-table.

And you'd better stay in ONE Thread definitively, even if the title is not the best one. We will find your posts thanks to full text indexing, no need to start new threads with "better" titles. This makes it only harder for me and others to follow you and your code and elucidations.

Rosario

In reply to Honorata Xyz

Re: Copy of course

by Rosario Carcò -

You will find the function

public static function duplicate_course($courseid, $fullname, $shortname, $categoryid, $visible = 1, $options = array())

in /course/externallib.php


DID YOU contribute it? Rosario