2016-07-14 10:19:38 +02:00
|
|
|
<?php
|
2016-09-27 17:24:18 +02:00
|
|
|
|
2018-09-25 17:33:31 +02:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Engelsystem\Models\EventConfig;
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function event_config_title()
|
|
|
|
{
|
2018-08-29 21:55:32 +02:00
|
|
|
return __('Event config');
|
2016-07-14 10:19:38 +02:00
|
|
|
}
|
2016-09-27 17:24:18 +02:00
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function event_config_edit_controller()
|
|
|
|
{
|
2018-11-12 14:41:23 +01:00
|
|
|
if (!auth()->can('admin_event_config')) {
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('/'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
$request = request();
|
2018-09-25 17:33:31 +02:00
|
|
|
$config = config();
|
|
|
|
$event_name = $config->get('name');
|
|
|
|
$event_welcome_msg = $config->get('welcome_msg');
|
|
|
|
/** @var Carbon $buildup_start_date */
|
|
|
|
$buildup_start_date = $config->get('buildup_start');
|
|
|
|
/** @var Carbon $event_start_date */
|
|
|
|
$event_start_date = $config->get('event_start');
|
|
|
|
/** @var Carbon $event_end_date */
|
|
|
|
$event_end_date = $config->get('event_end');
|
|
|
|
/** @var Carbon $teardown_end_date */
|
|
|
|
$teardown_end_date = $config->get('teardown_end');
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-11-20 16:02:03 +01:00
|
|
|
if ($request->hasPostData('submit')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$valid = true;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('event_name')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$event_name = strip_request_item('event_name');
|
|
|
|
}
|
|
|
|
if ($event_name == '') {
|
|
|
|
$event_name = null;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-07-18 21:38:53 +02:00
|
|
|
if ($request->has('event_welcome_msg')) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
|
|
|
|
}
|
|
|
|
if ($event_welcome_msg == '') {
|
|
|
|
$event_welcome_msg = null;
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2021-01-02 01:22:05 +01:00
|
|
|
$result = check_request_date('buildup_start_date', __('Please enter buildup start date.'), true, true);
|
2017-01-02 03:57:23 +01:00
|
|
|
$buildup_start_date = $result->getValue();
|
|
|
|
$valid &= $result->isValid();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2021-01-02 01:22:05 +01:00
|
|
|
$result = check_request_date('event_start_date', __('Please enter event start date.'), true, true);
|
2017-01-02 03:57:23 +01:00
|
|
|
$event_start_date = $result->getValue();
|
|
|
|
$valid &= $result->isValid();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2021-01-02 01:22:05 +01:00
|
|
|
$result = check_request_date('event_end_date', __('Please enter event end date.'), true, true);
|
2017-01-02 03:57:23 +01:00
|
|
|
$event_end_date = $result->getValue();
|
|
|
|
$valid &= $result->isValid();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2021-01-02 01:22:05 +01:00
|
|
|
$result = check_request_date('teardown_end_date', __('Please enter teardown end date.'), true, true);
|
2017-01-02 03:57:23 +01:00
|
|
|
$teardown_end_date = $result->getValue();
|
|
|
|
$valid &= $result->isValid();
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-01-14 17:47:26 +01:00
|
|
|
if (!is_null($buildup_start_date) && !is_null($event_start_date) && $buildup_start_date > $event_start_date) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$valid = false;
|
2018-08-29 21:55:32 +02:00
|
|
|
error(__('The buildup start date has to be before the event start date.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-01-14 17:47:26 +01:00
|
|
|
if (!is_null($event_start_date) && !is_null($event_end_date) && $event_start_date > $event_end_date) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$valid = false;
|
2018-08-29 21:55:32 +02:00
|
|
|
error(__('The event start date has to be before the event end date.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-01-14 17:47:26 +01:00
|
|
|
if (!is_null($event_end_date) && !is_null($teardown_end_date) && $event_end_date > $teardown_end_date) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$valid = false;
|
2018-08-29 21:55:32 +02:00
|
|
|
error(__('The event end date has to be before the teardown end date.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-01-14 17:47:26 +01:00
|
|
|
if (!is_null($buildup_start_date) && !is_null($teardown_end_date) && $buildup_start_date > $teardown_end_date) {
|
2017-01-02 03:57:23 +01:00
|
|
|
$valid = false;
|
2018-08-29 21:55:32 +02:00
|
|
|
error(__('The buildup start date has to be before the teardown end date.'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if ($valid) {
|
2018-09-25 17:33:31 +02:00
|
|
|
$eventConfig = new EventConfig();
|
|
|
|
|
|
|
|
foreach (
|
|
|
|
[
|
|
|
|
'name' => $event_name,
|
|
|
|
'welcome_msg' => $event_welcome_msg,
|
|
|
|
'buildup_start' => $buildup_start_date,
|
|
|
|
'event_start' => $event_start_date,
|
|
|
|
'event_end' => $event_end_date,
|
|
|
|
'teardown_end' => $teardown_end_date,
|
|
|
|
] as $key => $value
|
|
|
|
) {
|
|
|
|
$eventConfig
|
|
|
|
->findOrNew($key)
|
|
|
|
->setAttribute('name', $key)
|
|
|
|
->setAttribute('value', $value)
|
|
|
|
->save();
|
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
|
|
|
engelsystem_log(
|
2017-12-25 23:12:52 +01:00
|
|
|
sprintf(
|
|
|
|
'Changed event config: %s, %s, %s, %s, %s, %s',
|
|
|
|
$event_name,
|
|
|
|
$event_welcome_msg,
|
2021-01-02 01:22:05 +01:00
|
|
|
$buildup_start_date ? $buildup_start_date->format('Y-m-d H:i') : '',
|
|
|
|
$event_start_date ? $event_start_date->format('Y-m-d H:i') : '',
|
|
|
|
$event_end_date ? $event_end_date->format('Y-m-d H:i') : '',
|
|
|
|
$teardown_end_date ? $teardown_end_date->format('Y-m-d H:i') : ''
|
2017-11-19 10:32:21 +01:00
|
|
|
)
|
2017-01-02 15:43:36 +01:00
|
|
|
);
|
2023-10-01 22:33:58 +02:00
|
|
|
success(__('settings.success'));
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('admin_event_config'));
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2016-07-14 10:19:38 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
return [
|
2017-01-02 15:43:36 +01:00
|
|
|
event_config_title(),
|
|
|
|
EventConfig_edit_view(
|
|
|
|
$event_name,
|
|
|
|
$event_welcome_msg,
|
|
|
|
$buildup_start_date,
|
|
|
|
$event_start_date,
|
|
|
|
$event_end_date,
|
|
|
|
$teardown_end_date
|
2023-02-05 18:03:00 +01:00
|
|
|
),
|
2017-01-02 15:43:36 +01:00
|
|
|
];
|
2016-07-14 10:19:38 +02:00
|
|
|
}
|