/** * Determine whether course ajax should be enabled for the specified course * * @param stdClass $course The course to test against * @return boolean Whether course ajax is enabled or note */ function course_ajax_enabled($course) { global $CFG, $PAGE, $SITE; // Ajax must be enabled globally if (!$CFG->enableajax) { return false; } // The user must be editing for AJAX to be included if (!$PAGE->user_is_editing()) { return false; } // Check that the theme suports if (!$PAGE->theme->enablecourseajax) { return false; } // Check that the course format supports ajax functionality // The site 'format' doesn't have information on course format support if ($SITE->id !== $course->id) { $courseformatajaxsupport = course_format_ajax_support($course->format); if (!$courseformatajaxsupport->capable) { return false; } } // All conditions have been met so course ajax should be enabled return true; }
/** * Include the relevant javascript and language strings for the resource * toolbox YUI module * * @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 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) { global $PAGE, $CFG, $USER; // Ensure that ajax should be included $courseformatajaxsupport = course_format_ajax_support($course->format); if (!$CFG->enablecourseajax || !$PAGE->theme->enablecourseajax || !$CFG->enableajax || empty($USER->editing) || !$PAGE->user_is_editing() || $course->id != SITEID && !$courseformatajaxsupport->capable) { return; } if (!$config) { $config = new stdClass(); } // The URL to use for resource changes if (!isset($config->resourceurl)) { $config->resourceurl = '/course/rest.php'; } // The URL to use for section changes if (!isset($config->sectionurl)) { $config->sectionurl = '/course/rest.php'; } // Any additional parameters which need to be included on page submission if (!isset($config->pageparams)) { $config->pageparams = array(); } // Include toolboxes $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_resource_toolbox', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config))); $PAGE->requires->yui_module('moodle-course-toolboxes', 'M.course.init_section_toolbox', array(array('courseid' => $course->id, 'format' => $course->format, 'ajaxurl' => $config->sectionurl, 'config' => $config))); // Include course dragdrop if ($course->id != SITEID) { $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.core_course.init_section_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->sectionurl, 'config' => $config)), null, true); $PAGE->requires->yui_module('moodle-course-dragdrop', 'M.core_course.init_resource_dragdrop', array(array('courseid' => $course->id, 'ajaxurl' => $config->resourceurl, 'config' => $config)), null, true); } // Include blocks dragdrop $params = array('courseid' => $course->id, 'pagetype' => $PAGE->pagetype, 'pagelayout' => $PAGE->pagelayout, 'regions' => $PAGE->blocks->get_regions()); $PAGE->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); // Require various strings for the command toolbox $PAGE->requires->strings_for_js(array('moveleft', 'deletechecktype', 'deletechecktypename', 'show', 'hide', 'groupsnone', 'groupsvisible', 'groupsseparate', 'clicktochangeinbrackets', 'markthistopic', 'markedthistopic', 'move', 'movesection'), 'moodle'); // Include format-specific strings if ($course->id != SITEID) { $PAGE->requires->strings_for_js(array('showfromothers', 'hidefromothers'), 'format_' . $course->format); } // For confirming resource deletion we need the name of the module in question foreach ($modules as $module => $modname) { $PAGE->requires->string_for_js('pluginname', $module); } }
// are seen immediately on the navigation. $PAGE->navigation->clear_cache(); } } } } else { $USER->editing = 0; } $SESSION->fromdiscussion = $CFG->wwwroot . '/course/view.php?id=' . $course->id; if ($course->id == SITEID) { // This course is not a real course. redirect($CFG->wwwroot . '/'); } // AJAX-capable course format? $useajax = false; $formatajax = course_format_ajax_support($course->format); if (!empty($CFG->enablecourseajax) and $formatajax->capable and !empty($USER->editing) and ajaxenabled($formatajax->testedbrowsers) and $PAGE->theme->enablecourseajax and has_capability('moodle/course:manageactivities', $context)) { $PAGE->requires->yui2_lib('dragdrop'); $PAGE->requires->yui2_lib('connection'); $PAGE->requires->yui2_lib('selector'); $PAGE->requires->js('/lib/ajax/block_classes.js', true); $PAGE->requires->js('/lib/ajax/section_classes.js', true); // Okay, global variable alert. VERY UGLY. We need to create // this object here before the <blockname>_print_block() // function is called, since that function needs to set some // stuff in the javascriptportal object. $COURSE->javascriptportal = new jsportal(); $useajax = true; } $CFG->blocksdrag = $useajax; // this will add a new class to the header so we can style differently