Restrict student access to course by date

Restrict student access to course by date

by Percy Astocaza -
Number of replies: 9

Hello,


I'd like to ask if moodle has a way to restrict enrolled students to access their course after a certain date, for example after a certaint date the course is "closed" and you cannot enter, maybe a redirect?

I'm not talking about the current restrict settings, with those the user can still enter the course, still can see the activities but greyed out, what I want is some kind of redirect or custom message.

If not, how can I approach this? We want this functionality, do I edit course/view.php?  (strongly against this) or can I do it by theme? If so, where?


I'm using moodle 3.2 with boost theme, thanks for the help!

Average of ratings: -
In reply to Percy Astocaza

Re: Restrict student access to course by date

by Sebastian Schedlbauer -

Do you require to keep the student enrolled? If not, you may set "Enrolment ends" for each student

In reply to Sebastian Schedlbauer

Re: Restrict student access to course by date

by Percy Astocaza -

Yes, the user has to be enrolled

In reply to Percy Astocaza

Re: Restrict student access to course by date

by Sebastian Schedlbauer -

Not sure if this is the right and only approach: If you don't want to touch the core, you might create an own course format plugin, which is loaded in course/view.php line 141.

Do your checks inside __construct() of your course format renderer, where you can access the course context, then either continue, or do your redirect/message.

In reply to Sebastian Schedlbauer

Re: Restrict student access to course by date

by Percy Astocaza -

This seems to be the best solution, however i need to set the dates in a table somehow,  can i add a db folder to the format plugin like a local plugin?

And I also need a way to add this options to the course format inside the course edit settings page, right?

In reply to Percy Astocaza

Re: Restrict student access to course by date

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Editing the enrolment dates is still the best solution.

Here is a little trick (hidden gem in moodle):

  • go to "Enrolled users" page
  • filter by the enrolment method (for example "Manual"). Do it even if all users are enrolled manually (filter form)
  • now checkboxes appeared next to each student name, check some/all students and edit their enrolments - you can specify the enrolment end time
Attachment bulkenrol.png
Average of ratings: Useful (1)
In reply to Marina Glancy

Re: Restrict student access to course by date

by Sebastian Schedlbauer -

As I understood the questioner this seems not to be an option, since he wants to keep the users enrolled for some reasons.


@Percy Astocaza: You can define custom course format options on course level, see course_format_options() in lib.php of the course format. For some specific code, you might check https://moodle.org/plugins/pluginversions.php?plugin=format_masonry lib.php for it, the plugin adds some custom settings like border color, which can be altered in course settings. Using the same logic might enable you to define a end date here i guess.


In reply to Sebastian Schedlbauer

Re: Restrict student access to course by date

by Percy Astocaza -

Thank you very much Sebastian, I have a solid idea now smile

In reply to Marina Glancy

Re: Restrict student access to course by date

by Percy Astocaza -

The student has to be enrolled, otherwise he/she will lose his/her grades. Am I right?

In reply to Percy Astocaza

Re: Restrict student access to course by date

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

When enrolment is suspended and/or expired all student grades are still present.

Average of ratings: Useful (1)