Skip to content

Commit

Permalink
MDL-18309 Course: enrol/index.php returnurl improvement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zbitnev authored and marinaglancy committed Apr 10, 2015
1 parent d755125 commit 6601690
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion blocks/navigation/yui/src/navigation/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 3 additions & 0 deletions course/category.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@

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 change: 1 addition & 0 deletions course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

$PAGE->set_pagelayout('coursecategory');
$courserenderer = $PAGE->get_renderer('core', 'course');
$courserenderer->returnurl = $PAGE->url;

if ($CFG->forcelogin) {
require_login();
Expand Down
6 changes: 5 additions & 1 deletion course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -1207,7 +1210,8 @@ protected function coursecat_coursebox(coursecat_helper $chelper, $course, $addi

// 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.
Expand Down
4 changes: 4 additions & 0 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
};
Expand Down
Loading

0 comments on commit 6601690

Please sign in to comment.