-
app/Helpers/BirthdayHelper.php
Open in GitHubuse Carbon\Carbon; class BirthdayHelper { // public static function isBirthdayInXDays(Carbon $startDate, Carbon $birthdate, int $numberOfDays): bool { $future = $startDate->copy()->addDays($numberOfDays); $birthdate->year = $startDate->year; if ($birthdate->isPast()) { return false; } return $birthdate->lessThanOrEqualTo($future) && $future->greaterThanOrEqualTo($startDate); } // }
-
app/Http/ViewHelpers/Team/TeamShowViewHelper.php
Open in GitHubuse Carbon\Carbon; use App\Models\Company\Team; use App\Helpers\BirthdayHelper; use App\Models\Company\Company; class TeamShowViewHelper { // public static function birthdays(Team $team, Company $company): array { $employees = $team->employees() ->whereNotNull('employees.birthdate') ->where('employees.locked', false) ->get(); // build the collection of data $birthdaysCollection = collect([]); $now = Carbon::now(); foreach ($employees as $employee) { if (! $employee->birthdate) { continue; } if (BirthdayHelper::isBirthdayInXDays($now, $employee->birthdate, 30)) { $birthdaysCollection->push([ 'id' => $employee->id, 'url' => route('employees.show', [ 'company' => $company, 'employee' => $employee, ]), 'name' => $employee->name, 'avatar' => ImageHelper::getAvatar($employee, 35), 'birthdate' => DateHelper::formatMonthAndDay($employee->birthdate), 'sort_key' => Carbon::createFromDate($now->year, $employee->birthdate->month, $employee->birthdate->day)->format('Y-m-d'), ]); } } $birthdaysCollection = $birthdaysCollection->sortBy('sort_key')->values()->all(); return $birthdaysCollection; } // }