diff options
| author | Thomas Hackl <hackl@data-quest.de> | 2023-06-28 13:27:46 +0000 |
|---|---|---|
| committer | Thomas Hackl <hackl@data-quest.de> | 2023-06-28 13:27:46 +0000 |
| commit | 559ab723fabd4d10f26e7df631808e4cb8d91c9b (patch) | |
| tree | 91ef8cf94eba86973baf3efabca1cdbb8bf6826b /app/controllers/tree.php | |
| parent | b7f0f8bcaad8fefd96fd3e6316377eda53929ad3 (diff) | |
Resolve "Neuentwicklung Verzeichnisstrukturen"
Closes #1664, #2693, and #2692
Merge request studip/studip!1081
Diffstat (limited to 'app/controllers/tree.php')
| -rw-r--r-- | app/controllers/tree.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/controllers/tree.php b/app/controllers/tree.php new file mode 100644 index 0000000..7665b60 --- /dev/null +++ b/app/controllers/tree.php @@ -0,0 +1,55 @@ +<?php + +class TreeController extends AuthenticatedController +{ + public function export_csv_action() + { + if (!Request::isPost()) { + throw new MethodNotAllowedException(); + } + + $ids = explode(',', Request::get('courses', '')); + $courses = Course::findMany($ids); + + $captions = [ + _('Veranstaltungsnummer'), + _('Name'), + _('Semester'), + _('Zeiten'), + _('Lehrende') + ]; + + $data = []; + foreach ($courses as $course) { + $sem = Seminar::getInstance($course->id); + $lecturers = SimpleCollection::createFromArray( + CourseMember::findByCourseAndStatus($course->id, 'dozent') + )->orderBy('position, nachname, vorname'); + + $lecturersSorted = array_map( + function ($l) { + return implode(', ', $l); + }, + $lecturers->toArray('nachname vorname title_front title_rear') + ); + + $data[] = [ + $course->veranstaltungsnummer, + $course->getFullname('type-number-name'), + $course->getTextualSemester(), + $sem->getDatesExport(), + implode(', ', $lecturersSorted) + ]; + } + + $tmpname = md5(uniqid('ErgebnisVeranstaltungssuche')); + if (array_to_csv($data, $GLOBALS['TMP_PATH'] . '/' . $tmpname, $captions)) { + $this->render_text(FileManager::getDownloadURLForTemporaryFile( + $tmpname, + 'veranstaltungssuche.csv' + )); + } else { + $this->set_status(400, 'The csv could not be created.'); + } + } +} |
