Automatic Unhide Weeks by Date

Automatic Unhide Weeks by Date

by Paul Baumeister -
Number of replies: 17

Is there a way to automatically unhide each week as a specific date and time? Right now we are having to click on the unhide at the beginning of the week, but sometimes a professor will forget to open the week. I have Moodle ver 1.9.1.

Average of ratings: -
In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Not sure I understand the problem. Could you post a screenshot? smile

In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Paul Baumeister -

 Here is the screen capture. Presently we have to click on the eye to hide and unhide the weeks. Well, sometimes we have professors forget to open the next week for the students. So, we need the weeks to open automatically at a set period of time. I searched the forums and did not see this at all. I know many of the other platforms have this functionality.

In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Hiding a section by the eye makes all the activities in that section inaccessible unless you manually show each activity by its own eye (EDIT: actually, showing activities in hidden section may not be available in 1.9.1). I don't know if that effect is part of your hiding plan.

Here is a simple method which hides all sections but section-0 and the current week section, but that's a "soft" hide, that is, those sections are not displayed but the activities and resources in them remain accessible (from other places).

To test this method simply add a label in section-0, toggle html (<> in the editor toolbar) and add the following css code:

<style type="text/css">tr.section{display:none;}#section-0,tr.current{display:table-row;}</style>

The label will otherwise be empty. See if this works for you. smile

In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

I just tried this out of curiosity and I can only get it to just show section 0 and not the current week?

In reply to Mary Cooch

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Any css solution is theme and moodle version dependent. This solution should work on a standard theme and its close relatives and Moodle 1.9.x. smile

In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

I am using Standard logo , Moodle 1.9.8 and Firefox -but never mind!

and by the way I have been meaning to say for years you are the coolest coder on Moodle I know - you always have really clever workarounds that have taught me a lot - I'm a big fan of your tips smile

In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Paul Baumeister -

Thanks Itamar. I need to make prior weeks to stay open and the new weeks to open automatically according to the date of the week. Is that a possibility also? Is there code that I can use for that?

In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Yes, it is possible with a bit of php and then css. The idea is to classify future weeks as 'future' and then hide them by css. You need to add the red lines to course/format/weeks/format.php (around line 177 in 1.9.9):

$currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
$futureweek = ($weekdate > $timenow);

$currenttext = '';
if (!$thissection->visible) {
$sectionstyle = ' hidden';
} else if ($currentweek) {
$sectionstyle = ' current';
$currenttext = get_accesshide(get_string('currentweek','access'));
} else if ($futureweek) {
$sectionstyle = ' future';
} else {
$sectionstyle = '';
}

Then you add on the course page (as described above) the following css code:

<style type="text/css">#course-view .future{display:none;}</style>

If you need help with the php attach the file here and I'll make the changes for you. smile

(P.S. a natural extension to this approach is to classify past weeks as 'past' and then use css to distinguish these weeks from current and future. This may be useful in case users switch to single view mode on a past week, in which case they can't see the indication of current week)

In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Paul Baumeister -

That is very kind of you. I actually only have 1.9.1 version of Moodle, so I am afraid to add those lines and mess up the file.

Here is my format.php file. Also, where we would I find the course page? Is it in my theme? What would the file name be? If you would do it for us, I would also be willing to pay you for it.

Thanks,

Paul

In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Here is the file. I added comments indicating the extra lines (btw, almost the same version as the one I have in my 1.9.9).

This is a minor modification but to be safe test it first on a dev installation and back up your production site before applying.

Once applied you can see how it works by going to a course that is set to weekly outline, adding a label in section 0, in that label toggling html (<> in the editor toolbar) and adding the following css code:

<style type="text/css">#course-view .future{display:none;}</style>

The label will otherwise be empty.

You can apply this behavior more generally through a theme, in which case you either add the css definition to one or more themes, or create a designated theme (simply by duplicating one of the theme and adding the css definition to the new instance) smile

Average of ratings: Useful (1)
In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Paul Baumeister -

I have it working great. The only thing is I did not think of this until now. But I want only the students to not be able to see the future weeks, but the teacher to be able to see all weeks.

Also, what time would the week show with your changes? Is it 1am of the designated day that the week opens? What time zone is it working off?

In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Itamar Tzadok -

Given this solution, the easiest way to hide the sections only from students is to add to the css code in that label (or theme) the following definition:

#course-view.editing .future{display:table-row;}

Now, the sections will show when editing is on and so the teacher will be able to see them by turning editing on.

Otherwise, hiding/unhiding would have to be set by roles which might require a more complex hack.

The current solution doesn't touch the time calculation so the open/close time of a week should be the same as before applying the hack and the time zone should be that your Moodle installation is set up to.

smile

Average of ratings: Useful (1)
In reply to Itamar Tzadok

Re: Automatic Unhide Weeks by Date

by Brayton Maine -

I've been wondering and searching for this solution for 2.2.2. Do you have any insights as to how this could be added? I've been pulling my hair out every time I forget to unhide my courses.

Thank you in advance for any help you may be able to provide.

Brayton

In reply to Paul Baumeister

Re: Automatic Unhide Weeks by Date

by Maria Rubiales -

Hi there,

I am getting the same problem with the moodle version 2.9 and the previous answer is not valid anymore. So I have sections and are not being displayed automatically when the date of the "restrict access" option of the section arrives (is always shown by default)


However, if the shown section has questions, and the "restrict access" field of the question has been filled out, it is working: it will be hidden till the date arrives.

Thanks in advance for your answers.


BR,

Maria