aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/course/contentmodules.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-03-15 15:27:29 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-03-15 15:27:29 +0000
commit12cbd92f09f249ac7f6f1fb497c5820d46f8f1c1 (patch)
tree0ea783470d00e63c4eb5928d1f0151502f64f7c2 /app/controllers/course/contentmodules.php
parent7cbf3c537e4e05e8de9b2695ba6d55d820dbdd45 (diff)
fixes #3801
Closes #3801 Merge request studip/studip!2673
Diffstat (limited to 'app/controllers/course/contentmodules.php')
-rw-r--r--app/controllers/course/contentmodules.php58
1 files changed, 47 insertions, 11 deletions
diff --git a/app/controllers/course/contentmodules.php b/app/controllers/course/contentmodules.php
index adb3055..6dc6c2d 100644
--- a/app/controllers/course/contentmodules.php
+++ b/app/controllers/course/contentmodules.php
@@ -299,18 +299,8 @@ class Course_ContentmodulesController extends AuthenticatedController
'displayname' => $displayname,
'visibility' => $visibility,
'active' => (bool) $tool,
+ 'icon' => $this->getIconFromMetadata($metadata, $plugin),
];
- if (!empty($metadata['icon_clickable'])) {
- $list[$plugin_id]['icon'] = $metadata['icon_clickable'] instanceof Icon
- ? $metadata['icon_clickable']->asImagePath()
- : Icon::create($plugin->getPluginURL().'/'.$metadata['icon_clickable'])->asImagePath();
- } elseif (!empty($metadata['icon'])) {
- $list[$plugin_id]['icon'] = $metadata['icon'] instanceof Icon
- ? $metadata['icon']->asImagePath()
- : Icon::create($plugin->getPluginURL().'/'.$metadata['icon'])->asImagePath();
- } else {
- $list[$plugin_id]['icon'] = null;
- }
$list[$plugin_id]['summary'] = $metadata['summary'] ?? null;
$list[$plugin_id]['mandatory'] = $this->sem_class->isModuleMandatory(get_class($plugin));
$list[$plugin_id]['highlighted'] = (bool) $plugin->isHighlighted();
@@ -320,4 +310,50 @@ class Course_ContentmodulesController extends AuthenticatedController
return $list;
}
+
+ /**
+ * @param array $metadata
+ * @param CorePlugin|StudIPPlugin $plugin
+ */
+ private function getIconFromMetadata(array $metadata, $plugin): ?string
+ {
+ $icon = $metadata['icon_clickable'] ?? $metadata['icon'] ?? null;
+
+ if (!$icon) {
+ return null;
+ }
+
+ if ($plugin instanceof StudIPPlugin) {
+ $path = $GLOBALS['ABSOLUTE_PATH_STUDIP'] . '/' . $plugin->getPluginPath() . '/' . $icon;
+ $icon = $this->getCoreIcon($path) ?? $icon;
+ }
+
+ if (!$icon instanceof Icon) {
+ $icon = Icon::create($plugin->getPluginURL() . '/' . $icon);
+ }
+
+ return $icon->copyWithRole(Icon::ROLE_CLICKABLE)->asImagePath();
+ }
+
+ private function getCoreIcon(string $path): ?Icon
+ {
+ $path = realpath($path);
+
+ if (!file_exists($path)) {
+ return null;
+ }
+
+ try {
+ $icon = basename($path, '.svg');
+ $color = basename(dirname($path));
+ $roles = Icon::colorToRoles($color);
+
+ return Icon::create($icon, $roles[0]);
+ } catch (Exception $e) {
+ return null;
+ }
+
+
+
+ }
}