68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Models\Election;
|
|
use App\Models\ElectionSetting;
|
|
use App\Models\User;
|
|
|
|
class ElectionSettingsService
|
|
{
|
|
public function create(Election $election, array $data, User $actingUser): ElectionSetting
|
|
{
|
|
$settings = $election->settings()->create([
|
|
'registration_start_date' => $data['registration_start_date'],
|
|
'registration_end_date' => $data['registration_end_date'],
|
|
'polling_date' => $data['polling_date'],
|
|
'is_attendance_active' => $data['is_attendance_active'],
|
|
'is_registration_open_override' => $data['is_registration_open_override'],
|
|
]);
|
|
|
|
activity('admin_settings')
|
|
->performedOn($settings)
|
|
->causedBy($actingUser)
|
|
->withProperties(['election_id' => $election->id, 'after' => $data])
|
|
->log('election_settings_created');
|
|
|
|
return $settings;
|
|
}
|
|
|
|
public function update(Election $election, array $data, User $actingUser): void
|
|
{
|
|
/** @var ElectionSetting $settings */
|
|
$settings = $election->settings;
|
|
|
|
$before = $settings->only([
|
|
'registration_start_date',
|
|
'registration_end_date',
|
|
'polling_date',
|
|
'is_attendance_active',
|
|
'is_registration_open_override',
|
|
]);
|
|
|
|
$settings->update([
|
|
'registration_start_date' => $data['registration_start_date'],
|
|
'registration_end_date' => $data['registration_end_date'],
|
|
'polling_date' => $data['polling_date'],
|
|
'is_attendance_active' => $data['is_attendance_active'],
|
|
'is_registration_open_override' => $data['is_registration_open_override'],
|
|
]);
|
|
|
|
activity('admin_settings')
|
|
->performedOn($settings)
|
|
->causedBy($actingUser)
|
|
->withProperties([
|
|
'election_id' => $election->id,
|
|
'before' => $before,
|
|
'after' => $settings->only([
|
|
'registration_start_date',
|
|
'registration_end_date',
|
|
'polling_date',
|
|
'is_attendance_active',
|
|
'is_registration_open_override',
|
|
]),
|
|
])
|
|
->log('election_settings_updated');
|
|
}
|
|
}
|