first
This commit is contained in:
23
app/Http/Requests/Admin/Setup/AssignPpmRequest.php
Normal file
23
app/Http/Requests/Admin/Setup/AssignPpmRequest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AssignPpmRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => ['required', 'exists:users,id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Http/Requests/Admin/Setup/ImportPusatRequest.php
Normal file
39
app/Http/Requests/Admin/Setup/ImportPusatRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ImportPusatRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'election_id' => ['required', 'integer', 'exists:elections,id'],
|
||||
'dun_code' => ['required', 'string', 'max:20'],
|
||||
'dun_name' => ['required', 'string', 'max:255'],
|
||||
'file' => ['required', 'file', 'mimes:xlsx', 'max:10240'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'election_id' => 'pilihan raya',
|
||||
'dun_code' => 'kod DUN',
|
||||
'dun_name' => 'nama DUN',
|
||||
'file' => 'fail XLSX',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\BahagianPilihanraya;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertBahagianPilihanrayaRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$bahagian = $this->route('bahagianPilihanraya');
|
||||
|
||||
return [
|
||||
'election_id' => ['required', 'exists:elections,id'],
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('bahagian_pilihanrayas', 'code')
|
||||
->where('election_id', $this->input('election_id'))
|
||||
->ignore($bahagian instanceof BahagianPilihanraya ? $bahagian->id : null),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\DaerahMengundi;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertDaerahMengundiRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$daerah = $this->route('daerahMengundi');
|
||||
|
||||
return [
|
||||
'election_id' => ['required', 'exists:elections,id'],
|
||||
'bahagian_pilihanraya_id' => ['required', 'exists:bahagian_pilihanrayas,id'],
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('daerah_mengundis', 'code')
|
||||
->where('election_id', $this->input('election_id'))
|
||||
->ignore($daerah instanceof DaerahMengundi ? $daerah->id : null),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpsertElectionSettingsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'registration_start_date' => ['required', 'date'],
|
||||
'registration_end_date' => ['required', 'date', 'after_or_equal:registration_start_date'],
|
||||
'polling_date' => ['required', 'date', 'after_or_equal:registration_end_date'],
|
||||
'is_attendance_active' => ['required', 'boolean'],
|
||||
'is_registration_open_override' => ['nullable', 'in:,0,1'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'is_attendance_active' => $this->boolean('is_attendance_active'),
|
||||
'is_registration_open_override' => $this->resolveOverride(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function resolveOverride(): ?bool
|
||||
{
|
||||
$value = $this->input('is_registration_open_override');
|
||||
|
||||
if ($value === '' || $value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
}
|
||||
24
app/Http/Requests/Admin/Setup/UpsertPositionQuotaRequest.php
Normal file
24
app/Http/Requests/Admin/Setup/UpsertPositionQuotaRequest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpsertPositionQuotaRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'position_id' => ['required', 'exists:positions,id'],
|
||||
'quota' => ['required', 'integer', 'min:0', 'max:9999'],
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Requests/Admin/Setup/UpsertPositionRequest.php
Normal file
38
app/Http/Requests/Admin/Setup/UpsertPositionRequest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\Position;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertPositionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$position = $this->route('position');
|
||||
|
||||
return [
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('positions', 'code')->ignore($position instanceof Position ? $position->id : null),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'scope' => ['required', Rule::in(['pusat', 'saluran', 'external'])],
|
||||
'is_public_applyable' => ['nullable', 'boolean'],
|
||||
'is_assignable' => ['nullable', 'boolean'],
|
||||
'allows_dual_role' => ['nullable', 'boolean'],
|
||||
'sort_order' => ['nullable', 'integer', 'min:0', 'max:999'],
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/Admin/Setup/UpsertPusatMengundiRequest.php
Normal file
50
app/Http/Requests/Admin/Setup/UpsertPusatMengundiRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\PusatMengundi;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertPusatMengundiRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$pusatMengundi = $this->route('pusatMengundi');
|
||||
$pusatId = $pusatMengundi instanceof PusatMengundi ? $pusatMengundi->id : null;
|
||||
$operationalQuantity = $this->isMethod('post') ? ['required', 'integer'] : ['sometimes', 'integer'];
|
||||
|
||||
return [
|
||||
'election_id' => ['required', 'integer', 'exists:elections,id'],
|
||||
'dun_id' => ['nullable', 'integer', 'exists:duns,id'],
|
||||
'code' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:50',
|
||||
Rule::unique('pusat_mengundis', 'code')
|
||||
->where(fn ($query) => $query->where('election_id', $this->input('election_id')))
|
||||
->ignore($pusatId),
|
||||
],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'address' => ['nullable', 'string', 'max:2000'],
|
||||
'saluran_count' => [...$operationalQuantity, 'min:1', 'max:100'],
|
||||
'ktm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'polis_iring_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'ppm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kpdp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'papm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'jkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'kkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
'calon_tambahan_count' => [...$operationalQuantity, 'min:0', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Setup;
|
||||
|
||||
use App\Models\PusatMengundi;
|
||||
use App\Models\SaluranMengundi;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpsertSaluranMengundiRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasRole('Admin') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$pusatMengundi = $this->route('pusatMengundi');
|
||||
$pusatId = $pusatMengundi instanceof PusatMengundi ? $pusatMengundi->id : null;
|
||||
|
||||
$saluranMengundi = $this->route('saluranMengundi');
|
||||
$saluranId = $saluranMengundi instanceof SaluranMengundi ? $saluranMengundi->id : null;
|
||||
|
||||
return [
|
||||
'number' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:20',
|
||||
Rule::unique('saluran_mengundis', 'number')
|
||||
->where(fn ($query) => $query->where('pusat_mengundi_id', $pusatId))
|
||||
->ignore($saluranId),
|
||||
],
|
||||
'voter_count' => ['nullable', 'integer', 'min:0'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user