From c1d83d5536b46c6d0cd7df0ffd6fb3bd4c4a364b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20G=C3=BCnther?=
Date: Sat, 1 Jun 2024 11:07:03 +0200
Subject: [PATCH] Saving tribes as array
---
modules/event-participants/Controllers/class-createevent.php | 2 +-
modules/event-participants/Controllers/class-updateevent.php | 2 +-
modules/event-participants/Views/event-edit-form.php | 4 +++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/modules/event-participants/Controllers/class-createevent.php b/modules/event-participants/Controllers/class-createevent.php
index 7c8ae2c..0b310a0 100644
--- a/modules/event-participants/Controllers/class-createevent.php
+++ b/modules/event-participants/Controllers/class-createevent.php
@@ -17,7 +17,7 @@ class CreateEvent {
$post_data['amount_default'] = str_replace(',', '.', $_POST['amount_default']);
$post_data['amount_social'] = str_replace(',', '.', $_POST['amount_social']);
- $post_data['contributing_tribes'] = str_replace( PHP_EOL, ',', $post_data['contributing_tribes'] );
+ $post_data['contributing_tribes'] = serialize( explode(PHP_EOL, $post_data['contributing_tribes'] ) );
$new_event_id = $dbHandler->insertRows(
'kompass_veranstaltungen_index',
diff --git a/modules/event-participants/Controllers/class-updateevent.php b/modules/event-participants/Controllers/class-updateevent.php
index 30746ad..800a7f6 100644
--- a/modules/event-participants/Controllers/class-updateevent.php
+++ b/modules/event-participants/Controllers/class-updateevent.php
@@ -17,7 +17,7 @@ class UpdateEvent {
$post_data['amount_default'] = str_replace(',', '.', $_POST['amount_default']);
$post_data['amount_social'] = str_replace(',', '.', $_POST['amount_social']);
- $post_data['contributing_tribes'] = str_replace( PHP_EOL, ',', $post_data['contributing_tribes'] );
+ $post_data['contributing_tribes'] = serialize( explode(PHP_EOL, $post_data['contributing_tribes'] ) );
$dbHandler->updateRows(
'kompass_veranstaltungen_index',
diff --git a/modules/event-participants/Views/event-edit-form.php b/modules/event-participants/Views/event-edit-form.php
index 53cabef..f0f04ca 100644
--- a/modules/event-participants/Views/event-edit-form.php
+++ b/modules/event-participants/Views/event-edit-form.php
@@ -5,12 +5,14 @@ use Bdp\Modules\EventParticipants\Models\Event as Event;
function kompass_print_event_edit_form(?int $event_id = null)
{
$event = null;
+ $tribes = '';
if (null === $event_id) {
$page = 'kompass-events&action=create-event';
} else {
$page = 'kompass-events&action=update-event&event-id=' . $event_id;
$event = Event::loadById($event_id);
+ $tribes = implode(PHP_EOL, unserialize($event->contributing_tribes));
}
$events_settings = BDP_LV_PLUGIN_SLUG . '-events-settings';
@@ -101,7 +103,7 @@ function kompass_print_event_edit_form(?int $event_id = null)
'kompass_print_textbox',
$events_settings,
'events_settings',
- ['setting' => 'contributing_tribes', 'style' => 'width: 256px', 'lines' => 5, 'value' => str_replace(',', PHP_EOL, null !== $event ? $event->contributing_tribes : ''), 'appendix' => '
' . __('Please one line per row', BDP_LV_PLUGIN_SLUG)] );
+ ['setting' => 'contributing_tribes', 'style' => 'width: 256px', 'lines' => 5, 'value' => $tribes, 'appendix' => '
' . __('Please one line per row', BDP_LV_PLUGIN_SLUG)] );
do_settings_sections($events_settings);
submit_button();