Custom login and redirect to specific/last enrolled course (update)

Custom login and redirect to specific/last enrolled course (update)

by oliver stearn -
Number of replies: 0

Hi All, 


I wanted to reply to this thread (title same as above) as it seems to be the only one on the topic. 

https://moodle.org/mod/forum/discuss.php?d=156049


This describes a method of modifying login/index.php to redirect to specific course. This method no longer works due to developments in login/index.php and was not quite suitable for my requirements. After login, I wanted students to be redirected to the last course they were enrolled in (or perhaps the course with the largest id). I therefore adapted some code for this purpose. 


https://gist.github.com/ostearn/3482c1cdea015f475945f632f364b7cc


//this should be added after $SESSION->wantsurl = null; (there are roughly 4 occurances, consider each individually) 

if($student_course_arry = enrol_get_users_courses($USER->id, true, Null, 'visible DESC,sortorder DESC'))
        {
            
            foreach($student_course_arry as $value)
            {
                
                $SESSION->wantsurl = $CFG->httpswwwroot . '/course/view.php?id=' . $value->id;
            }
            
        }

Average of ratings: -