General developer forum

Moodle Course Module Availability

 
Picture of Jeff Columb
Moodle Course Module Availability
 

I'm running Moodle version 3.1.9 (Build: 2017113) with php version 5.6.33 on a server running Linux.

I work for a company that uses its own course module. I've been tasked with updating the code to handle the changes from the previous moodle (2. something), and everything was working until I encountered the availability changes. I was unable to decipher a method of checking the availability within Moodle itself. All my attempts to utilize the core_availability::info_module resulted in the equivalent of a visibility check which did not appear to take date or profile access restrictions into account. Eventually I had spent longer looking through functions than it would take me to simply decipher it myself so I did that. Unfortunately I then ran into the "Restriction set" being used by some users and I find I can no longer write a quick workaround.

So here I am asking for directions on how to use Moodle's core functions to do what I know what must be possible but have been unable to determine. I don't know what I've missed.

 
Average of ratings: -
moi!!! it is what is is...
Re: Moodle Course Module Availability
Documentation writersParticularly helpful Moodlers
Are you trying to tweak core code? Oh dear, that is a no-no, don't do that, but if you start with the Dev documentation, that might give you an idea on how you can develop for your Moodle without wrecking it. Can you please be a little more specific about what you call a "course module"? For most people here a "Course module" will be the resources and activities placed in a course, and that does not need to be decoded to see if it works or not. ALso, what do you mean by an "availability check"? Are you looking at what resources and activities are available to Users? If so, then that is the wrong way around, availability is determined by accessibility, and accessibility is governed by permissions granted in what you seem to be calling "profile access restrictions", or Roles. 


If you are talking about specific plugins developed by your company, and you want to update them, then I seriously suggest you  start with the Development documentation. There should also be a repository of design and implementation documentation stored somewhere on your company's server written by the original development team, if not then I would suggest someone has been seriously underperforming.  

 
Average of ratings: -
Picture of Jeff Columb
Re: Moodle Course Module Availability
 

As I understand it each course has modules, the different types are in the mdl_modules table, the specific instances are located in the mdl_course_modules table that appear on a course page and can be anything from certificates to forums. In the mdl_course_modules table there is an availability field that is populated by moodle core functions. This is usually something like has a grace >= 70 or the date < May 12, 2018. Moodle must have a way it reads this information. 

My delving into both the code and the dev documentation has led me to the availability class but I have not been able to figure out how to use it. I just need to know how to tell moodle to read the data out of mdl_course_modules->availability and tell me if a user can access a course module based on the availability conditions that have been set on it.

 
Average of ratings: -
Picture of Jeff Noel
Re: Moodle Course Module Availability
 

What is your question ?
Depending on the course_module row, you can have something along those lines within the available field:

{"op":"&","c":[{"type":"profile","sf":"lastname","op":"isequalto","v":"Doe"},{"type":"profile","sf":"firstname","op":"isequalto","v":"John"}],"showc":[false,false]}

 
Average of ratings: -