1.- On a Moodle course page, when the Delete icon is clicked on an activity, a notice is issued asking for deletion confirmation. If deletion is confirmed by the user, then that activity is deleted, going through the activity's activityname_delete_instance($id) lib function.
2.- However, there may be cases where a given activity instance has dependencies, i.e. other instances (of the same activity) depending on it. The example I am working on at the moment is the Questionnaire add-on, where a "Public" instance has dependent "Private" instances (in other courses). Upon the user deleting a Public instance, I need to issue a warning (and further confirmation) about the potential consequences of the deletion. Maybe there are no other activities (core or add-on) in Moodle that present this problem, but there may well be in the future, so I think this issue must be seriously addressed.
3.- Of course, in my activity's lib activityname_delete_instance($id) function I can conduct tests and return false if my tests say that the instance must not be deleted.
3a.-If AJAX is disabled on the moodle site, the following test in course/lib.php results in an ugly error message being displayed. Something more graceful is really needed!
// Call the delete_instance function, if it returns false throw an exception.
if (!$deleteinstancefunction($cm->instance)) {
throw new moodle_exception('cannotdeletemoduleinstance', '', '', null,
"Cannot delete the module $modulename (instance).");
}
One way to do it would be to offer activities a choice of returning, instead of false, some kind of "message" which would get printed by courselib.
3b.- If AJAX is enabled, things look different. No ugly error message is displayed, but the instance seems to have been deleted, but it re-appears upon refreshing the page, which is disconcerting for the user. Also, in that case, it's impossible for the activity to display its own warning or confirmation.
Any ideas?
Joseph