Availability condition: How to get current module id?

Availability condition: How to get current module id?

av Mark van Hoek -
Antall svar: 3
Bilde av Core developers Bilde av 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?


Gjennomsnittlig vurdering: -
Som svar til Mark van Hoek

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

av Mark van Hoek -
Bilde av Core developers Bilde av Plugin developers

I'm working in classes/condition.php

Som svar til Mark van Hoek

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

av Renaat Debleu -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av 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).

Som svar til Renaat Debleu

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

av Mark van Hoek -
Bilde av Core developers Bilde av 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]