General plugins (Local): Use template on course creation

local_course_template
Maintained by Picture of Charles FultonCharles Fulton, Picture of Andrew ZitoAndrew Zito
This local plugin allows site administrators to create "template" courses which will be restored into new courses on course creation.
221 sites
271 downloads
27 fans
Current versions available: 4

This local plugin allows site administrators to create "template" courses which will be restored into new courses on course creation. The intended use case is defining common blocks and activities for a given academic term.

Usage

The administrator will need to create a "template" course which contains the desired blocks and resources. This course will need a specially-named short name. By default the plugin will search for a course with the short name Template-[TERMCODE], where [TERMCODE] is the matching value for YYYYYY. For example, if a course had the termcode 201610, the module would search for a course with the short name Template-201610.

The administrator will need to define a regular expression for extracting the term code from the course idnumber. This will be used to identify which course template (if any) should be used on creation. For example, if your courses have idnumbers in the format XXXXXX.YYYYYY, where YYYYYY is the termcode, then the regular expression /[0-9]+\.([0-9]+)/ will return YYYYYY.

The plugin listens on the \core\event\course_created event and fires immediately on course creation. Once you've given a course the necessary short name you don't need to do anything further. The plugin will create a backup of the template course and import it into the new course.

You should consider overriding Moodle's default block settings in config.php: $CFG->defaultblocks_override = '';. Otherwise you will get two sets of blocks on course creation. Manually configure the blocks in the template course instead. 

Screenshots

Screenshot #0

Contributors

Picture of Charles Fulton
Charles Fulton (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Scott Krajewski
    Thu, May 2, 2019, 4:06 AM
    I'm trying this regex https://regex101.com/r/LbPXPV/2 and the plugin says the Term code value (the regex) is not valid. Any ideas?
  • Picture of Charles Fulton
    Fri, May 3, 2019, 3:26 AM
    Scott: did you wrap your regular expression in slashes (e.g. /my-regex-here/)? The plugin expects them but doesn't add them if they're not present.
  • Picture of Scott Krajewski
    Fri, May 3, 2019, 5:04 AM
    Thanks Charles. This is what I'm using that is coming up as invalid though it works in the regex testing site I linked (without the slashes).
    /(?<=\_)(.*?)(?=\-)/
  • Picture of Cory Robbins
    Fri, May 15, 2020, 9:10 PM
    Hi, Charles. Thanks for developing this. I can't seem to get it to work though. I've tried multiple times using custom regex, and I can't get the courses to actually restore the templates. I finally decided to just straight up copy the example courses listed in the wiki, but even then, when using the supplied regex, I don't get the copy of the course. It is just a default course. I've looked at the logs, and it does have a record for the template being backed up when I create the new course, but there isn't a restore record anywhere. Am I missing something?
  • Picture of Cory Robbins
    Mon, May 18, 2020, 10:43 PM
    Just a heads up... It seems that it DOES work if I do a traditional backup and restore of my template course to a new course that begins with the shortname naming convention. I guess there may be an issue with when shortnames are changed? Anyway, it seems to be working.
  • Picture of Eric Phetteplace
    Sat, Jun 13, 2020, 2:23 AM
    I was struggling with getting this plugin to work while ignoring shortname (since the settings make it sound like everything hinges on idnumber) and creating courses that I _know_ match my regex from testing. Seeing Cory's comment, I changed my template's shortname to be the same as its idnumber and did the same with my created course—and it worked. So I don't know exactly what's going on but it seems like shortname is somehow related to the term code matching procedure.
  • Picture of Andrew Zito
    Sat, Jun 13, 2020, 2:44 AM
    I'm not sure I 100% follow the precise nature of the issue here (not assigning blame, this plugin has some jargon and complexity difficulties), but I can review the way the plugin works: The ID NUMBER of new courses is matched to the SHORTNAME of the template course. So the shortname of your template matters, the shortname of your new courses does not.
  • Picture of Joanna Beaver
    Mon, Jul 27, 2020, 5:55 PM
    Hello, I am using 3.9 version of the plugin and I'm finding that changes made after the template has been used are not showing in future courses created using that template. Are templates not amendable after first use?
  • Picture of Andrew Zito
    Mon, Jul 27, 2020, 7:18 PM
    Hi Joanna, it is the case that courses created based on the template will not be updated when you update the template, but it sounds like you are describing something else. You're saying that changes to the template are not reflected even in courses created after the template change was made?
  • Picture of Joanna Beaver
    Mon, Jul 27, 2020, 10:06 PM
    Hi Andrew, yes that's right. I found that I could create the template + save. Make changes to the template + save. Use the template to successfully create course 1. If I then modified the template and created course 2, it did not contain the changes I had just made and instead delivered me the same template as was served for course 1. It seemed as soon as the template was used once, it no longer reflected any subsequent changes.
  • Picture of Andrew Zito
    Mon, Jul 27, 2020, 11:39 PM
    Hi Joanna, we've discussed this internally and determined that what you're seeing is the caching behavior. For now, you'll have to clear the cache in between each change. We recognize that this is less than ideal, so we're going to look at making the caching behavior more intelligent.
  • Picture of Charles Fulton
    Sat, Aug 1, 2020, 1:05 AM
    Hi Joanna, we've released a new vesrsion (3.6.2) that allows you to disable the caching behavior. That should clear up the problem that you're encountering.
  • Picture of Charles Fulton
    Sat, Aug 1, 2020, 1:05 AM
    Hi Joanna, we've released a new vesrsion (3.6.2) that allows you to disable the caching behavior. That should clear up the problem that you're encountering.
  • Picture of Eric Phetteplace
    Sat, Aug 8, 2020, 4:22 AM
    I believe there's a bug in the most recent version (3.6.2) of this plugin. We're on 3.8.2. I upgraded and it started running a "\local_course_template\task\cleanup_task" every second, filling up the task queue and maxing out our task runners so no other tasks could complete. I tried turning off the new caching option but the behavior persisted. The plugin would not allow me to downgrade to 3.4.1 so I had to uninstall it.
  • Picture of Charles Fulton
    Sat, Aug 8, 2020, 4:54 AM
    Hi Eric, thanks for the report. That's unexpected; the task should run once at 3 AM server time. The caching behavior change shouldn't have affected that part of the plugin; we'll look into it right away.
1 2 3
Please login to post comments