General developer forum

Request for help in implementing a maintenance mode setting for the course context

 
Picture of Richard Oelmann
Re: Request for help in implementing a maintenance mode setting for the course context
Core developersParticularly helpful MoodlersPlugin developersTesters

I had a similar issue but took a different approach.

I added a conditional which creates a class added to body, based on the start date of the course and whether the user had editing rights. Then added some css to hide the course content and show a notice banner until 2 weeks prior to the course start date.

Very simplified psuedo code:

In layout

IF (now > 2weeks before startdate AND user != editor) {add 'hidecontent' to body class}

In stylesheet

body.hidecontent .contenthiddenbanner {display:block}

body.hidecontent .maincontent {display:none}

(on boost themes, rather than clean/more based ones, I think this would be page-content and maybe would also need to target the nav-drawer, but I'm not at my test system right now to check my code - but essentially with the relevant body tag in place you can target whatever other selectors within that as needed)

There's actually a bit more to what I did than that, because in fact I went with only displaying the hidden content when editing is turned on, had a different contenthidden banner for students and editors, and obviously the layout file also has to include the contenthidden banner that I haven't put here (Its just actually a bootstrap alert in practice), but that's the basic principle - much easier than implementing a full maintenance mode for a single context.

Essentially its automatic - teachers can reveal their course early if they want to, by altering the course start date, or using a different theme if that's allowed on the site. But the students get to see their modules as soon as they are enrolled, but dont get the content until 2 weeks before the start of the semester.

 
Average of ratings: -