FS-Mod/FSMod/TagExaminations.php

105 lines
2.7 KiB
PHP

<?php
/**
* Examinations tag from FSMod extracted from FSMod.php
*
* @file
* @ingroup Extensions
* @author Björn Kinscher
* @copyright © 2009 Björn Kinscher
* @modified 2014 Christian Zirkelbach
* @modified 2018,2019 Einhard Leichtfuß
* @modified 2019 Bennet Bleßmann
* @license GNU General Public Licence 2.0 or later
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
class TagExaminations {
static function exLogsRender (?string $input, array $args, Parser $parser, PPFrame $frame) {
$user = $parser->getUserIdentity();
$ip = explode('.', $_SERVER['REMOTE_ADDR']);
if ( !$user->isRegistered() ) {
if ( !FSMod::isCAUIP())
return 'Sie versuchen von außerhalb des Uni-Netzes auf die Protokolle zuzugreifen.';
}
$output = '';
try {
$xml = @new SimpleXMLElement(trim($input));
}
catch (Exception $e) {
return "Ungültiges Datenformat!";
}
$logs = $xml->children();
$data = [];
$sortkeys_date = [];
$sortkeys_reading = [];
$sortkeys_extra = [];
foreach ( $logs as $log ) {
$exam = [
'date' => (integer)$log->date,
'reading' => (string)$log->reading,
'extra' => (count($log->extra) > 0 ? (string)$log->extra : ""),
'type' => $log->type,
'file' => $log->file
];
$sortkeys_date[] = $exam['date'];
$sortkeys_reading[] = $exam['reading'];
$sortkeys_extra[] = $exam['extra'];
$expersons = [];
$examlist = $log->examiners->children();
foreach ( $examlist as $examper ) {
$expersons[] = (string)$examper;
}
$exam['examiners'] = $expersons;
$data[] = $exam;
}
array_multisort($sortkeys_date, SORT_DESC, $sortkeys_reading, SORT_ASC, $sortkeys_extra, SORT_ASC, $data);
//print_r($sortkeys);
//print_r ($data);
$output .= "<table class=\"prettytable sortable\">\n<tr>\n<th>Veranstaltung</th><th>Zusatz</th>\n<th>Pruefer</th>\n<th>Jahr</th>\n<th>Typ</th>\n</tr>\n";
foreach ( $data as $log ) {
$exas = '';
foreach ( $log['examiners'] as $exa ) {
if ( $exas != '' )
$exas .= ', ';
$exas .= $exa;
}
$file_link = $parser->recursiveTagParse("[[Media:{$log['file']}|{$log['reading']}]]",$frame);
$output .= "<tr>\n<td>{$file_link}</td>\n<td>{$log['extra']}</td>\n<td>{$exas}</td>\n<td>{$log['date']}</td>\n<td>{$log['type']}</td>\n</tr>";
}
//return "Protokolle/Klausuren folgen bald!";
$output .= "</tr>\n</table>";
return $output;
}
}