aboutsummaryrefslogtreecommitdiff
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
parent2a3e3ecc72417a7bffbbc572d69282fae571668b (diff)
re #5741 : sync tools_activated table according to sem classesissue-5741
-rw-r--r--lib/models/Course.php32
-rw-r--r--lib/models/Institute.php5
-rw-r--r--lib/navigation/CourseNavigation.php2
3 files changed, 38 insertions, 1 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';
diff --git a/lib/navigation/CourseNavigation.php b/lib/navigation/CourseNavigation.php
index d4c7919..efab919 100644
--- a/lib/navigation/CourseNavigation.php
+++ b/lib/navigation/CourseNavigation.php
@@ -59,7 +59,7 @@ class CourseNavigation extends Navigation
$found = null;
$where = null;
- foreach ($this->range->tools as $tool) {
+ foreach ($this->range->context_tools as $tool) {
if ($found && $tool->metadata['navigation']) {
$where = $tool->metadata['navigation'];
break;