Couse and Category Duplication.

Couse and Category Duplication.

by Gary Plumbridge -
Number of replies: 20
Hello.
I've recently been working on some code for moodle 1.6 that is designed to duplicate whole courses in a very simple way for the user, and to duplicate an entire category recursively including courses if the user chooses too.

I was wondering if anybody else would find this facility useful, if so, i'd be happy to improve the code if there are any issues.

Lastly, in order to accomplish this task I wrote a wrapper-library for the backup and restore functions. This alone might be useful to other people as it allows a developer to use moodle's backup and restore in 1 or 2 lines of code.

Please find attached the libraries required, and the User-Interface pages. The user interface pages require an ID parameter. This is either the course ID or the category ID. (depending on the page)

I'll appreciate any feedback!
Average of ratings: -
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Darren Smith -
If I understand the functionality correctly then this would enable me to choose a category and make a copy or everything inside?

If so, this would be superb for archiving courses cool. I have had to do then one by one manually this year sad
In reply to Darren Smith

Re: Couse and Category Duplication.

by Gary Plumbridge -
yes, this is exactly the intended purpose.
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Darren Smith -
Excellent. I will get 1.6 and test this out.

Does it have any other functionality which would aid this procedure? I'm thinking of the option to remove users, files and the like which you get when doing a normal backup/restore of a course.
In reply to Darren Smith

Re: Couse and Category Duplication.

by Gary Plumbridge -
You can chose if you want to include users and their files.
Unfortunatly, there is no easy way to differentiate between teachers and students.

Its purpose for us here was for creating new courses at the end of a year too, so it should contain options that are useful to this task.
Average of ratings: Useful (1)
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Eugene Ritter -
Nice work! We'll be needing a similar feature. I'll take a look at the code. If I can contribute I will.

Thanks


In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Eugene Ritter -
I placed couse files in the course directory and the backupfiles in the backup directory. I went to the course to duplicate. Changed view.php to duplicate.php. Got the dialogue. Entered the information needed. Submitted the form and got the following error:

Moodle 1.5.2

Duplication in progress:
(This may take a while)

Reading existing course...
Warning: Invalid argument supplied for foreach() in /usr2/home/tsrwu/www/moodle/backup/backuplib.php on line 1644

Fatal error: Call to undefined function utf8_encode() in /usr2/home/tsrwu/www/moodle/backup/backuplib.php on line 443
In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Eugene Ritter -
Actually it looks like it is rebelling agianst the absence of my XML - PHP extension. Will be adding it.tongueout
In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Gary Plumbridge -
ok smile
This looks like the backuplib is unhappy with the way I use it.
I'd of course be interested to know if you fix this, or if it turns out to be that this code does not function at all with <1.6 moodles.

If you'd like help with anything to do with this code or have anything to ask, please do feel free to contact me.
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Eugene Ritter -
Thanks for the reply.

I will definitely trying to implement this in Moodle 1.5.2. It looks like the function failures was due to the fact that the XML parser functions aren't installed yet on my server. Once they get there I will let you know how it goes.


In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Martín Langhoff -
There _is_ something similar to this already implemented in Moodle 1.5.x. It's called 'Import course data'.
In reply to Martín Langhoff

Re: Couse and Category Duplication.

by Tim Allen -
I think this hack does this for multiple courses at once, which "import course data" doesn't do.  So this would save a lot of clicks for the user and seems perfect for an end-of-semester scenario.  "Import course data" seems more suited to import data into a course that is already existing and open.

What a great idea! 
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Eugene Ritter -
I'm still working on getting my xml extension installed. I thought of one small improvement to duplicate.php.

The one thing course/import.php does that duplicate.php doesn't is to check for xml function capability. import.php does it using backup_required_functions(); In backup/lib.php. 
In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Eugene Ritter -
duplicate.php went flawlessly! smile

However  duplicate-category.php went like this:


Duplication in progress: (This may take a while)

Duplicating: American Studies...
>>> Duplicating course: American Studies 101--Introduction to the U.S. Founding Documents... Done!
>>> Duplicating course: American Studies 201--Federalist Papers Part I... Done!
>>> Duplicating course: American Studies 202--Federalist Papers Part II... Done!
>>> Duplicating course: American Studies 203--Historical Roots of the American Founding... Done!
>>> Duplicating course: American Studies 204--Founding Fathers of America... Done!
>>> Duplicating course: American Studies 205--Escaping the Polybian Cycle: A Primer... Done!
>>> Duplicating course: American Studies 209--Introduction to Anglo-American Law... Done!
>>> Duplicating course: American Studies 210--Introduction to the Constitution--Part I... Done!
>>> Duplicating course: American Studies 211--Introduction to the Constitution Part II... started restore... got to stage 2 restore
finished creating a new course
started restoring users
finished restoring users
finished 0.1
finished 0.5
finished 0.8
finished 1

Fatal error: Maximum execution time of 30 seconds exceeded in /usr2/home/tsrwu/www/moodle/backup/restorelib.php on line 3006

Before it timed out it successfully copied 7 of 11 courses,  created a copy category. Overall execellent work!
Average of ratings: Useful (1)
In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Gary Plumbridge -
Whoops!
This was a really silly mistake I had been thinking of fixing ages ago but clearly never did smile

I've fixed that now. (see attached)

The new scripts will (if your PHP installation is kind enough) expand their timeout and memory restrictions to 50minutes timeout and 128MB memory usage.
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Eugene Ritter -
Very nice script. Thanks so much. I'll give the new version a try tomorrow.

Thanks again!
In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Sean S -
This looks great. I look forward to it's inclusion in 1.6
In reply to Gary Plumbridge

Re: Couse and Category Duplication.

by Adolfo Franco -

Hey! That is the exactly solution I've been praying for... I have 9 courses which, for bosses' requirements, have to be cloned 35 times dead, meaning 35 categories that are named after the groups whose 35 tutors will manage. The total of students will be something about 1.000, and the bosses do not want tutors interfering in other groups matters. Cloning the courses did not seem to be a nice idea because of the tough task involved, but I had no alternative 'cause the group stuff is still confusing to me.

However, I've upload the files to the course and backup folders but I could not find where to make the duplications in the moodle interface... What am I missing?

Thanks in advance.

In reply to Adolfo Franco

Re: Course and Category Duplication.

by Adolfo Franco -

Well... nobody has replied... so I had to create MANUALLY all the 35 categories with 9 courses each... dead Currently I am MANUALLY configuring all gradebooks... Yep, I does NOT sound like fun. At least the tutors will be assigned to populate the contents themselves... Otherwise I would quit... big grin

Anywayz I still wish someone gave some clues for making the hack work (so that I won't have to go through this again).

In reply to Eugene Ritter

Re: Couse and Category Duplication.

by Adolfo Franco -

quote: ...Changed view.php to duplicate.php. Got the dialogue...

clown Ahhh

In reply to Adolfo Franco

Re: Couse and Category Duplication.

by Kent Villard -
Does this work for newer versions of Moodle (1.8+)?