You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/controller/event_config_controller.php

137 lines
4.6 KiB
PHTML

<?php
use Carbon\Carbon;
use Engelsystem\Models\EventConfig;
/**
* @return string
*/
8 years ago
function event_config_title()
{
return __('Event config');
}
/**
* @return array
*/
8 years ago
function event_config_edit_controller()
{
if (!auth()->can('admin_event_config')) {
redirect(page_link_to('/'));
8 years ago
}
8 years ago
$request = request();
$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');
8 years ago
if ($request->hasPostData('submit')) {
8 years ago
$valid = true;
8 years ago
if ($request->has('event_name')) {
8 years ago
$event_name = strip_request_item('event_name');
}
if ($event_name == '') {
$event_name = null;
}
8 years ago
if ($request->has('event_welcome_msg')) {
8 years ago
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
}
if ($event_welcome_msg == '') {
$event_welcome_msg = null;
}
8 years ago
$result = check_request_date('buildup_start_date', __('Please enter buildup start date.'), true);
8 years ago
$buildup_start_date = $result->getValue();
$valid &= $result->isValid();
8 years ago
$result = check_request_date('event_start_date', __('Please enter event start date.'), true);
8 years ago
$event_start_date = $result->getValue();
$valid &= $result->isValid();
8 years ago
$result = check_request_date('event_end_date', __('Please enter event end date.'), true);
8 years ago
$event_end_date = $result->getValue();
$valid &= $result->isValid();
8 years ago
$result = check_request_date('teardown_end_date', __('Please enter teardown end date.'), true);
8 years ago
$teardown_end_date = $result->getValue();
$valid &= $result->isValid();
8 years ago
if (!is_null($buildup_start_date) && !is_null($event_start_date) && $buildup_start_date > $event_start_date) {
8 years ago
$valid = false;
error(__('The buildup start date has to be before the event start date.'));
8 years ago
}
8 years ago
if (!is_null($event_start_date) && !is_null($event_end_date) && $event_start_date > $event_end_date) {
8 years ago
$valid = false;
error(__('The event start date has to be before the event end date.'));
8 years ago
}
8 years ago
if (!is_null($event_end_date) && !is_null($teardown_end_date) && $event_end_date > $teardown_end_date) {
8 years ago
$valid = false;
error(__('The event end date has to be before the teardown end date.'));
8 years ago
}
8 years ago
if (!is_null($buildup_start_date) && !is_null($teardown_end_date) && $buildup_start_date > $teardown_end_date) {
8 years ago
$valid = false;
error(__('The buildup start date has to be before the teardown end date.'));
8 years ago
}
8 years ago
8 years ago
if ($valid) {
$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();
}
8 years ago
engelsystem_log(
sprintf(
'Changed event config: %s, %s, %s, %s, %s, %s',
$event_name,
$event_welcome_msg,
$buildup_start_date ? $buildup_start_date->format('Y-m-d') : '',
$event_start_date ? $event_start_date->format('Y-m-d') : '',
$event_end_date ? $event_end_date->format('Y-m-d') : '',
$teardown_end_date ? $teardown_end_date->format('Y-m-d') : ''
)
8 years ago
);
success(__('Settings saved.'));
8 years ago
redirect(page_link_to('admin_event_config'));
}
}
8 years ago
8 years ago
return [
8 years ago
event_config_title(),
EventConfig_edit_view(
$event_name,
$event_welcome_msg,
$buildup_start_date,
$event_start_date,
$event_end_date,
$teardown_end_date
)
];
}