diff --git a/.travis.yml b/.travis.yml index 6cbc5b0..46ea9fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: before_script: - travis_retry composer self-update - travis_retry composer install --prefer-source --no-interaction - - travis_retry composer require php-coveralls/php-coveralls + - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer require php-coveralls/php-coveralls - cp .env.example .env - php artisan key:generate - php artisan storage:link diff --git a/app/Http/Controllers/BirthdayController.php b/app/Http/Controllers/BirthdayController.php new file mode 100644 index 0000000..fd75d65 --- /dev/null +++ b/app/Http/Controllers/BirthdayController.php @@ -0,0 +1,30 @@ +getUpcomingBirthdays(); + + return view('birthdays.index', compact('users')); + } + + private function getUpcomingBirthdays() + { + $birthdayDateRaw = "concat(YEAR(CURDATE()), '-', RIGHT(dob, 5)) as birthday_date"; + + $userBirthdayQuery = User::whereNotNull('dob') + ->select('users.name', 'users.dob', 'users.id as user_id', DB::raw($birthdayDateRaw)) + ->orderBy('birthday_date', 'asc') + ->havingBetween('birthday_date', [today()->format('Y-m-d'), today()->addDays(60)->format('Y-m-d')]); + + $users = $userBirthdayQuery->get(); + + return $users; + } +} diff --git a/app/User.php b/app/User.php index cd98314..a9dd05a 100644 --- a/app/User.php +++ b/app/User.php @@ -3,9 +3,9 @@ namespace App; use Carbon\Carbon; -use Ramsey\Uuid\Uuid; -use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; +use Ramsey\Uuid\Uuid; class User extends Authenticatable { @@ -284,4 +284,27 @@ class User extends Authenticatable { return '
'.$this->age.' '.trans_choice('user.age_years', $this->age).'
'; } + + public function getBirthdayAttribute() + { + if (!$this->dob) { + return; + } + + $birthdayDate = date('Y').substr($this->dob, 4); + $birthdayDateClass = Carbon::parse($birthdayDate); + + if (Carbon::parse(date('Y-m-d').' 00:00:00')->gt($birthdayDateClass)) { + return $birthdayDateClass->addYear(); + } + + return $birthdayDateClass; + } + + public function getBirthdayRemainingAttribute() + { + if ($this->dob) { + return Carbon::now()->diffInDays($this->birthday, false); + } + } } diff --git a/resources/lang/en/birthday.php b/resources/lang/en/birthday.php new file mode 100644 index 0000000..a90b50b --- /dev/null +++ b/resources/lang/en/birthday.php @@ -0,0 +1,9 @@ + 'Birhtday', + 'upcoming' => 'Upcoming birthdays', + 'remaining' => ':count days', + 'age_years' => ':age years', + 'days' => 'days', +]; diff --git a/resources/lang/id/birthday.php b/resources/lang/id/birthday.php new file mode 100644 index 0000000..7a446a6 --- /dev/null +++ b/resources/lang/id/birthday.php @@ -0,0 +1,9 @@ + 'Ulang Tahun', + 'upcoming' => 'Ulang tahun akan datang', + 'remaining' => ':count hari', + 'age_years' => ':age tahun', + 'days' => 'Hari', +]; diff --git a/resources/views/birthdays/index.blade.php b/resources/views/birthdays/index.blade.php new file mode 100644 index 0000000..713df35 --- /dev/null +++ b/resources/views/birthdays/index.blade.php @@ -0,0 +1,46 @@ +@extends('layouts.app') + +@section('title', __('user.upcoming_birthday')) + +@section('content') + +
+
+
+
+

{{ __('birthday.upcoming') }}

+
+ + + + + + + + + + + @php + $no = 1; + @endphp + @forelse($users as $key => $user) + + + + + + + @empty + + + + @endforelse + +
#{{ __('user.name') }}{{ __('birthday.birthday') }}{{ __('user.age') }}
{{ $no++ }}{{ $user->name }} + {{ $user->birthday->format('j M') }} + ({{ __('birthday.remaining', ['count' => $user->birthday_remaining]) }}) + {{ __('birthday.age_years', ['age' => $user->age]) }}
{{ __('user.no_upcoming_birthday', ['days' => 60]) }}
+
+
+
+@endsection diff --git a/resources/views/layouts/partials/nav.blade.php b/resources/views/layouts/partials/nav.blade.php index dbd2c12..00a14f3 100644 --- a/resources/views/layouts/partials/nav.blade.php +++ b/resources/views/layouts/partials/nav.blade.php @@ -19,13 +19,14 @@