module instance only visible to admins

module instance only visible to admins

by tony chesney -
Number of replies: 2
Hi
I'm working on a module that releases (makes visible) resources at a specified time.

Essentially, this works by flipping the "visible" field in the course_modules table at a time which is stored with the resource details in the new module table. Currently, when visible is turned on, the resource does become visible for an admin, but remains hidden for students.

Initially I thought it must be something to do with capabilities / permissions, however there are no permissions relating to the module in the role_capabilities table. I just can't think of anything else that would come into play, but clearly there is something I'm overlooking.
Average of ratings: -
In reply to tony chesney

Re: module instance only visible to admins

by tony chesney -
I found the answer, but if anyone can throw any further light it could be useful.

The answer is that having flipped the visible field in the course_modules table, I needed to run

rebuild_course_cache($courseid);

where $courseid is the course that the module instance belongs to.

This function is called in modedit, so if you create or update a module using the proper forms it is called.

The function updates the modinfo member of the $COURSE global object. This member contains serialized information about all the modules in a course ready for quick access (with minimal database lookup).

So I have 2 questions: why is the course cache apparently used for displaying course information for students, but not for admins (see original post)?

I was surprised to find the course cache not updated even after I logged out, closed the browser, opened a new one and logged back in. Does the cache not get built when you first enter a course after logging in, or when you switch to a new course?


In reply to tony chesney

Re: module instance only visible to admins

by Richard Crawford -
I have no insight into the nature of the course cache or its purpose, but I do want to thank you for the tip on adding rebuild_course_cache() to your functionality, since I'm building a very similar tool and I was having exactly the same problem. I haven't tested it with the rebuild_course_cache() function yet, but I am optimistic that it will work.