Capability to copy resources/activities finished!

Capability to copy resources/activities finished!

by Joan Vendrell -
Number of replies: 38

Hi, we have developed a new feature to let the teacher copy the existing resources/activities from a course in only 3 steps, avoiding the work to fill all the fields of the form every time you need to create a new activity.

This functionality is very similar to the one that allows you to move activities, but copying them instead of just moving. This is really helpful when you have to create some new activities which are very similar to the existing ones, because you only have to copy them and make the few needed modifications.

To do this we have added a new icon which appears when the teacher turns the editing mode on, and we have added several code to some Moodle files too.

The feature has been added to Moodle version 1.5.

Finally, we attach all the code with the post. If somebody finds it interesting, you only have to unzip the package to the Moodle directory and overwrite the existing files (remember to check your Moodle version before doing anything!).

Despite his easy concept, here come some screenshots to have an idea of how it works:

Step 1

Step 2

Step 3

P.D: I dont know if this forum is the suitable place to put this, if Im wrong please let me know where I can move it.

Joan & Sergio

Average of ratings: Useful (2)
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Darren Smith -
This looks brilliant. I can't believe people haven't jumped in and requested this functionality for the main moodle code.

Thanks for making this public. I will certainly add it when we upgrade to 1.5
In reply to Darren Smith

Re: Capability to copy resources/activities finished!

by Robert Brenstein -
I have always wondered why this was not in Moodle. Duplicating resources and activities within a course or between courses seems such a basic feature but any mention of it was met with 'use backup' as far as I could see from forums here smile

In reply to Darren Smith

Re: Capability to copy resources/activities finished!

by Art Lader -

I will add it to our Moodle, too! (It would be GREAT if this worked in copying from one course to another.)

Thanks!

-- Art

In reply to Art Lader

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I'm working on making it usable from one course to another, but I am planning on using the version from 1.4.4 that was commented out by Martin.
In reply to Anthony Borrow

Re: Capability to copy resources/activities finished!

by Art Lader -

> I'm working on making it usable from one course to another

Woohoo!

-- Art

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Joan Codina Filba -
This improvement to Moodle has been part of a Course about open source where Moodle was the suport, and sample project.
I, as the teacher, proposed them some changes that they had to develop and make public. I think that it would be great for them to see this changes as part of the Moodle distribution... but I'm not sure about the right method to propose improvements and once programmed how they become part of the Moodle distribution.
Because as the code is not in CVS then it needs to be maintained every time a new release is installed
In reply to Joan Codina Filba

Re: Capability to copy resources/activities finished!

by Marc Dastous -

Let me say that this code is wonderful.  I implenented it flawlessly on my development site and it works GREAT!!!!  I plan on upgrading all of my sites this weekend with this code.

A big thank you to your and your students.  We hope to see more from them in the future.

Marc

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Bob Puffer -
Running version Moodle 1.5 + (2005060201) and I get a "unable to downgrade" error. 
In reply to Bob Puffer

Re: Capability to copy resources/activities finished!

by Joan Vendrell -

Hi, could you tell us with a little more detail what your problem is?

Which activity are you trying to copy?

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Bob Puffer -
I get this error when I go into Administration and it tries to install the various changes.  Never get to the point of copying resources.
In reply to Bob Puffer

Re: Capability to copy resources/activities finished!

by Joan Vendrell -

If you are still interested then try to make a backup of your files and directly overwrite them with the new ones, without doing anything in Administration. That should be enough to work ok.

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Bob Puffer -
My procedures for installing this functionality were:
  1. Make a complete backup of my Moodle installation
  2. take the files you've provided in the zip and copy them over the original files
Whenever I go into administration it tries to install a block or module and says it cannot downgrade the installation because my current one is newer.  I get the message:
Version mismatch: block site_main_menu can't downgrade 2005061300 -> 2004052700! 

This was a fresh site when I installed the current version just a few days ago.
In reply to Bob Puffer

Re: Capability to copy resources/activities finished!

by Joan Vendrell -

Well, then it's possible that you have a more recent version than the one we used to develop the feature and it gives some kind of problems...

These are the problems of adding a feature not included in the official release... that they can change some code and we have to check and update our customized code every time.

What you can try is to change line 4 of the affected file ($this->version = 2004052700;) and put your version. It might work.

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Bob Puffer -
yes, thanks -- that did the trick.  Very good feature addition -- hope it makes it into the mainstream.
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Thank you for posting this code - I had seen that in version 1.4.4 the ability to duplicate an assignment was commented out (and in V1.5 and 1.6dev it has been removed). Rather than using the move interface it simply brought up the module's add form and filled in the form values from the previous form.

Both methods have their advantages - your method lets users easily place the new module (resource/activity) in the proper section (week or topic). The other method is a little cleaner.

I would like to extend the functionality of the 1.4.4 method by having a dropdown list of the courses taught by the teacher appear when duplicating a module. By default, the current course would be highlighted and would function as duplicating; however, if a different course would be selected then it would set the $form->course id variable to that of the selected course and the event would be saved into that course. This would allow for resources/activities to be more easily shared between courses. I am not a professional programmer but I will continue to hack away unless someone with more experience and expertise beats me to it (which I hope they do). As others have commented, this seems to be a basic feature that is surprisingly absent in an otherwise very impressive system.

