Hidden sections flag

Hidden sections flag

by Richard Crawford -
Number of replies: 1
I've been working on a script that will run on a nightly basis and "unhide" hidden sections on their release date. My script checks the current time against a new "releasedate" field in the mdl_course_sections table and sets the "hidden" field from 1 to 0.

It seems, though, that there's more to "unhiding" a section and all the modules within it than simply switching the value of the "hidden" field from 0 to 1. When my script runs, the section is marked as visible -- the eye is open -- but students are unable to see the section. We can get around this by hiding and then unhiding the section manually, but this defeats the purpose of the script.

So how are sections that are marked as "hidden" flagged in the database besides the "hidden" field in the mdl_course_sections table?

We're using Moodle 1.9.3. Because of heavy modifications we've made to our code, upgrading is not an option for us.
Average of ratings: -
In reply to Richard Crawford

Re: Hidden sections flag

by Stefan Nychka -

Hey.

I was looking into similar things, and noted no one had answered this.

So, here's a place to start.

It's likely not so simple.  Look at the code that's triggered when a section is hidden/revealed:

  • Namely, the course/lib.php's set_section_visible function.
    • It's called from course/view.php.
  • Note set_section_visible not only sets the visible field for a section, but calls set_coursemodule_visible (in the same lib.php) to set each module's visibility within that section.
  • Further, each module has a visibleold field, too, which is critical (see the function for its use ... it basically allows a module, when a section is revealed, to revert to its prior setting.  Otherwise, everything would remain hidden.)
  • And, back to set_section_visible, note the call to rebuild_course_cache.  I'm not certain about its role, but I believe it grabs the new settings out of the db, shoves them into Moodle's memory (likely an array), so Moodle knows how to display a course.

So, I'd highly recommend not manipulating the db manually, but first understanding the above info. better than I, then using those functions, maybe just set_section_visible, to properly update the db.  (Test on a develop. comp. first, of course.)

Note

  • I only looked at the code.  I haven't tried any of this.  It's likely I'm missing at least a few things (e.g., it seems calling set_section_visible properly would do the trick, but there may be adverse side-effects).
  • I'm really uncertain about rebuild_course_cache ... especially investigate that further.  One tangible reason is that your change in the db resulted in a change to moodle, sans a direct call to rebuild_course_cache; so, I obviously don't know when this is triggered, thus am not sure if you need to or don't need to, should or should not, call it.
  • I was looking at 1.9.9.  I doubt it makes a big difference, but it very well may.

Cheers