Aim: When I login to Moodle, the system will redirect the user to his last accessed course.
Add the following code to \moodle\login\index.php (just before the "Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my" comment):
==================================================
//redirect user to his course (ignore if it is his first time login)
if ( !empty( $user->lastcourseaccess ) ) {
$mostRecent = 0;
$mostRecentCourse = 0;
foreach ( $user->lastcourseaccess as $k => $v ) {
if ( $v > $mostRecent ) {
$mostRecent = $v;
$mostRecentCourse = $k;
}
}
if ( $mostRecent != 0 ) {
$urltogo = $CFG->wwwroot.'/course/view.php?id='.$mostRecentCourse;
}
}
}
==================================================
沒有留言:
張貼留言