Also, I designed a different pix image duplicate.gif for duplicate that is a little simpler and perhaps more consistent with the other icons. I named it /pix/t/duplicate.gif (I think duplicate.gif would be more consistent).

Peace - Anthony
In reply to Anthony Borrow

Re: Capability to copy resources/activities finished!

by W Page -

Hi Anthony!

Could what I suggested in the link below be part of what you are looking at?
http://moodle.org/mod/forum/discuss.php?d=26758&parent=125961

WP1

In reply to W Page

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Somewhat. It suggests using backup and restore which seems to be a little cumbersome but I do like the idea as part of the backup/restore process. In other words, I think that one should be able to select which items are backed up and which items from a backup are restored.

I would also like to see a duplicate icon as part of the \course\lib.php
print_section_add_menus function with code added to the  \course\mod.php
much of this has already been done in 1.4.4 but was commented out

I am specifically talking about adding in a dropdown box of courses when the new module (resouce/activity) form opens. What I like about the way that it works is that it uses existing code and will thus be easier to maintain. My suggestion would be to set the $form->mode to 'dup' and then in the module/mod.html have it check for either 'add' or 'dup' but if it is 'dup' to add the dropdown list. Then it is just a matter of having the dropdown bar change the course id ($form->id) to that of the selected course, and voila. It seems pretty straight forward to me, now it is just a matter of implementing it. Hopefully, a more experienced developer will catch on to this first and be able to do it fairly quickly (unless of course there is something that I am overlooking or not considering).

Peace - Anthony
In reply to Anthony Borrow

Multiple paste

by Joan Codina Filba -
Maybe the solution is to allow multiple paste.
So, when the copy is performed the activity/resource selected is stored in the session, and it can be pasted as many times as necessary untill the "cancel copy" button is selected. This "copy status" is preserved even when changing from one course to another. This can allow a teacher to have two navigator's windows with one course in each one and perform the following actions
Copy
[change window, reload, [Paste]*]*
Cancell copy.
Of course this has many implications as what happens whe two copy are done without paste, if which screen the cancel is done and what happens if there is a paste after...
In reply to Joan Codina Filba

Re: Multiple paste

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
It's a clever way of using the session but I would not like to see that be the recommended way of accomplishing the duplication of a module (assignment/resouce). It would not allow for the scenario of teachers sharing modules and easily being able to copy the module from a shared course to his or her individual course. Sharing course content seems to be an issue that is slowly developing - first with the course backup/restore development and hopefully next with the piecemeal approach. 
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Of course I would like to see this functionality in Moodle, we have talked about it many times before. This is a great little hack, but it doesn't quite fit in with the long-term view which solves a few big requests in one stroke. I would prefer to see it done more like this:
  1. Add checkboxes before listed activity icons to allow multiple select, with a "select" or "copy" button to choose them.
  2. Change paste picture to clearly show "move" and "copy" as two separate options
  3. Allow this to occur BETWEEN courses. So if you have five activities in the clipboard, you can navigate to another course and see them displayed in the clipboard of that course too (and move them there)
  4. Handle user data in some elegant way - needs thinking about -  especially when moving between courses.
Also it's not always enough to just copy the one record from the main table for that activity, some activities may have more data associated with them (like quizzes) so there needs to be support for that (as an optional function in each module lib.php) otherwise there will be corrupted or empty copies created.
In reply to Martin Dougiamas

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I like the clipboard idea - sounds fairly similar to the way that phpMyAdmin handles tables (checkbox listed before the item except that rather than having icons they use a drop down box at the bottom to select the action (drop, empty, repair). In Moodle it could be similar (duplicate, copy [to another course], delete, hide, and group setting)). I think that indent, move, edit setting should remain associated with an individual course. If you were to move a selected group of modules (resources/activities) it becomes confusing (or atleast unclear) for the end user how the different selections will be moved. For example, if I select a module from week 1 and another from week 4 hit move (or even duplicate for that matter) and then select week 3 as the target for the move, where should the selected module from week 4 end up? Presumably in week 6, but I see this causing more confusion for the user. I do like the duplicate function as commented out in 1.4.4 where it simply adds a new instance of the module with the values on the form already filled in. The user can then make any changes and save. As I have mentioned before, I think adding a drop down box of the courses taught by the user would allow an easy way to duplicate the module in another course (even quizzes [from what I can tell]). While this may not fit in with the long term vision of the clipboard, it would provide some functionality that seems to be much desired. Let me know if there is interest in this and I will see if I can come up with a draft of a hack. If Martin or the other developers would prefer to avoid this approach and simply focus on the long term clipboard idea then I would probably not invest that much time in it since I am new to PHP and it would take me a lot longer than a more seasoned developer - but if it would be helpful then I would be happy to do so. I do agree that some thinking will need to go into how to handle the user data, it may be that starting with duplicating individual modules between courses is the way to test this as preparation for the clipboard. From what I can tell it should be fairly straight forward to implement.

