aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Course.php
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2025-07-18 14:36:48 +0200
committerRasmus Fuhse <fuhse@data-quest.de>2025-07-18 14:36:48 +0200
commit7f48c7fbe034ff47423b145015838454be3d6ddd (patch)
tree0aa78d236f3180903199d71c2a6c36223cb2ebf1 /lib/models/Course.php
parent2a3e3ecc72417a7bffbbc572d69282fae571668b (diff)
re #5741 : sync tools_activated table according to sem classesissue-5741
Diffstat (limited to 'lib/models/Course.php')
-rw-r--r--lib/models/Course.php32
1 files changed, 32 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';