From 7580842a16382cbf2ba50f227eacafd4869c1eba Mon Sep 17 00:00:00 2001 From: Thomas Hackl <hackl@data-quest.de> Date: Thu, 7 Oct 2021 09:10:38 +0000 Subject: [PATCH] TIC 11438 Export-Buchungstypen --- app/controllers/resources/admin.php | 14 +++++++++ app/controllers/resources/export.php | 25 ++++++++++++++- app/controllers/resources/print.php | 12 ++++++- app/routes/Resources.php | 2 +- app/views/resources/admin/configuration.php | 15 +++++++++ .../resources/export/resource_bookings.php | 21 +++++++++++-- .../export/select_booking_sources.php | 13 ++++++++ app/views/resources/print/clipboard_rooms.php | 15 ++++++++- .../20210420_export_bookingtypes.php | 31 +++++++++++++++++++ 9 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 db/migrations/20210420_export_bookingtypes.php diff --git a/app/controllers/resources/admin.php b/app/controllers/resources/admin.php index 4f413be98f4..0ce8d41fc20 100644 --- a/app/controllers/resources/admin.php +++ b/app/controllers/resources/admin.php @@ -1056,6 +1056,13 @@ class Resources_AdminController extends AuthenticatedController $this->resources_booking_plan_end_hour = $this->config->RESOURCES_BOOKING_PLAN_END_HOUR; + $this->bookingtypes = [ + 0 => _('Buchung'), + 1 => _('Reservierung'), + 2 => _('Sperrbuchung'), + 3 => _('Planungsbuchung') + ]; + if (Request::submitted('save')) { //Get colors: @@ -1203,6 +1210,11 @@ class Resources_AdminController extends AuthenticatedController $this->resources_booking_plan_end_hour ); + $this->config->store( + 'RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT', + Request::intArray('export_booking_types') + ); + PageLayout::postSuccess( _('Die Konfigurationsoptionen wurden gespeichert!') ); @@ -1212,5 +1224,7 @@ class Resources_AdminController extends AuthenticatedController "colour_id LIKE 'Resources%' ORDER BY colour_id ASC" ); + + $this->export_bookingtypes_default = $this->config->RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT; } } diff --git a/app/controllers/resources/export.php b/app/controllers/resources/export.php index f5220084e28..87d6d8a0df0 100644 --- a/app/controllers/resources/export.php +++ b/app/controllers/resources/export.php @@ -119,6 +119,16 @@ class Resources_ExportController extends AuthenticatedController $this->range_id = Request::get('range_id'); } + // All available booking types. + $this->booking_types = [ + 0 => _('Buchung'), + 1 => _('Reservierung'), + 2 => _('Sperrbuchung'), + 3 => _('Planungsbuchung') + ]; + $this->selected_booking_types = Request::intArray('bookingtypes') ?: + Config::get()->RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT; + //Build sidebar $sidebar = Sidebar::get(); @@ -214,6 +224,16 @@ class Resources_ExportController extends AuthenticatedController ); $this->end->setTime(23, 59, 59); } + + + // All available booking types. + $this->booking_types = [ + 0 => _('Buchung'), + 1 => _('Reservierung'), + 2 => _('Sperrbuchung'), + 3 => _('Planungsbuchung') + ]; + $this->selected_booking_types = Config::get()->RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT; } @@ -317,11 +337,14 @@ class Resources_ExportController extends AuthenticatedController ] ); + $types = Request::intArray('bookingtypes') ?: + Config::get()->RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT; + //Prepare data for export: foreach ($intervals as $interval) { $booking = $interval->booking; - if (!$booking instanceof ResourceBooking) { + if (!$booking instanceof ResourceBooking || !in_array($booking->booking_type, $types)) { continue; } $description = $booking->description; diff --git a/app/controllers/resources/print.php b/app/controllers/resources/print.php index 63da03f8981..a21db5e847f 100644 --- a/app/controllers/resources/print.php +++ b/app/controllers/resources/print.php @@ -128,10 +128,20 @@ class Resources_PrintController extends AuthenticatedController //and In both cases we must collect the selected //clipboard, the selected date and the selected schedule type. //Furthermore a date and the type of schedule has been selected. + // Also check for booking types to export. $this->selected_clipboard_id = Request::get('clipboard_id'); $this->schedule_type = Request::get('schedule_type'); $this->selected_date_string = Request::get('date'); - + $this->selected_booking_types = Request::intArray('bookingtypes') ?: + Config::get()->RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT; + + // All available booking types. + $this->booking_types = [ + 0 => _('Buchung'), + 1 => _('Reservierung'), + 2 => _('Sperrbuchung'), + 3 => _('Planungsbuchung') + ]; if (!$this->clipboard_selected && !$this->print_schedules) { //We have to load all selectable clipboards of the current user: $this->available_clipboards = Clipboard::getClipboardsForUser( diff --git a/app/routes/Resources.php b/app/routes/Resources.php index 652cb8b4882..84b91105b38 100644 --- a/app/routes/Resources.php +++ b/app/routes/Resources.php @@ -378,7 +378,7 @@ class Resources extends \RESTAPI\RouteMap //Get parameters: $booking_types = []; if (!$nobody_access) { - $booking_types = \Request::getArray('booking_types'); + $booking_types = explode(',', \Request::get('booking_types')); } $begin_timestamp = $begin->getTimestamp(); diff --git a/app/views/resources/admin/configuration.php b/app/views/resources/admin/configuration.php index 3b72cc96041..62c1d886bbc 100644 --- a/app/views/resources/admin/configuration.php +++ b/app/views/resources/admin/configuration.php @@ -114,5 +114,20 @@ value="<?= htmlReady($config->RESOURCES_MIN_BOOKING_TIME) ?>"> </label> </fieldset> + <fieldset> + <legend><?= _('Export') ?></legend> + <label> + <?= _('Voreinstellung zu exportierender Buchungstypen') ?> + <select name="export_booking_types[]" class="nested-select" multiple> + <option value="">-- <?= _('Bitte auswählen') ?> --</option> + <? foreach ($bookingtypes as $index => $name) : ?> + <option value="<?= $index ?>"<?= in_array($index, $export_bookingtypes_default) ? + ' selected' : '' ?>> + <?= htmlReady($name) ?> + </option> + <? endforeach ?> + </select> + </label> + </fieldset> <?= \Studip\Button::create(_('Speichern'), 'save') ?> </form> diff --git a/app/views/resources/export/resource_bookings.php b/app/views/resources/export/resource_bookings.php index 39933ded511..144159067a6 100644 --- a/app/views/resources/export/resource_bookings.php +++ b/app/views/resources/export/resource_bookings.php @@ -9,8 +9,8 @@ <input type="hidden" name="selected_resources[]" value="<?= htmlReady($resource->id)?>"> <? endif ?> - <article class="widget"> - <header><?= _('Zeitbereich auswählen') ?></header> + <fieldset> + <legend><?= _('Zeitbereich auswählen') ?></legend> <section> <label> <?= _('Startzeitpunkt') ?> @@ -27,7 +27,22 @@ value="<?= $end->format('H:i')?>"> </label> </section> - </article> + </fieldset> + <fieldset> + <legend><?= _('Belegungstypen auswählen') ?></legend> + <section> + <label> + <?= _('Zu exportierende Belegungstypen') ?> + <select name="bookingtypes[]" multiple class="nested-select"> + <? foreach ($booking_types as $index => $name) : ?> + <option value="<?= $index ?>" + <?= in_array($index, $selected_booking_types) ? ' selected' : '' ?>> + <?= htmlReady($name) ?></option> + <? endforeach ?> + </select> + </label> + </section> + </fieldset> <div data-dialog-button> <?= \Studip\Button::create( _('Exportieren'), diff --git a/app/views/resources/export/select_booking_sources.php b/app/views/resources/export/select_booking_sources.php index 527de27190e..f24b064cb0c 100644 --- a/app/views/resources/export/select_booking_sources.php +++ b/app/views/resources/export/select_booking_sources.php @@ -99,6 +99,19 @@ </tbody> </table> <? endif ?> + <fieldset> + <legend><?= _('Belegungstypen auswählen') ?></legend> + <label> + <?= _('Zu exportierende Belegungstypen') ?> + <select name="bookingtypes[]" multiple class="nested-select"> + <? foreach ($booking_types as $index => $name) : ?> + <option value="<?= $index ?>" + <?= in_array($index, $selected_booking_types) ? ' selected' : '' ?>> + <?= htmlReady($name) ?></option> + <? endforeach ?> + </select> + </label> + </fieldset> <div data-dialog-button> <?= \Studip\Button::create(_('Liste mit Buchungen exportieren')) ?> </div> diff --git a/app/views/resources/print/clipboard_rooms.php b/app/views/resources/print/clipboard_rooms.php index b5b4a0d2497..0cba520d95d 100644 --- a/app/views/resources/print/clipboard_rooms.php +++ b/app/views/resources/print/clipboard_rooms.php @@ -6,6 +6,9 @@ <input type="hidden" name="clipboard_id" value="<?= htmlReady($selected_clipboard_id) ?>"> <input type="hidden" name="schedule_type" value="<?= htmlReady($schedule_type) ?>"> <input type="hidden" name="date" value="<?= htmlReady($selected_date_string) ?>"> + <? foreach ($selected_booking_types as $type) : ?> + <input type="hidden" name="bookingtypes[]" value="<?= $type ?>"> + <? endforeach ?> <fieldset> <? if (!$available_rooms): ?> <?= MessageBox::info( @@ -91,6 +94,16 @@ value="<?= date('d.m.Y') ?>" class="has-date-picker"> </label> + <label> + <?= _('Zu exportierende Belegungstypen') ?> + <select name="bookingtypes[]" multiple class="nested-select"> + <? foreach ($booking_types as $index => $name) : ?> + <option value="<?= $index ?>" + <?= in_array($index, $selected_booking_types) ? ' selected' : '' ?>> + <?= htmlReady($name) ?></option> + <? endforeach ?> + </select> + </label> </fieldset> <div data-dialog-button> <?= \Studip\Button::create( @@ -156,7 +169,7 @@ ), 'method' => 'GET', 'extraParams' => [ - 'booking_types' => [0,1,2], + 'booking_types' => $selected_booking_types, 'display_requests' => 1 ] ] diff --git a/db/migrations/20210420_export_bookingtypes.php b/db/migrations/20210420_export_bookingtypes.php new file mode 100644 index 00000000000..5722f1ef1c5 --- /dev/null +++ b/db/migrations/20210420_export_bookingtypes.php @@ -0,0 +1,31 @@ +<?php + +class ExportBookingTypes extends Migration +{ + + public function description() + { + return 'Adds a config entry for specifying which booking types shall be exported per default'; + } + + protected function up() + { + $query = "INSERT IGNORE INTO `config` ( + `field`, `value`, `type`, `range`, `section`, `mkdate`, `chdate`, `description` + ) VALUES ( + 'RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT', '[0,1,2]', 'array', 'global', 'resources', + UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 'Standardmäßig zu exportierende Belegungstypen' + )"; + DBManager::get()->exec($query); + } + + protected function down() + { + $query = "DELETE FROM `config` + WHERE `field` = 'RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT'"; + DBManager::get()->exec($query); + $query = "DELETE FROM `config_values` + WHERE `field` = 'RESOURCES_EXPORT_BOOKINGTYPES_DEFAULT'"; + DBManager::get()->exec($query); + } +} -- GitLab