diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-25 17:33:31 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-10-30 21:13:56 +0100 |
commit | 7f61dc95be4ac543986c7df2459532fd8f81368d (patch) | |
tree | 930497c659bbaa3e073313a261f3458348fd423d /includes/model | |
parent | 63d1292bf80d88be40eec7695c1a59f29e6609c5 (diff) |
EventConfig: Merge event configuration from database to global config
Diffstat (limited to 'includes/model')
-rw-r--r-- | includes/model/EventConfig_model.php | 78 | ||||
-rw-r--r-- | includes/model/UserWorkLog_model.php | 10 | ||||
-rw-r--r-- | includes/model/User_model.php | 46 |
3 files changed, 35 insertions, 99 deletions
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 @@ -<?php - -use Engelsystem\Database\DB; - -/** - * Get event config. - * - * @return array|null - */ -function EventConfig() -{ - $config = DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1'); - - return empty($config) ? null : $config; -} - -/** - * Update event config. - * - * @param string $event_name - * @param int $buildup_start_date - * @param int $event_start_date - * @param int $event_end_date - * @param int $teardown_end_date - * @param string $event_welcome_msg - * @return bool - */ -function EventConfig_update( - $event_name, - $buildup_start_date, - $event_start_date, - $event_end_date, - $teardown_end_date, - $event_welcome_msg -) { - $eventConfig = EventConfig(); - if (empty($eventConfig)) { - return DB::insert(' - INSERT INTO `EventConfig` ( - `event_name`, - `buildup_start_date`, - `event_start_date`, - `event_end_date`, - `teardown_end_date`, - `event_welcome_msg` - ) - VALUES (?, ?, ?, ?, ?, ?) - ', - [ - $event_name, - $buildup_start_date, - $event_start_date, - $event_end_date, - $teardown_end_date, - $event_welcome_msg - ] - ); - } - - return (bool)DB::update(' - UPDATE `EventConfig` SET - `event_name` = ?, - `buildup_start_date` = ?, - `event_start_date` = ?, - `event_end_date` = ?, - `teardown_end_date` = ?, - `event_welcome_msg` = ? - ', - [ - $event_name, - $buildup_start_date, - $event_start_date, - $event_end_date, - $teardown_end_date, - $event_welcome_msg, - ] - ); -} diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index ff39ba8f..dd4b2574 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -1,5 +1,6 @@ <?php +use Carbon\Carbon; use Engelsystem\Database\Db; /** @@ -128,10 +129,13 @@ function UserWorkLog_create($userWorkLog) function UserWorkLog_new($user) { $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', time())); - $event_config = EventConfig(); - if (!empty($event_config['buildup_start_date'])) { - $work_date = parse_date('Y-m-d H:i', date('Y-m-d 00:00', $event_config['buildup_start_date'])); + + /** @var Carbon $buildup */ + $buildup = $buildup = config('buildup_start'); + if (!empty($buildup)) { + $work_date = $buildup->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 @@ <?php +use Carbon\Carbon; use Engelsystem\Database\DB; use Engelsystem\ValidationResult; @@ -359,19 +360,23 @@ function User_validate_planned_arrival_date($planned_arrival_date) // null is not okay return new ValidationResult(false, time()); } - $event_config = EventConfig(); - if (empty($event_config)) { - // Nothing to validate against - return new ValidationResult(true, $planned_arrival_date); - } - if (isset($event_config['buildup_start_date']) && $planned_arrival_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_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); } |