Skip to content

Instantly share code, notes, and snippets.

@taptapdan
Last active August 29, 2015 14:01
Show Gist options
  • Save taptapdan/832a62eda20a9c371ebf to your computer and use it in GitHub Desktop.
Save taptapdan/832a62eda20a9c371ebf to your computer and use it in GitHub Desktop.
Example Bookmarklet for Moodle Quiz Settings
/*
Author: Daniel Fiore (@taptapdan)
License: MIT License
I needed a way to make the same settings changes to many quizzes in a course. Since Moodle doesn't offer a bulk edit for quizzes, I created this bookmarklet to save me a ton of clicking. Hopefully someone else finds this helpful. To use -- modify the settings or remove the ones you don't need, open the quiz's Edit Settings page, and click on the bookmarklet.
This works on my university's installation of Moodle 2.6. This may or may not work for you. I'd suggest backing up your course before attempting to use this!
Feel free to get in touch on Github or Twitter (@taptapdan) if you have questions and I'll try to help.
*/
function setFormField(f,v) {
document.getElementById(f).disabled = false;
document.getElementById(f).value = v;
}
function setChecked(f) {
document.getElementById(f).disabled = false;
document.getElementById(f).checked = true;
}
function setUnchecked(f) {
document.getElementById(f).checked = false;
}
/* SETTINGS: TIMING */
/* Enables "Open the quiz" and sets date/time. */
setChecked("id_timeopen_enabled");
setFormField("id_timeopen_day", 25); /* no leading 0 */
setFormField("id_timeopen_month", 8); /* no leading 0 */
setFormField("id_timeopen_year", 2014); /* four digit */
setFormField("id_timeopen_hour", 00); /* leading 0 */
setFormField("id_timeopen_minute", 00); /* leading 0 */
/* Enables "Close the quiz" and sets date/time. */
setChecked("id_timeclose_enabled");
setFormField("id_timeclose_day", 28); /* no leading 0 */
setFormField("id_timeclose_month", 8); /* no leading 0 */
setFormField("id_timeclose_year", 2014); /* four digit */
setFormField("id_timeclose_hour", 23); /* leading 0 */
setFormField("id_timeclose_minute", 55); /* leading 0 */
/* Enables Time Limit, sets Time Limit and sets When Time Expires. */
setChecked("id_timelimit_enabled");
setFormField("id_timelimit_number", 30);
/* 1: seconds, 60: minutes, 3600: hours, 86400: days, 604800: weeks */
setFormField("id_timelimit_timeunit", 60);
/*
autosubmit: Open attempts are submitted automatically,
graceperiod: There is a grace period when open attempts can be submitted, but no more questions answered,
autoabandon: Attempts must be submitted before time expires, or they are not counted.
*/
setFormField("id_overduehandling", "autosubmit");
/* SETTINGS: GRADE */
setFormField("id_gradecat", 4080); /* need to look this up */
setFormField("id_attempts", 4); /* 0: unlimited, or 1-10 */
/* 1: highest grade, 2: average grade, 3: first attempt, 4: last attempt */
setFormField("id_grademethod", 1);
/* SETTINGS: RESTRICT ACCESS */
setUnchecked("id_availablefrom_enabled"); /* use open/close dates instead */
setUnchecked("id_availableuntil_enabled"); /* use open/close dates instead */
/* SETTINGS: ACTIVITY COMPLETION */
setFormField("id_completion", 2); /* when conditions are met */
setChecked("id_completionview"); /* must view this activity to complete it */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment