libdir.'/externallib.php'); use \local_treestudyplan\studyplan; class enrolcohortsync { private $studyplan; function __construct($studyplan){ $this->studyplan = $studyplan; } function sync(){ // Find the courses that need to be synced to the associated cohorts $courses = $this->studyplan->get_linked_course_ids(); // And find the cohorts that are linked to this studyplan. // Next, for each course that is linked: // 1: check if a link exists // If not, make it (maybe use some of the custom text to list the studyplans involved) // 2: Check if there are cohort links for this studyplan that should be removed // A: Check if there are cohort links that are no longer related to this studyplan // B: Check if these links are valid through another studyplan... // If no one uses the link anymore, deactivate it... } }