Skip to content

Commit

Permalink
MDL-32873 Separate out course ajax enabled detection into new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Robert Nicols committed May 9, 2012
1 parent 875f2e4 commit 5720019
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4396,6 +4396,43 @@ function course_page_type_list($pagetype, $parentcontext, $currentcontext) {
}
}

/**
* Determine whether course ajax should be enabled for the specified course
*
* @param object $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
Expand All @@ -4410,16 +4447,11 @@ function course_page_type_list($pagetype, $parentcontext, $currentcontext) {
* @return void
*/
function include_course_ajax($course, $modules = array(), $config = null) {
global $PAGE, $CFG, $USER;
global $PAGE, $CFG, $SITE;

// Ensure that ajax should be included
$courseformatajaxsupport = course_format_ajax_support($course->format);
if (!$PAGE->theme->enablecourseajax
|| !$CFG->enableajax
|| empty($USER->editing)
|| !$PAGE->user_is_editing()
|| ($course->id != SITEID && !$courseformatajaxsupport->capable)) {
return;
if (!course_ajax_enabled($course)) {
return false;
}

if (!$config) {
Expand Down Expand Up @@ -4461,7 +4493,7 @@ function include_course_ajax($course, $modules = array(), $config = null) {
);

// Include course dragdrop
if ($course->id != SITEID) {
if ($course->id != $SITE->id) {
$PAGE->requires->yui_module('moodle-course-dragdrop', 'M.course.init_section_dragdrop',
array(array(
'courseid' => $course->id,
Expand Down Expand Up @@ -4504,7 +4536,7 @@ function include_course_ajax($course, $modules = array(), $config = null) {
), 'moodle');

// Include format-specific strings
if ($course->id != SITEID) {
if ($course->id != $SITE->id) {
$PAGE->requires->strings_for_js(array(
'showfromothers',
'hidefromothers',
Expand All @@ -4515,6 +4547,8 @@ function include_course_ajax($course, $modules = array(), $config = null) {
foreach ($modules as $module => $modname) {
$PAGE->requires->string_for_js('pluginname', $module);
}

return true;
}

/**
Expand Down

0 comments on commit 5720019

Please sign in to comment.