From dc4cd12a30faa2a2a4221f99508ee7afaeb4c1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Sun, 1 Dec 2024 21:42:26 +0200 Subject: [PATCH] fixes --- app/Services/RecordService.php | 10 +++++++--- config/import.php | 2 +- .../views/livewire/pages/election-results.blade.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Services/RecordService.php b/app/Services/RecordService.php index 1d004cb..72d0c18 100644 --- a/app/Services/RecordService.php +++ b/app/Services/RecordService.php @@ -63,12 +63,16 @@ public static function getPart(string $code): Part public static function isIndependentCandidate(string $name): bool { - return Str::startsWith($name, config('import.independent_candidate_prefix')); + return Str::contains($name, config('import.independent_candidate_designation'), ignoreCase: true); } public static function getName(string $name): string { - return Str::afterLast($name, config('import.independent_candidate_prefix')); + return Str::of($name) + ->remove(config('import.independent_candidate_designation'), caseSensitive: false) + ->trim('-') + ->trim() + ->value(); } public static function generateVotables(array $header, int $electionId): Collection @@ -86,7 +90,7 @@ public static function generateVotables(array $header, int $electionId): Collect ->where('election_id', $electionId) ->firstOr( fn () => Candidate::query() - ->where('name', $name) + ->where('name', static::getName($name)) ->where('election_id', $electionId) ->first() ); diff --git a/config/import.php b/config/import.php index 296fddb..1429cde 100644 --- a/config/import.php +++ b/config/import.php @@ -8,7 +8,7 @@ 'disk' => env('IMPORT_DISK', env('FILESYSTEM_DISK', 'local')), - 'independent_candidate_prefix' => env('IMPORT_INDEPENDENT_CANDIDATE_PREFIX', 'CANDIDAT INDEPENDENT - '), + 'independent_candidate_designation' => env('IMPORT_INDEPENDENT_CANDIDATE_DESIGNATION', 'CANDIDAT INDEPENDENT'), 'candidate_votes_suffix' => env('IMPORT_CANDIDATE_VOTES_SUFFIX', '-voturi'), ]; diff --git a/resources/views/livewire/pages/election-results.blade.php b/resources/views/livewire/pages/election-results.blade.php index 73c7fbd..916126b 100644 --- a/resources/views/livewire/pages/election-results.blade.php +++ b/resources/views/livewire/pages/election-results.blade.php @@ -10,7 +10,7 @@