From 33209ea70b94837716b497cfa5dc8059f03ceec3 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 17 Dec 2023 00:34:35 +0100 Subject: [PATCH] Remove unused functions and methods --- includes/controller/users_controller.php | 6 +- includes/includes.php | 1 - includes/model/ShiftsFilter.php | 8 --- includes/model/UserWorkLog_model.php | 24 -------- includes/model/User_model.php | 71 ------------------------ includes/sys_page.php | 17 ------ includes/view/ShiftsFilterRenderer.php | 10 ---- 7 files changed, 5 insertions(+), 132 deletions(-) delete mode 100644 includes/model/UserWorkLog_model.php diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 2e92ccae..91b31114 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -244,6 +244,10 @@ function user_controller() $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . ' h'; } + $worklogs = $user_source->worklogs() + ->with(['user', 'creator']) + ->get(); + return [ htmlspecialchars($user_source->displayName), User_view( @@ -257,7 +261,7 @@ function user_controller() $tshirt_score, auth()->can('admin_active'), auth()->can('admin_user_worklog'), - UserWorkLogsForUser($user_source->id) + $worklogs ), ]; } diff --git a/includes/includes.php b/includes/includes.php index afdb1d81..d8df64f7 100644 --- a/includes/includes.php +++ b/includes/includes.php @@ -18,7 +18,6 @@ $includeFiles = [ __DIR__ . '/../includes/model/ShiftSignupState.php', __DIR__ . '/../includes/model/Stats.php', __DIR__ . '/../includes/model/User_model.php', - __DIR__ . '/../includes/model/UserWorkLog_model.php', __DIR__ . '/../includes/model/ValidationResult.php', __DIR__ . '/../includes/view/AngelTypes_view.php', diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php index 4d31a22f..59fc56aa 100644 --- a/includes/model/ShiftsFilter.php +++ b/includes/model/ShiftsFilter.php @@ -179,14 +179,6 @@ class ShiftsFilter $this->locations = $locations; } - /** - * @return bool - */ - public function isUserShiftsAdmin() - { - return $this->userShiftsAdmin; - } - /** * @param bool $userShiftsAdmin */ diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php deleted file mode 100644 index a6413f78..00000000 --- a/includes/model/UserWorkLog_model.php +++ /dev/null @@ -1,24 +0,0 @@ -whereDate('worked_at', '>=', $sinceTime); - } - $worklogs->with(['user', 'creator']); - - return $worklogs->get(); -} diff --git a/includes/model/User_model.php b/includes/model/User_model.php index c28990de..560ab171 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -5,7 +5,6 @@ use Engelsystem\Database\Db; use Engelsystem\Models\AngelType; use Engelsystem\Models\User\User; use Engelsystem\Models\Worklog; -use Engelsystem\ValidationResult; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; @@ -67,76 +66,6 @@ function Users_by_angeltype_inverted(AngelType $angeltype) ->get(); } -/** - * Validate the planned arrival date - * - * @param int $planned_arrival_date Unix timestamp - * @return ValidationResult - */ -function User_validate_planned_arrival_date($planned_arrival_date) -{ - if (is_null($planned_arrival_date)) { - // null is not okay - return new ValidationResult(false, time()); - } - - $config = config(); - $buildup = $config->get('buildup_start'); - $teardown = $config->get('teardown_end'); - - /** @var Carbon $buildup */ - if (!empty($buildup) && Carbon::createFromTimestamp($planned_arrival_date)->lessThan($buildup->setTime(0, 0))) { - // Planned arrival can not be before buildup start date - return new ValidationResult(false, $buildup->getTimestamp()); - } - - /** @var Carbon $teardown */ - if (!empty($teardown) && Carbon::createFromTimestamp($planned_arrival_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0, 0))) { - // Planned arrival can not be after teardown end date - return new ValidationResult(false, $teardown->getTimestamp()); - } - - 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 (is_null($planned_departure_date)) { - // 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); - } - - $config = config(); - $buildup = $config->get('buildup_start'); - $teardown = $config->get('teardown_end'); - - /** @var Carbon $buildup */ - if (!empty($buildup) && Carbon::createFromTimestamp($planned_departure_date)->lessThan($buildup->setTime(0, 0))) { - // Planned departure can not be before buildup start date - return new ValidationResult(false, $buildup->getTimestamp()); - } - - /** @var Carbon $teardown */ - if (!empty($teardown) && Carbon::createFromTimestamp($planned_departure_date)->greaterThanOrEqualTo($teardown->addDay()->setTime(0, 0))) { - // Planned departure can not be after teardown end date - return new ValidationResult(false, $teardown->getTimestamp()); - } - - return new ValidationResult(true, $planned_departure_date); -} - /** * @param User $user * @return float diff --git a/includes/sys_page.php b/includes/sys_page.php index b0e7b492..70aa7f93 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -197,20 +197,3 @@ function strip_item($item) // Only allow letters, symbols, punctuation, separators and numbers without html tags return preg_replace('/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]+)/ui', '', strip_tags($item)); } - -/** - * Validates an email address with support for IDN domain names. - * - * @param string $email - * @return bool - */ -function check_email($email) -{ - // Convert the domain part from idn to ascii - if (substr_count($email, '@') == 1) { - list($name, $domain) = explode('@', $email); - $domain = idn_to_ascii($domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); - $email = $name . '@' . $domain; - } - return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); -} diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php index a8df82d1..ac08917c 100644 --- a/includes/view/ShiftsFilterRenderer.php +++ b/includes/view/ShiftsFilterRenderer.php @@ -87,14 +87,4 @@ class ShiftsFilterRenderer $this->daySelectionEnabled = true; $this->days = $days; } - - /** - * Should the filter display a day selection. - * - * @return bool - */ - public function isDaySelectionEnabled() - { - return $this->daySelectionEnabled; - } }