General developer forum

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

 
Picture of Roel Cantada
Request for help in implementing a maintenance mode setting for the course context
Core developersTranslators

I'm trying to implement a proof of concept for adding course settings that will set the course in maintenance mode. In other words a maintenance mode at the course level. This had been in my mind for years now and it is only now that I can articulate it but I just can't figure out the code. If anyone has done this already I'd appreciate any info.

The problem I'm trying to solve is this. When students are enrolled two weeks before the start of classes, course sites are hidden so students get frustrated and send support request that basically just asks where their courses are. As far as I know visibility has only two settings, hide and show, so students have no idea where the course site is until it is shown by the teacher. This is a situation wherein the control of the visibility of the course site is with the teacher.

Anyways I've been using meta linked courses as workaround (the topic for my proposed paper in MoodleMoot Philippines on April 2018) but I think a simple setting for maintenance mode at the course level is what is really needed. What I've done so far is to mock up what I mean by course maintenance mode as shown in the screenshot that was done by hacking moodle/course/view.php with:

21 //course maintenance mode test start
22     $maintenance_mode = 1;
23 //course maintenance mode test end
...

268 //maintenance test start 2
269    if ($USER->editing == 0 && $maintenance_mode == 1) {
270    echo "<h1>This course site is in maintenance mode.</h1>";
271    } else {
272 //maintenance test end 2

display maintenance mode in course

The problems that I need help are:

1. How to display the maintenance text only for users without editing capabilities. Those with editing capabilites should see the normal course page.

2. How to get rid of nav block menu items except for participants, for users without editing capabilities. Those with editing capabilities should see the normal nav block.

3. and how to add custom message text box in the settings.

The settings would simply add a select yes/no setting in the course editing page like so:

mock up of course maintenance setting

I guess I should add a db field for this but I don't know where to put it.

Any hints would be appreciated. I've attached some of the files in /moodle/course I've been trying to hack.





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: -