General developer forum

How to interpret the data in mdl_course_modules

Picture of Jeff Columb
How to interpret the data in mdl_course_modules

How do I read the data in mdl_course_modules->availability?

I have tried using Moodle's functions but I was unable to determine exactly how. For example setting restrict access on a certificate making it available after February 1st, but my code always returns true and appears to have the same result as a simple $cm->uservisible. I know I'm doing something wrong, maybe everything, but I don't know what. 

$get_module_sql = "SELECT id FROM {course_modules} WHERE `instance` = $module_info->id";

$get_module = $DB->get_record_sql($get_module_sql);

$cmid = $get_module->id;

$modinfo = get_fast_modinfo($course, $USER->id);

$cm = $modinfo->get_cm($cmid);

$info = new \core_availability\info_module($cm);

$information = '';

$module_available = $info->is_available($information);


bool(true) bool(true)

And despite these returning true, the module is grayed out and displays the expected message:

Not available unless:

  • It is on or after February 1, 2018
Average of ratings: -
Picture of Darko Miletić
Re: How to interpret the data in mdl_course_modules
Core developersParticularly helpful Moodlers

Take a look at this document:

Have in mind that get_fast_modinfo API has following signature

function get_fast_modinfo($courseorid, $userid = 0, $resetonly = false)

So if you do not explicitly specify the userid the function defaults to the currently logged in user. If that user is teacher or admin he/she will always have access to the activity. Restriction access is intended for students primarily.

Average of ratings: Useful (2)
Picture of Jeff Columb
Re: How to interpret the data in mdl_course_modules

Thank you for your help Darko,

As expected I feel a fool. I had been using what I thought was a student user but, sure enough, it turned it to have been set as an admin.

Once I tested using a new user everything is returning expected results. Thank you again.

Average of ratings: -