General developer forum

Availability plugin: reference to new activity that is currently being edited

 
Picture of Zimcke Van de Staey
Availability plugin: reference to new activity that is currently being edited
 

We are developing an availability plugin – relative completion – where the availability condition is “must complete the previous activity” in case of adjusting the availability of an activity. When the user selects this condition, the name of the current previous activity should be visible, so that the user understands the meaning of the condition. An example is visible on this screenshot:








In frontend.php we can derive the previous activity from the parameter $cm in the get_javascript_init_params method, by looking at the sequence field in the section of the course module $cm.

/**
 * Gets additional parameters for the plugin's initInner function.
 * Default returns no parameters.
 * @param \stdClass $course Course object
 * @param \cm_info $cm Course-module currently being edited (null if none)
 * @param \section_info $section Section currently being edited (null if none)
 * @return array Array of parameters for the JavaScript function
 */
protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null) {
// if we are adjusting availability of a course module
// use getPreviousActivity($course, $cm) to return previous activity
// else (adjusting section) do something else
}
/**
 * Return the previous visible activity (if any)
 */
private function getPreviousActivity($course, \cm_info $cm = null) {
   // derive the section to which $cm belongs to (current section)
   // derive the previous activity from the sequence of the current section
   // return the previous activity
}

However, if we are creating a new activity $cm will be null because the course module being edited is not yet in the database. I am wondering if there is a different way to derive where we are adding the new activity (e.g. after which other course module)? So that we can display the name of the previous course module even if the current course module is not yet registered.


 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Availability plugin: reference to new activity that is currently being edited
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

When you are creating a new activity, the parameter you have available is the section number/id. The activity gets added at the end of that section.

 
Average of ratings: -
Picture of Zimcke Van de Staey
Re: Availability plugin: reference to new activity that is currently being edited
 

Hi Tim, seems logical, however the $section parameter seems to be null when adding a new activity. It only gives you the section info when the method is called to edit a section. This is also what the documentation specifies in the base class: "@param \section_info $section Section currently being edited (null if none)". 

 
Average of ratings: -