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.