File manager - Edit - /var/www/html/homologBancodetalentos/app/Support/TalentBank/CandidateQuery.php
Back
<?php namespace App\Support\TalentBank; use App\Models\TalentBank\Candidate; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; /** * Mirrors legacy Candidate FilterQueryString filters for report/listing. */ class CandidateQuery { public static function apply(Request $request): Builder { $query = Candidate::query(); if ($request->filled('like')) { $raw = $request->input('like'); $parts = explode(',', $raw, 2); if (count($parts) === 2) { $query->where($parts[0], 'like', '%'.$parts[1].'%'); } } $simple = [ 'id', 'cpf', 'name', 'email', 'address', 'zip_code', 'special_needs', 'telephone', 'cellphone', 'min_payment', 'desired_payment', 'cv_summary', 'has_experience', 'active', 'neighbourhood_id', 'gender_id', 'marital_status_id', 'occupation_id', 'ethnicity_id', ]; foreach ($simple as $field) { if ($request->filled($field)) { $query->where($field, $request->input($field)); } } if ($request->filled('ethnicity')) { $query->whereHas('ethnicity', function ($q) use ($request) { $q->where('name', $request->input('ethnicity')); }); } if ($request->filled('education_level')) { $query->whereHas('educations', function ($q) use ($request) { $q->where('education_level_id', $request->input('education_level')); }); } if ($request->filled('age')) { $query->whereRaw('TIMESTAMPDIFF(YEAR, birth_date, CURDATE()) = ?', [$request->input('age')]); } if ($request->filled('age_between')) { $exploded = explode(',', $request->input('age_between')); if (count($exploded) === 2) { $query->whereRaw('TIMESTAMPDIFF(YEAR, birth_date, CURDATE()) BETWEEN ? AND ?', [$exploded[0], $exploded[1]]); } } if ($request->filled('neighbourhoods')) { $ids = explode(',', $request->input('neighbourhoods')); $query->whereIn('neighbourhood_id', $ids); } if ($request->filled('occupations')) { $ids = explode(',', $request->input('occupations')); $query->whereIn('occupation_id', $ids); } $inValues = $request->input('in', []); if (! is_array($inValues)) { $inValues = $inValues ? [$inValues] : []; } foreach ($inValues as $in) { if (! is_string($in) || $in === '') { continue; } $ids = explode(',', $in); $field = array_shift($ids); if ($field && count($ids)) { $query->whereIn($field, $ids); } } if ($request->filled('sort')) { $sortParts = explode(',', $request->input('sort')); $column = $sortParts[0]; $direction = $sortParts[1] ?? 'asc'; $query->orderBy($column, $direction === 'desc' ? 'desc' : 'asc'); } return $query; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings