+++ /dev/null
-<?php
-/**
- * This file is required if the course format is to support AJAX.
- */
-
-
-$CFG->ajaxcapable = true;
-$CFG->ajaxtestedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari'=>531, 'Chrome'=>6.0);
} else {
return get_string('topic').' '.$section->section;
}
-}
\ No newline at end of file
+}
+
+/**
+ * Declares support for course AJAX features
+ *
+ * @see course_format_ajax_support()
+ * @return stdClass
+ */
+function callback_topics_ajax_support() {
+ $ajaxsupport = new stdClass();
+ $ajaxsupport->capable = true;
+ $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
+ return $ajaxsupport;
+}
+++ /dev/null
-<?php
-/**
- * This file is required if the course format is to support AJAX.
- */
-
-
-$CFG->ajaxcapable = true;
-$CFG->ajaxtestedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari'=>531, 'Chrome'=>6.0);
return $weekday.' - '.$endweekday;
}
}
+
+/**
+ * Declares support for course AJAX features
+ *
+ * @see course_format_ajax_support()
+ * @return stdClass
+ */
+function callback_weeks_ajax_support() {
+ $ajaxsupport = new stdClass();
+ $ajaxsupport->capable = true;
+ $ajaxsupport->testedbrowsers = array('MSIE' => 6.0, 'Gecko' => 20061111, 'Safari' => 531, 'Chrome' => 6.0);
+ return $ajaxsupport;
+}
return false;
}
+/**
+ * Returns the information about the ajax support in the given source format
+ *
+ * The returned object's property (boolean)capable indicates that
+ * the course format supports Moodle course ajax features.
+ * The property (array)testedbrowsers can be used as a parameter for {@see ajaxenabled()}.
+ *
+ * @param string $format
+ * @return stdClass
+ */
+function course_format_ajax_support($format) {
+ global $CFG;
+
+ // set up default values
+ $ajaxsupport = new stdClass();
+ $ajaxsupport->capable = false;
+ $ajaxsupport->testedbrowsers = array();
+
+ // get the information from the course format library
+ $featurefile = $CFG->dirroot.'/course/format/'.$format.'/lib.php';
+ $featurefunction = 'callback_'.$format.'_ajax_support';
+ if (!function_exists($featurefunction) && file_exists($featurefile)) {
+ require_once $featurefile;
+ }
+ if (function_exists($featurefunction)) {
+ $formatsupport = $featurefunction();
+ if (isset($formatsupport->capable)) {
+ $ajaxsupport->capable = $formatsupport->capable;
+ }
+ if (is_array($formatsupport->testedbrowsers)) {
+ $ajaxsupport->testedbrowsers = $formatsupport->testedbrowsers;
+ }
+ }
+
+ return $ajaxsupport;
+}
+
/**
* Can the current user delete this course?
* Course creators have exception,
redirect($CFG->wwwroot .'/');
}
-
// AJAX-capable course format?
$useajax = false;
- $ajaxformatfile = $CFG->dirroot.'/course/format/'.$course->format.'/ajax.php';
- $bodytags = '';
-
- if (empty($CFG->disablecourseajax) and file_exists($ajaxformatfile) and !$PAGE->theme->disablecourseajax) { // Needs to exist otherwise no AJAX by default
-
- // TODO: stop abusing CFG global here
- $CFG->ajaxcapable = false; // May be overridden later by ajaxformatfile
- $CFG->ajaxtestedbrowsers = array(); // May be overridden later by ajaxformatfile
-
- require_once($ajaxformatfile);
-
- if (!empty($USER->editing) && $CFG->ajaxcapable && has_capability('moodle/course:manageactivities', $context)) {
- // Course-based switches
-
- if (ajaxenabled($CFG->ajaxtestedbrowsers)) { // Browser, user and site-based switches
- $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;
- }
- }
+ $formatajax = course_format_ajax_support($course->format);
+
+ if (empty($CFG->disablecourseajax)
+ and $formatajax->capable
+ and !empty($USER->editing)
+ and ajaxenabled($formatajax->testedbrowsers)
+ and $PAGE->theme->disablecourseajax
+ 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