Skip to content

Commit

Permalink
MDL-70821 course: Remove old manual completion toggling
Browse files Browse the repository at this point in the history
Remove the old ways of toggling manual completion via completion.js
and the ajax part of togglecompletion.php.
  • Loading branch information
junpataleta committed Apr 12, 2021
1 parent e933044 commit 32b76b3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 162 deletions.
114 changes: 0 additions & 114 deletions course/completion.js

This file was deleted.

30 changes: 5 additions & 25 deletions course/togglecompletion.php
Expand Up @@ -119,9 +119,7 @@
}
}


$targetstate = required_param('completionstate', PARAM_INT);
$fromajax = optional_param('fromajax', 0, PARAM_INT);

$PAGE->set_url('/course/togglecompletion.php', array('id'=>$cmid, 'completionstate'=>$targetstate));

Expand Down Expand Up @@ -158,33 +156,15 @@

// Check completion state is manual
if($cm->completion != COMPLETION_TRACKING_MANUAL) {
error_or_ajax('cannotmanualctrack', $fromajax);
throw new moodle_exception('cannotmanualctrack');
}

$completion->update_state($cm, $targetstate);

// And redirect back to course
if ($fromajax) {
print 'OK';
// In case of use in other areas of code we allow a 'backto' parameter, otherwise go back to course page.
if ($backto = optional_param('backto', null, PARAM_URL)) {
redirect($backto);
} else {
// In case of use in other areas of code we allow a 'backto' parameter,
// otherwise go back to course page

if ($backto = optional_param('backto', null, PARAM_URL)) {
redirect($backto);
} else {
redirect(course_get_url($course, $cm->sectionnum));
}
}

// utility functions

function error_or_ajax($message, $fromajax) {
if ($fromajax) {
print get_string($message, 'error');
exit;
} else {
print_error($message);
}
redirect(course_get_url($course, $cm->sectionnum));
}

22 changes: 1 addition & 21 deletions course/view.php
Expand Up @@ -215,14 +215,6 @@
redirect($CFG->wwwroot .'/');
}

$completion = new completion_info($course);
if ($completion->is_enabled()) {
$PAGE->requires->string_for_js('completion-alt-manual-y', 'completion');
$PAGE->requires->string_for_js('completion-alt-manual-n', 'completion');

$PAGE->requires->js_init_call('M.core_completion.init');
}

// Determine whether the user has permission to download course content.
$candownloadcourse = \core\content::can_export_context($context, $USER);

Expand Down Expand Up @@ -262,19 +254,6 @@
}
}

if ($completion->is_enabled()) {
// This value tracks whether there has been a dynamic change to the page.
// It is used so that if a user does this - (a) set some tickmarks, (b)
// go to another page, (c) clicks Back button - the page will
// automatically reload. Otherwise it would start with the wrong tick
// values.
echo html_writer::start_tag('form', array('action'=>'.', 'method'=>'get'));
echo html_writer::start_tag('div');
echo html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'completion_dynamic_change', 'name'=>'completion_dynamic_change', 'value'=>'0'));
echo html_writer::end_tag('div');
echo html_writer::end_tag('form');
}

// Course wrapper start.
echo html_writer::start_tag('div', array('class'=>'course-content'));

Expand Down Expand Up @@ -315,6 +294,7 @@
}

// Load the view JS module if completion tracking is enabled for this course.
$completion = new completion_info($course);
if ($completion->is_enabled()) {
$PAGE->requires->js_call_amd('core_course/view', 'init');
}
Expand Down
2 changes: 0 additions & 2 deletions lib/outputrequirementslib.php
Expand Up @@ -787,8 +787,6 @@ protected function find_module($component) {
'requires' => array('node', 'cookie'));
break;
case 'core_completion':
$module = array('name' => 'core_completion',
'fullpath' => '/course/completion.js');
break;
case 'core_message':
$module = array('name' => 'core_message',
Expand Down

0 comments on commit 32b76b3

Please sign in to comment.