p.d. This is the duplicate.gif that I was suggesting - any feedback on it would be appreciated too.
Attachment duplicate.gif
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Joan Codina Filba -
You can test the "copy&paste", the new icon for new activities and the possiblity to count words in an assignment at this site

http://parles.upf.es/TEST

user teacher pass teacher

In reply to Joan Codina Filba

Re: Capability to copy resources/activities finished!

by Michael Penney -
Are there any plans to fix copy activities so that it works with quiz?

Right now, a copied quiz shows the error: No questions found. The quiz shows questions in it, if I remove the question then re-add it, the quiz works.

Also, copied activities have the same names as the originals, causing problems in the gradebook. Any chance 'copy 1', 'copy 2', etc. could get appended to the copied activity name?
In reply to Michael Penney

Re: Capability to copy resources/activities finished!

by Joan Codina Filba -
One of the main reasons for me to use the copy utility is to reuse all the parameters already set for that activity. So I first copy and then edit it in order to customize it.
I also use the copy utility for labels.
The patch was made by Joan Vendrell, a student of a course about open source I give to computer science students. The course is held in spring, and this year I plan for new improvements to be developed by them.  I'm sorry about it, but I can't give support to all the patches they did. Even that this is ones that was working better. As for me the code is as unknown as for most of you
There are other patch's that I did myself, like the floating window, or count words in the assignment . For these ones I still try to keep track of them.


In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Mark Little -
Hi,

Does this work in 1.5.1?

Thanks
Mark
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Brian Gray -

When I added the copy_activities.zip files into my 1.5.2 installation, I got an error on the Admin page warning of an invalid version code for block_site_main_menu.php. 

Also, when I click on the login link, the page that is returned from login.php is blank.

Is there a newer version available that works with 1.5.2?

bkg

In reply to Brian Gray

Re: Capability to copy resources/activities finished!

by Nikki Macfarlane -
Brian,

For the version problem, you just have to edit the block_site_main_menu.php file with the version number it is saying you cannot downgrade from. So for example, if it says cannot downgrade from version 222222 to 111111, you edit the file so it is version 222222. This is what I did and it worked fine.

Nikki
In reply to Nikki Macfarlane

Re: Capability to copy resources/activities finished!

by Brian Gray -
Nikki -

Thanks for the advice. I did what you suggested, and I still get a blank log-in screen.

Restoring the original versions of the files listed below fixes the login screen (but obviously does not allow me to copy activities).

block_site_main_menu.php
block_social_activities.php
course/format/topics/format.php
course/format/weeks/format.php
course/lib.php
course/mod.php
lib/moodlelib.php

I previously installed the copy_activities add-in on a 1.5.1 system I was playing with, and it worked fine there. It does not work on my 1.5.2 installation. (It is possible that the problem is caused by an interaction between the copy_activity changes and one of the other add-ins that I have installed, but I don't know where to start looking.)

bkg


In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Here is my introductory hack at duplicating resources/activities. It works within the same course and also allows for a copy to a different course. I would be interested in getting feedback. I like the simplicity of the approach and how it pretty much uses existing code to accomplish it. The feature can be demo'd at http://arborrow.net/moodle/

Peace - Anthony
In reply to Anthony Borrow

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Also, if you want to undo the changes from duplicate.zip I have created the attached unduplicate.zip for convenience.
In reply to Anthony Borrow

Re: Capability to copy resources/activities finished!

by Mark Stevens -
It looks like a great start to a great feature.  Thanks for your effort!
In reply to Anthony Borrow

Re: Capability to copy resources/activities finished!

by Paul Andrews -
In reply to Paul Andrews

Re: Capability to copy resources/activities finished!

by Paul Andrews -
Updated!

The previous version only worked with one directory... this one's better!!

(Thank Dan Clarke for this... he's a proper coder).

cool


In reply to Paul Andrews

Re: Capability to copy resources/activities finished!

by Paul Andrews -
Another update.. blush

The previous version worked but reported errors when a web site resource was being copied.

This new version checks to see if it's a web site resource and acts accordingly - hopefully this is the last update but you never know...

...on the plus side I have learnt some php!

big grin

In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Helen Bound -
I used this copy facility with 1.5.4 and it worked. We then had to revert back to 1.5. When we upgraded again to 1.5.4 and I downloaded the zip file it didn't work. Any ideas?
In reply to Helen Bound

Re: Capability to copy resources/activities finished!

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
FYI: I have upgraded to 1.6 beta 5 on my production site and abandoned the duplicate functionality due to improvements in the import functionality that will allow the selection of individual assignments, quizzes, etc. to be moved over. I am trying to limit the number of site customizations. I think with some minor improvements and increased functionality in displaying the data when importing that the use of the duplicate.zip can be deprecated (at least that is my intention) so I am not planning on revising the code for 1.6.
In reply to Joan Vendrell

Re: Capability to copy resources/activities finished!

by Helen Bound -
Any chance of the code being updated for 1.6?
In reply to Joan Vendrell

Modules and Plugins

by Mark Penny -
You need to move this to Modules and Plugins, where people are most likely to find it.

Thanks for your work.