Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-22504 Course drag and drop upload - now correctly ignores disable…

…d modules and allows upload to orphaned sections
  • Loading branch information...
commit 5103b5e66790047586b52516f852fe751c1e6a50 1 parent abed5d6
@davosmith davosmith authored
View
6 course/lib.php
@@ -4445,13 +4445,15 @@ function course_page_type_list($pagetype, $parentcontext, $currentcontext) {
* @param integer $id The ID of the course being applied to
* @param array $modules An array containing the names of the modules in
* use on the page
+ * @param array $allmodules An array containing the names of the enabled (visible)
+ * modules on this site
* @param object $config An object containing configuration parameters for ajax modules including:
* * resourceurl The URL to post changes to for resource changes
* * sectionurl The URL to post changes to for section changes
* * pageparams Additional parameters to pass through in the post
* @return void
*/
-function include_course_ajax($course, $modules = array(), $config = null) {
+function include_course_ajax($course, $modules = array(), $allmodules = null, $config = null) {
global $PAGE, $CFG, $USER;
// Ensure that ajax should be included
@@ -4560,5 +4562,5 @@ function include_course_ajax($course, $modules = array(), $config = null) {
}
// Load drag and drop upload AJAX.
- dndupload_add_to_course($course);
+ dndupload_add_to_course($course, $allmodules);
}
View
2  course/view.php
@@ -232,6 +232,6 @@
echo html_writer::end_tag('div');
// Include the command toolbox YUI module
- include_course_ajax($course, $modnamesused);
+ include_course_ajax($course, $modnamesused, $modnames);
echo $OUTPUT->footer();
View
2  index.php
@@ -147,7 +147,7 @@
echo $OUTPUT->box_end();
}
}
- include_course_ajax($SITE, $modnamesused);
+ include_course_ajax($SITE, $modnamesused, $modnames);
if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
View
3  lib/ajax/dndupload.js
@@ -202,6 +202,9 @@ M.course_dndupload = {
*/
drag_type: function(e) {
if (this.types_includes(e, 'Files')) {
+ if (this.handlers.filehandlers.length == 0) {
+ return false; // No available file handlers - ignore this drag.
+ }
return {
realtype: 'Files',
addmessage: M.util.get_string('addfilehere', 'core_dndupload'),
View
24 lib/dnduploadlib.php
@@ -33,12 +33,18 @@
* Add the Javascript to enable drag and drop upload to a course page
*
* @param object $course The currently displayed course
+ * @param array $modnames The list of enabled (visible) modules on this site
+ * @return void
*/
-function dndupload_add_to_course($course) {
+function dndupload_add_to_course($course, $modnames) {
global $CFG, $PAGE;
// Get all handlers.
- $handler = new dndupload_handler($course);
+ $handler = new dndupload_handler($course, $modnames);
+ $jsdata = $handler->get_js_data();
+ if (empty($jsdata->types) && empty($jsdata->filehandlers)) {
+ return; // No valid handlers - don't enable drag and drop.
+ }
// Add the javascript to the page.
$jsmodule = array(
@@ -93,7 +99,7 @@ class dndupload_handler {
*
* @param object $course The course this is being added to (to check course_allowed_module() )
*/
- public function __construct($course) {
+ public function __construct($course, $modnames = null) {
global $CFG;
// Add some default types to handle.
@@ -110,8 +116,11 @@ public function __construct($course) {
$mods = get_plugin_list_with_function('mod', 'dndupload_register');
foreach ($mods as $component => $funcname) {
list($modtype, $modname) = normalize_component($component);
+ if ($modnames && !array_key_exists($modname, $modnames)) {
+ continue; // Module is deactivated (hidden) at the site level.
+ }
if (!course_allowed_module($course, $modname)) {
- continue;
+ continue; // User does not have permission to add this module to the course.
}
$resp = $funcname();
if (!$resp) {
@@ -387,7 +396,7 @@ public function __construct($courseid, $section, $type, $modulename) {
require_login($this->course, false);
$this->context = context_course::instance($this->course->id);
- if (!is_number($section) || $section < 0 || $section > $this->course->numsections) {
+ if (!is_number($section) || $section < 0) {
throw new coding_exception("Invalid section number $section");
}
$this->section = $section;
@@ -592,6 +601,11 @@ protected function finish_setup_course_module($instanceid) {
rebuild_course_cache($this->course->id, true);
$this->course->modinfo = null; // Otherwise we will just get the old version back again.
$info = get_fast_modinfo($this->course);
+ if (!isset($info->cms[$this->cm->id])) {
+ // The course module has not been properly created in the course - undo everything.
+ delete_course_module($this->cm->id);
+ throw new moodle_exception('errorcreatingactivity', 'core_dndupload', '', $this->module->name);
+ }
$mod = $info->cms[$this->cm->id];
// Trigger mod_created event with information about this module.
Please sign in to comment.
Something went wrong with that request. Please try again.