Availability condition: How to get current module id?

Availability condition: How to get current module id?

by Mark van Hoek -
Number of replies: 3
Picture of Core developers Picture of Plugin developers

I'm building a new availability condition module in which the requirement is to allow access to Activity2 if:

  1. Activity1 was completed within [n] days
  2. If Activity2 has been completed, continue to allow access indefinitely.

I'm trying to build item #2, and it seems I need the course-module id of the *current module* (the one the restriction is being applied to -- "Activity2" here).  It's easy to get the id of the other one.


Can anyone give me a hint?


Average of ratings: -
In reply to Mark van Hoek

Re: Availability condition: How to get current module id?

by Mark van Hoek -
Picture of Core developers Picture of Plugin developers

I'm working in classes/condition.php

In reply to Mark van Hoek

Re: Availability condition: How to get current module id?

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

The file availability/classes/info_module.php file shows how you can use the function get_course_module() on the core_availability\info class.

The functions is_available and get_description both have the core_availability\info parameter. So calling $info->get_course_module() or $info->get_modinfo() in these functions should do the trick. You could also try to use $this->modinfo to collect the necessary information.

Beware that the function can also return null (when the $info is about section availability).

In reply to Renaat Debleu

Re: Availability condition: How to get current module id?

by Mark van Hoek -
Picture of Core developers Picture of Plugin developers

Perfect - thanks a ton, Renaat!

[code php]

    public function is_available($not, \core_availability\info $info, $grabthelot, $userid) {

            $restricted_modinfo = $info->get_course_module();

            error_log(__FILE__.'::'.__FUNCTION__."::Found \$restricted_modinfo id=".print_r($restricted_modinfo->id, true));

[/code]