MDL-18309 Course: enrol/index.php returnurl improvement

This patch improves usability of enrolment page in case of course is not
enrollable. 'Continue' button now returns student to referring page instead of
main moodle page (as it used to be). To make this improvement, passing correct
returnurl parameter to enrol/index.php page was implemented for links that may
be accessible for not-enrolled students.
This commit is contained in:
Gregory Zbitnev
2015-01-28 17:01:24 +04:00
committed by Marina Glancy
parent d7551257a0
commit 6601690202
17 changed files with 55 additions and 12 deletions
@@ -634,7 +634,8 @@ BRANCH.prototype = {
id : this.get('key'),
type : this.get('type'),
sesskey : M.cfg.sesskey,
instance : this.get('tree').get('instance')
instance : this.get('tree').get('instance'),
returnurl : location.href
};
var ajaxfile = '/lib/ajax/getnavbranch.php';
File diff suppressed because one or more lines are too long
@@ -632,7 +632,8 @@ BRANCH.prototype = {
id : this.get('key'),
type : this.get('type'),
sesskey : M.cfg.sesskey,
instance : this.get('tree').get('instance')
instance : this.get('tree').get('instance'),
returnurl : location.href
};
var ajaxfile = '/lib/ajax/getnavbranch.php';
+2 -1
View File
@@ -632,7 +632,8 @@ BRANCH.prototype = {
id : this.get('key'),
type : this.get('type'),
sesskey : M.cfg.sesskey,
instance : this.get('tree').get('instance')
instance : this.get('tree').get('instance'),
returnurl : location.href
};
var ajaxfile = '/lib/ajax/getnavbranch.php';
+3
View File
@@ -29,11 +29,14 @@ define('AJAX_SCRIPT', true);
require_once(dirname(__dir__) . '/config.php');
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
if ($CFG->forcelogin) {
require_login();
}
$PAGE->set_context(context_system::instance());
$courserenderer = $PAGE->get_renderer('core', 'course');
$courserenderer->returnurl = $returnurl;
echo json_encode($courserenderer->coursecat_ajax());
+1
View File
@@ -44,6 +44,7 @@ if ($categoryid) {
$PAGE->set_pagelayout('coursecategory');
$courserenderer = $PAGE->get_renderer('core', 'course');
$courserenderer->returnurl = $PAGE->url;
if ($CFG->forcelogin) {
require_login();
+5 -1
View File
@@ -49,6 +49,9 @@ class core_course_renderer extends plugin_renderer_base {
*/
protected $strings;
/** @var moodle_url|null stores page where to return to from the enrolment page */
public $returnurl;
/**
* Override the constructor so that we can initialise the string cache
*
@@ -1207,7 +1210,8 @@ class core_course_renderer extends plugin_renderer_base {
// course name
$coursename = $chelper->get_course_formatted_name($course);
$coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
$coursenamelink = html_writer::link(new moodle_url('/course/view.php',
array('id' => $course->id, 'returnurl' => $this->returnurl)),
$coursename, array('class' => $course->visible ? '' : 'dimmed'));
$content .= html_writer::tag($nametag, $coursenamelink, array('class' => 'coursename'));
// If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
+4
View File
@@ -19,6 +19,7 @@
$switchrole = optional_param('switchrole',-1, PARAM_INT); // Deprecated, use course/switchrole.php instead.
$modchooser = optional_param('modchooser', -1, PARAM_BOOL);
$return = optional_param('return', 0, PARAM_LOCALURL);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$params = array();
if (!empty($name)) {
@@ -42,6 +43,9 @@
if ($section) {
$urlparams['section'] = $section;
}
if ($returnurl) {
$urlparams['returnurl'] = $returnurl;
}
$PAGE->set_url('/course/view.php', $urlparams); // Defined here to avoid notices on errors etc
@@ -181,7 +181,8 @@ NS._toggle_category_expansion = function(e) {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
type: TYPE_CATEGORY,
returnurl: location.href
}
});
};
File diff suppressed because one or more lines are too long
@@ -180,7 +180,8 @@ NS._toggle_category_expansion = function(e) {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
type: TYPE_CATEGORY,
returnurl: location.href
}
});
};
+2 -1
View File
@@ -179,7 +179,8 @@ NS._toggle_category_expansion = function(e) {
categoryid: categoryid,
depth: depth,
showcourses: categorynode.getData('showcourses'),
type: TYPE_CATEGORY
type: TYPE_CATEGORY,
returnurl: location.href
}
});
};
+3
View File
@@ -26,6 +26,7 @@ require('../config.php');
require_once("$CFG->libdir/formslib.php");
$id = required_param('id', PARAM_INT);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
if (!isloggedin()) {
// do not use require_login here because we are usually coming from it,
@@ -98,6 +99,8 @@ foreach ($forms as $form) {
if (!$forms) {
if (isguestuser()) {
notice(get_string('noguestaccess', 'enrol'), get_login_url());
} else if ($returnurl) {
notice(get_string('notenrollable', 'enrol'), $returnurl);
} else {
notice(get_string('notenrollable', 'enrol'), "$CFG->wwwroot/index.php");
}
+11
View File
@@ -43,6 +43,8 @@ try {
$branchtype = required_param('type', PARAM_INT);
// This identifies the block instance requesting AJAX extension
$instanceid = optional_param('instance', null, PARAM_INT);
// URL of referrer page.
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
$PAGE->set_context(context_system::instance());
@@ -102,9 +104,18 @@ try {
if (!$linkcategories) {
foreach ($branch->find_all_of_type(navigation_node::TYPE_CATEGORY) as $category) {
$category->action = null;
foreach ($category->find_all_of_type(navigation_node::TYPE_COURSE) as $course) {
$course->action->param('returnurl', $returnurl);
}
}
foreach ($branch->find_all_of_type(navigation_node::TYPE_MY_CATEGORY) as $category) {
$category->action = null;
foreach ($category->find_all_of_type(navigation_node::TYPE_COURSE) as $course) {
$course->action->param('returnurl', $returnurl);
}
}
foreach ($branch->find_all_of_type(navigation_node::TYPE_COURSE) as $course) {
$course->action->param('returnurl', $returnurl);
}
}
+5 -1
View File
@@ -2796,7 +2796,11 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
if ($setwantsurltome) {
$SESSION->wantsurl = qualified_me();
}
redirect($CFG->wwwroot .'/enrol/index.php?id='. $course->id);
$redirecturl = new moodle_url($CFG->wwwroot .'/enrol/index.php', array('id' => $course->id));
if ($PAGE->url->get_param('returnurl')) {
$redirecturl->param('returnurl', $PAGE->url->get_param('returnurl'));
}
redirect($redirecturl);
}
}
+3 -1
View File
@@ -186,7 +186,9 @@ if (!$choiceformshown) {
echo $OUTPUT->box_start('generalbox', 'notice');
echo '<p align="center">'. get_string('notenrolledchoose', 'choice') .'</p>';
echo $OUTPUT->container_start('continuebutton');
echo $OUTPUT->single_button(new moodle_url('/enrol/index.php?', array('id'=>$course->id)), get_string('enrolme', 'core_enrol', $courseshortname));
echo $OUTPUT->single_button(new moodle_url('/enrol/index.php?',
array('id' => $course->id, 'returnurl' => $PAGE->url)),
get_string('enrolme', 'core_enrol', $courseshortname));
echo $OUTPUT->container_end();
echo $OUTPUT->box_end();
+6 -1
View File
@@ -187,7 +187,12 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
if (!is_enrolled($coursecontext)) { // User is a guest here!
$SESSION->wantsurl = qualified_me();
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id, get_string('youneedtoenrol'));
redirect(new moodle_url('/enrol/index.php', array(
'id' => $course->id,
'returnurl' => new moodle_url('/mod/forum/view.php',
array('f' => $forum->id))
)),
get_string('youneedtoenrol'));
}
}
print_error('nopostforum', 'forum');