diff options
| author | Rasmus Fuhse <fuhse@data-quest.de> | 2025-07-18 14:36:48 +0200 |
|---|---|---|
| committer | Rasmus Fuhse <fuhse@data-quest.de> | 2025-07-18 14:36:48 +0200 |
| commit | 7f48c7fbe034ff47423b145015838454be3d6ddd (patch) | |
| tree | 0aa78d236f3180903199d71c2a6c36223cb2ebf1 /lib/models | |
| parent | 2a3e3ecc72417a7bffbbc572d69282fae571668b (diff) | |
re #5741 : sync tools_activated table according to sem classesissue-5741
Diffstat (limited to 'lib/models')
| -rw-r--r-- | lib/models/Course.php | 32 | ||||
| -rw-r--r-- | lib/models/Institute.php | 5 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/models/Course.php b/lib/models/Course.php index 5678465..cb83219 100644 --- a/lib/models/Course.php +++ b/lib/models/Course.php @@ -353,6 +353,38 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe } ]; + $config['additional_fields']['context_tools'] = [ + 'get' => function (Course $course) { + $tools = $course->tools; + $class = $course->getSemClass(); + $tools_classes = []; + $highest_position = 0; + foreach ($tools as $index => $tool) { + $plugin = PluginManager::getInstance()->getPluginById($tool->plugin_id); + if (!$class->isModuleAllowed(get_class($plugin))) { + $tool->delete(); + unset($tools[$index]); + } else { + $tools_classes[] = get_class($plugin); + $highest_position = max($highest_position, $tool->position); + } + } + $pluginInfos = PluginManager::getInstance()->getPluginInfos('StudipModule'); + foreach ($pluginInfos as $pluginInfo) { + if (!in_array($pluginInfo['class'], $tools_classes) && $class->isModuleMandatory($pluginInfo['class'])) { + $newTool = new ToolActivation();# + $newTool->range_id = $course->id; + $newTool->range_type = 'course'; + $newTool->plugin_id = $pluginInfo['id']; + $newTool->position = ++$highest_position; + $newTool->store(); + $tools[] = $newTool; + } + } + return $tools; + } + ]; + $config['notification_map']['after_create'] = 'CourseDidCreateOrUpdate'; $config['notification_map']['after_store'] = 'CourseDidCreateOrUpdate'; diff --git a/lib/models/Institute.php b/lib/models/Institute.php index fd6a155..19c2f7f 100644 --- a/lib/models/Institute.php +++ b/lib/models/Institute.php @@ -138,6 +138,11 @@ class Institute extends SimpleORMap implements Range $config['additional_fields']['all_status_groups']['get'] = function ($institute) { return Statusgruppen::findAllByRangeId($institute->id, true); }; + $config['additional_fields']['context_tools'] = [ + 'get' => function (Institute $institute) { + return $institute->tools; + } + ]; $config['i18n_fields'] = ['name', 'url']; $config['registered_callbacks']['after_create'][] = 'setDefaultTools'; |
