From 7f61dc95be4ac543986c7df2459532fd8f81368d Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 25 Sep 2018 17:33:31 +0200 Subject: EventConfig: Merge event configuration from database to global config --- includes/model/EventConfig_model.php | 78 ------------------------------------ includes/model/UserWorkLog_model.php | 10 +++-- includes/model/User_model.php | 46 ++++++++++++--------- 3 files changed, 35 insertions(+), 99 deletions(-) delete mode 100644 includes/model/EventConfig_model.php (limited to 'includes/model') diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php deleted file mode 100644 index 766a5849..00000000 --- a/includes/model/EventConfig_model.php +++ /dev/null @@ -1,78 +0,0 @@ -format('Y-m-d H:i'); } + return [ 'user_id' => $user['UID'], 'work_timestamp' => $work_date, diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 092ddf27..051f8ff6 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -1,5 +1,6 @@ get('buildup_start'); + $teardown = $config->get('teardown_end'); + + /** @var Carbon $buildup */ + if (!empty($buildup) && $buildup->greaterThan(Carbon::createFromTimestamp($planned_arrival_date))) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $buildup->getTimestamp()); } - if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) { + + /** @var Carbon $teardown */ + if (!empty($teardown) && $teardown->lessThan(Carbon::createFromTimestamp($planned_arrival_date))) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $teardown->getTimestamp()); } + return new ValidationResult(true, $planned_arrival_date); } @@ -388,23 +393,28 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de // null is okay return new ValidationResult(true, null); } + if ($planned_arrival_date > $planned_departure_date) { // departure cannot be before arrival return new ValidationResult(false, $planned_arrival_date); } - $event_config = EventConfig(); - if (empty($event_config)) { - // Nothing to validate against - return new ValidationResult(true, $planned_departure_date); - } - if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) { + + $config = config(); + $buildup = $config->get('buildup_start'); + $teardown = $config->get('teardown_end'); + + /** @var Carbon $buildup */ + if (!empty($buildup) && $buildup->greaterThan(Carbon::createFromTimestamp($planned_departure_date))) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $buildup->getTimestamp()); } - if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) { + + /** @var Carbon $teardown */ + if (!empty($teardown) && $teardown->lessThan(Carbon::createFromTimestamp($planned_departure_date))) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $teardown->getTimestamp()); } + return new ValidationResult(true, $planned_departure_date); } -- cgit v1.2.3-54-g00ecf