diff options
author | msquare <msquare@notrademark.de> | 2016-11-11 16:34:23 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-11-11 16:34:23 +0100 |
commit | 247166f28b81e53c1ebd90285969ca92b67a872f (patch) | |
tree | 2a4391433e0e7b651a8c2b85de9cfc24034c3c68 /includes/model/User_model.php | |
parent | f5a5f234e41a23f56c1515eebc0824ce8cd115d1 (diff) |
improve code of user settings
Diffstat (limited to 'includes/model/User_model.php')
-rw-r--r-- | includes/model/User_model.php | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 4d7bbb65..d3597f54 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -41,7 +41,8 @@ function User_update($user) { `Hometown`='" . sql_escape($user['Hometown']) . "', `got_voucher`='" . sql_escape($user['got_voucher']) . "', `arrival_date`='" . sql_escape($user['arrival_date']) . "', - `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "' + `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "', + `planned_departure_date`='" . sql_escape($user['planned_departure_date']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'"); } @@ -163,6 +164,68 @@ function User_validate_Nick($nick) { } /** + * Validate the planned arrival date + * + * @param int $planned_arrival_date + * Unix timestamp + * @return ValidationResult + */ +function User_validate_planned_arrival_date($planned_arrival_date) { + if ($planned_arrival_date == null) { + // null is not okay + return new ValidationResult(false, time()); + } + $event_config = EventConfig(); + if ($event_config == null) { + // 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']) { + // Planned arrival can not be before buildup start date + return new ValidationResult(false, $event_config['buildup_start_date']); + } + if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) { + // Planned arrival can not be after teardown end date + return new ValidationResult(false, $event_config['teardown_end_date']); + } + return new ValidationResult(true, $planned_arrival_date); +} + +/** + * Validate the planned departure date + * + * @param int $planned_arrival_date + * Unix timestamp + * @param int $planned_departure_date + * Unix timestamp + * @return ValidationResult + */ +function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) { + if ($planned_departure_date == null) { + // 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 ($event_config == null) { + // 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']) { + // Planned arrival can not be before buildup start date + return new ValidationResult(false, $event_config['buildup_start_date']); + } + if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) { + // Planned arrival can not be after teardown end date + return new ValidationResult(false, $event_config['teardown_end_date']); + } + return new ValidationResult(true, $planned_departure_date); +} + +/** * Returns user by id. * * @param $user_id UID |