diff --git a/app/Http/Controllers/Api/EmployerWorkerController.php b/app/Http/Controllers/Api/EmployerWorkerController.php index e0dabfd..fbaa6a0 100644 --- a/app/Http/Controllers/Api/EmployerWorkerController.php +++ b/app/Http/Controllers/Api/EmployerWorkerController.php @@ -28,7 +28,7 @@ private function formatWorker(Worker $w) // Preferred job types: full-time / part-time / live-in / live-out $jobTypes = ['full-time', 'part-time', 'live-in', 'live-out']; - $preferredJobType = $jobTypes[$w->id % 4]; + $preferredJobType = $w->preferred_job_type ?? $jobTypes[$w->id % 4]; // Emirates ID verification status (dynamic passport status) $emiratesIdStatus = $w->emirates_id_status; @@ -73,6 +73,9 @@ private function formatWorker(Worker $w) 'bio' => $w->bio, 'rating' => $rating, 'reviews_count' => $reviewsCount, + 'preferred_location' => $w->preferred_location, + 'live_in_out' => $w->live_in_out, + 'in_country' => (bool)$w->in_country, ]; } @@ -109,11 +112,21 @@ public function getWorkers(Request $request) $workersArray = $formattedWorkers->toArray(); - // Apply filters: skills, language/languages, nationality + // Apply filters: skills, language/languages, nationality, preferred_location, job_type, live_in_out, in_country, visa_status if ($request->filled('nationality')) { - $nationality = strtolower($request->nationality); - $workersArray = array_values(array_filter($workersArray, function ($c) use ($nationality) { - return isset($c['nationality']) && strtolower($c['nationality']) === $nationality; + $natInput = $request->nationality; + $natsArray = is_array($natInput) ? $natInput : array_filter(array_map('trim', explode(',', $natInput))); + $natsArray = array_map('strtolower', $natsArray); + + $workersArray = array_values(array_filter($workersArray, function ($c) use ($natsArray) { + if (!isset($c['nationality'])) return false; + $wNat = strtolower($c['nationality']); + foreach ($natsArray as $n) { + if (str_contains($wNat, $n) || $wNat === $n) { + return true; + } + } + return false; })); } @@ -149,6 +162,125 @@ public function getWorkers(Request $request) })); } + // Filter: preferred_location + if ($request->filled('preferred_location')) { + $prefLoc = $request->preferred_location; + $locsArray = is_array($prefLoc) ? $prefLoc : array_filter(array_map('trim', explode(',', $prefLoc))); + $locsArray = array_map('strtolower', $locsArray); + + $workersArray = array_values(array_filter($workersArray, function ($c) use ($locsArray) { + if (!isset($c['preferred_location'])) return false; + $wLoc = strtolower($c['preferred_location']); + foreach ($locsArray as $l) { + if (str_contains($wLoc, $l)) { + return true; + } + } + return false; + })); + } + + // Filter: job_type / preferred_job_type + $jobTypeParam = $request->input('job_type') ?? $request->input('preferred_job_type'); + if ($jobTypeParam) { + $jobTypesArray = is_array($jobTypeParam) ? $jobTypeParam : array_filter(array_map('trim', explode(',', $jobTypeParam))); + $jobTypesArray = array_map('strtolower', $jobTypesArray); + + $workersArray = array_values(array_filter($workersArray, function ($c) use ($jobTypesArray) { + if (!isset($c['preferred_job_type'])) return false; + $wJobType = strtolower($c['preferred_job_type']); + foreach ($jobTypesArray as $jt) { + if (str_contains($wJobType, $jt)) { + return true; + } + } + return false; + })); + } + + // Filter: accommodation_type / accomadation_type / live_in_out + $accParam = $request->input('live_in_out') ?? $request->input('accommodation_type') ?? $request->input('accomadation_type'); + if ($accParam) { + $accsArray = is_array($accParam) ? $accParam : array_filter(array_map('trim', explode(',', $accParam))); + $accsArray = array_map(function($val) { + return str_replace(['_', '-'], ' ', strtolower($val)); + }, $accsArray); + + $workersArray = array_values(array_filter($workersArray, function ($c) use ($accsArray) { + if (!isset($c['live_in_out'])) return false; + $wAcc = str_replace(['_', '-'], ' ', strtolower($c['live_in_out'])); + foreach ($accsArray as $a) { + if (str_contains($wAcc, $a)) { + return true; + } + } + return false; + })); + } + + // Filter: in country / out country (in_country / out_country) + if ($request->has('in_country')) { + $inCountryVal = $request->input('in_country'); + if ($inCountryVal !== null && $inCountryVal !== '') { + $isInCountry = filter_var($inCountryVal, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if ($isInCountry === null) { + $strVal = strtolower(trim($inCountryVal)); + if ($strVal === 'in' || $strVal === 'in_country' || $strVal === 'yes') { + $isInCountry = true; + } elseif ($strVal === 'out' || $strVal === 'out_country' || $strVal === 'no') { + $isInCountry = false; + } + } + if ($isInCountry !== null) { + $workersArray = array_values(array_filter($workersArray, function ($c) use ($isInCountry) { + return isset($c['in_country']) && (bool)$c['in_country'] === $isInCountry; + })); + } + } + } + + if ($request->has('out_country')) { + $outCountryVal = $request->input('out_country'); + if ($outCountryVal !== null && $outCountryVal !== '') { + $isOutCountry = filter_var($outCountryVal, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if ($isOutCountry === null) { + $strVal = strtolower(trim($outCountryVal)); + if ($strVal === 'out' || $strVal === 'out_country' || $strVal === 'yes') { + $isOutCountry = true; + } elseif ($strVal === 'in' || $strVal === 'in_country' || $strVal === 'no') { + $isOutCountry = false; + } + } + if ($isOutCountry !== null) { + $workersArray = array_values(array_filter($workersArray, function ($c) use ($isOutCountry) { + return isset($c['in_country']) && (bool)$c['in_country'] !== $isOutCountry; + })); + } + } + } + + // Filter: visa_status / next_visa_type / visa_type (applicable when in country) + $visaParam = $request->input('visa_status') ?? $request->input('next_visa_type') ?? $request->input('visa_type'); + if ($visaParam) { + $visasArray = is_array($visaParam) ? $visaParam : array_filter(array_map('trim', explode(',', $visaParam))); + $visasArray = array_map('strtolower', $visasArray); + + $workersArray = array_values(array_filter($workersArray, function ($c) use ($visasArray) { + if (!isset($c['visa_status'])) return false; + $isInCountry = isset($c['in_country']) && (bool)$c['in_country']; + if (!$isInCountry) { + return false; + } + $wVisa = strtolower($c['visa_status']); + foreach ($visasArray as $v) { + if (str_contains($wVisa, $v)) { + return true; + } + } + return false; + })); + } + return response()->json([ 'success' => true, 'data' => [ @@ -222,6 +354,8 @@ public function getCandidates(Request $request) $skillsList[$w->id % 6], $skillsList[($w->id + 2) % 6] ]; + $jobTypes = ['full-time', 'part-time', 'live-in', 'live-out']; + $preferredJobType = $w->preferred_job_type ?? $jobTypes[$w->id % 4]; return [ 'id' => $app->id, @@ -234,6 +368,11 @@ public function getCandidates(Request $request) 'skills' => $mappedSkills, 'languages' => $langs, 'availability' => $w->availability ?? 'Immediate', + 'preferred_location' => $w->preferred_location, + 'preferred_job_type' => $preferredJobType, + 'live_in_out' => $w->live_in_out, + 'in_country' => (bool)$w->in_country, + 'visa_status' => $w->visa_status, ]; })->filter()->values()->toArray(); @@ -255,6 +394,8 @@ public function getCandidates(Request $request) $skillsList[$w->id % 6], $skillsList[($w->id + 2) % 6] ]; + $jobTypes = ['full-time', 'part-time', 'live-in', 'live-out']; + $preferredJobType = $w->preferred_job_type ?? $jobTypes[$w->id % 4]; return [ 'id' => 'offer_' . $offer->id, @@ -267,6 +408,11 @@ public function getCandidates(Request $request) 'skills' => $mappedSkills, 'languages' => $langs, 'availability' => $w->availability ?? 'Immediate', + 'preferred_location' => $w->preferred_location, + 'preferred_job_type' => $preferredJobType, + 'live_in_out' => $w->live_in_out, + 'in_country' => (bool)$w->in_country, + 'visa_status' => $w->visa_status, ]; })->filter()->values()->toArray(); @@ -278,11 +424,21 @@ public function getCandidates(Request $request) return $c && $c['status'] === 'Hired'; })); - // Apply filters: skills, languages, nationality, availability + // Apply filters: skills, languages, nationality, availability, preferred_location, job_type, live_in_out, in_country, visa_status if ($request->filled('nationality')) { - $nationality = strtolower($request->nationality); - $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($nationality) { - return isset($c['nationality']) && strtolower($c['nationality']) === $nationality; + $natInput = $request->nationality; + $natsArray = is_array($natInput) ? $natInput : array_filter(array_map('trim', explode(',', $natInput))); + $natsArray = array_map('strtolower', $natsArray); + + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($natsArray) { + if (!isset($c['nationality'])) return false; + $wNat = strtolower($c['nationality']); + foreach ($natsArray as $n) { + if (str_contains($wNat, $n) || $wNat === $n) { + return true; + } + } + return false; })); } @@ -325,6 +481,125 @@ public function getCandidates(Request $request) })); } + // Filter: preferred_location + if ($request->filled('preferred_location')) { + $prefLoc = $request->preferred_location; + $locsArray = is_array($prefLoc) ? $prefLoc : array_filter(array_map('trim', explode(',', $prefLoc))); + $locsArray = array_map('strtolower', $locsArray); + + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($locsArray) { + if (!isset($c['preferred_location'])) return false; + $wLoc = strtolower($c['preferred_location']); + foreach ($locsArray as $l) { + if (str_contains($wLoc, $l)) { + return true; + } + } + return false; + })); + } + + // Filter: job_type / preferred_job_type + $jobTypeParam = $request->input('job_type') ?? $request->input('preferred_job_type'); + if ($jobTypeParam) { + $jobTypesArray = is_array($jobTypeParam) ? $jobTypeParam : array_filter(array_map('trim', explode(',', $jobTypeParam))); + $jobTypesArray = array_map('strtolower', $jobTypesArray); + + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($jobTypesArray) { + if (!isset($c['preferred_job_type'])) return false; + $wJobType = strtolower($c['preferred_job_type']); + foreach ($jobTypesArray as $jt) { + if (str_contains($wJobType, $jt)) { + return true; + } + } + return false; + })); + } + + // Filter: accommodation_type / accomadation_type / live_in_out + $accParam = $request->input('live_in_out') ?? $request->input('accommodation_type') ?? $request->input('accomadation_type'); + if ($accParam) { + $accsArray = is_array($accParam) ? $accParam : array_filter(array_map('trim', explode(',', $accParam))); + $accsArray = array_map(function($val) { + return str_replace(['_', '-'], ' ', strtolower($val)); + }, $accsArray); + + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($accsArray) { + if (!isset($c['live_in_out'])) return false; + $wAcc = str_replace(['_', '-'], ' ', strtolower($c['live_in_out'])); + foreach ($accsArray as $a) { + if (str_contains($wAcc, $a)) { + return true; + } + } + return false; + })); + } + + // Filter: in country / out country (in_country / out_country) + if ($request->has('in_country')) { + $inCountryVal = $request->input('in_country'); + if ($inCountryVal !== null && $inCountryVal !== '') { + $isInCountry = filter_var($inCountryVal, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if ($isInCountry === null) { + $strVal = strtolower(trim($inCountryVal)); + if ($strVal === 'in' || $strVal === 'in_country' || $strVal === 'yes') { + $isInCountry = true; + } elseif ($strVal === 'out' || $strVal === 'out_country' || $strVal === 'no') { + $isInCountry = false; + } + } + if ($isInCountry !== null) { + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($isInCountry) { + return isset($c['in_country']) && (bool)$c['in_country'] === $isInCountry; + })); + } + } + } + + if ($request->has('out_country')) { + $outCountryVal = $request->input('out_country'); + if ($outCountryVal !== null && $outCountryVal !== '') { + $isOutCountry = filter_var($outCountryVal, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + if ($isOutCountry === null) { + $strVal = strtolower(trim($outCountryVal)); + if ($strVal === 'out' || $strVal === 'out_country' || $strVal === 'yes') { + $isOutCountry = true; + } elseif ($strVal === 'in' || $strVal === 'in_country' || $strVal === 'no') { + $isOutCountry = false; + } + } + if ($isOutCountry !== null) { + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($isOutCountry) { + return isset($c['in_country']) && (bool)$c['in_country'] !== $isOutCountry; + })); + } + } + } + + // Filter: visa_status / next_visa_type / visa_type (applicable when in country) + $visaParam = $request->input('visa_status') ?? $request->input('next_visa_type') ?? $request->input('visa_type'); + if ($visaParam) { + $visasArray = is_array($visaParam) ? $visaParam : array_filter(array_map('trim', explode(',', $visaParam))); + $visasArray = array_map('strtolower', $visasArray); + + $mergedCandidates = array_values(array_filter($mergedCandidates, function ($c) use ($visasArray) { + if (!isset($c['visa_status'])) return false; + $isInCountry = isset($c['in_country']) && (bool)$c['in_country']; + if (!$isInCountry) { + return false; + } + $wVisa = strtolower($c['visa_status']); + foreach ($visasArray as $v) { + if (str_contains($wVisa, $v)) { + return true; + } + } + return false; + })); + } + $page = (int)$request->input('page', 1); $perPage = (int)$request->input('per_page', 15); $total = count($mergedCandidates);