Skip to content
Snippets Groups Projects
Commit e67b2835 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

transfer CourseHistory plugin into main, fixes #1497

Closes #1497

Merge request studip/studip!936
parent ec07c503
No related branches found
No related tags found
No related merge requests found
<?php
final class Course_HistoryController extends AuthenticatedController
{
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
if (!Context::isCourse()) {
throw new Exception('History view is only available for courses');
}
if (!$GLOBALS['perm']->have_studip_perm('admin', Context::getId())) {
throw new AccessDeniedException();
}
Navigation::activateItem('/course/main/history');
PageLayout::setTitle(_('Änderungsverlauf'));
}
public function index_action()
{
$this->history = $this->getHistory(Context::get());
}
private function getHistory(Course $course): array
{
$result = [];
LogEvent::findEachBySQL(
function (LogEvent $event) use (&$result) {
if (!isset($result[$event->action_id])) {
$result[$event->action_id] = [
'name' => "{$event->action->name}: {$event->action->description}",
'events' => [],
];
}
$result[$event->action_id]['events'][] = $event;
},
"? IN (affected_range_id, coaffected_range_id, user_id) ORDER BY mkdate DESC",
[$course->id]
);
$result = array_values($result);
usort($result, function ($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
return $result;
}
}
<?php
$sanitizeEvent = function (LogEvent $event) {
$info = preg_replace('/chdate:\s+(\d+)\s+=&gt;\s+(\d+)/', '', $event->formatEvent());
$info = str_replace('admission_turnout', _('max. Teilnehmerzahl'), $info);
$info = str_replace('=&gt;', '&rarr;', $info);
return $info;
};
?>
<? if (!$history): ?>
<?= MessageBox::info(_('Es konnten keine Logeinträge gefunden werden.'))->hideClose() ?>
<? else: ?>
<table class="default collapsable">
<colgroup>
<col style="width: 150px">
<col>
</colgroup>
<? foreach ($history as $index => $type): ?>
<tbody <? if ($index > 0) echo 'class="collapsed"'; ?>>
<tr class="header-row">
<th colspan="2" class="toggle-indicator">
<a class="toggler">
<?= htmlReady($type['name']) ?>
</a>
</th>
</tr>
<? foreach ($type['events'] as $event): ?>
<tr>
<td><?= strftime('%x %X', $event->mkdate) ?></td>
<td>
<?= $sanitizeEvent($event) ?>
<? if ($event->info && $GLOBALS['perm']->have_perm('root')): ?>
<br><?= _('Info') ?>: <?= htmlReady($event->info) ?>
<? endif ?>
<? if ($event->dbg_info && $GLOBALS['perm']->have_perm('root')): ?>
<br><?= _('Debug') ?>: <?= htmlReady($event->dbg_info) ?>
<? endif ?>
</td>
</tr>
<? endforeach ?>
</tbody>
<? endforeach ?>
</table>
<? endif; ?>
...@@ -100,6 +100,9 @@ class CoreOverview extends CorePlugin implements StudipModule ...@@ -100,6 +100,9 @@ class CoreOverview extends CorePlugin implements StudipModule
if (!$sem_class['studygroup_mode']) { if (!$sem_class['studygroup_mode']) {
$navigation->addSubNavigation('details', new Navigation(_('Details'), 'dispatch.php/course/details/')); $navigation->addSubNavigation('details', new Navigation(_('Details'), 'dispatch.php/course/details/'));
} }
if ($GLOBALS['perm']->have_studip_perm('admin', $course_id)) {
$navigation->addSubNavigation('history', new Navigation(_('Änderungsverlauf'), 'dispatch.php/course/history'));
}
} }
return ['main' => $navigation]; return ['main' => $navigation];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment