first
This commit is contained in:
53
app/Services/RegistrationPeriodService.php
Normal file
53
app/Services/RegistrationPeriodService.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Election;
|
||||
use App\Models\ElectionSetting;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class RegistrationPeriodService
|
||||
{
|
||||
public function isOpen(Election $election, ?Carbon $date = null): bool
|
||||
{
|
||||
/** @var ElectionSetting|null $setting */
|
||||
$setting = $election->settings;
|
||||
|
||||
if ($setting === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($setting->is_registration_open_override !== null) {
|
||||
return $setting->is_registration_open_override;
|
||||
}
|
||||
|
||||
if (! $setting->is_registration_open) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentDate = ($date ?? now())->toDateString();
|
||||
|
||||
return Carbon::parse($setting->registration_start_date)->toDateString() <= $currentDate
|
||||
&& Carbon::parse($setting->registration_end_date)->toDateString() >= $currentDate;
|
||||
}
|
||||
|
||||
public function closedMessage(Election $election): string
|
||||
{
|
||||
/** @var ElectionSetting|null $setting */
|
||||
$setting = $election->settings;
|
||||
|
||||
if ($setting === null) {
|
||||
return 'Pendaftaran belum dibuka untuk pilihanraya ini.';
|
||||
}
|
||||
|
||||
if ($setting->is_registration_open_override === false || ! $setting->is_registration_open) {
|
||||
return 'Pendaftaran permohonan petugas telah ditutup.';
|
||||
}
|
||||
|
||||
return 'Pendaftaran dibuka dari '
|
||||
.Carbon::parse($setting->registration_start_date)->format('d/m/Y')
|
||||
.' hingga '
|
||||
.Carbon::parse($setting->registration_end_date)->format('d/m/Y')
|
||||
.'.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user