File manager - Edit - /var/www/html/homologBancodetalentos/app/Support/TalentBank/CurriculumPresenter.php
Back
<?php namespace App\Support\TalentBank; use App\Http\Services\TalentBank\CandidateService; use App\Models\TalentBank\Candidate; use App\Models\TalentBank\LanguageProficiency; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response; class CurriculumPresenter { private static array $levelPct = [ 'Basico' => 25, 'Intermediario' => 50, 'Avancado' => 75, 'Fluente' => 90, 'Nativo' => 100, ]; public static function build(Candidate $candidate): array { $candidate->loadMissing([ 'gender', 'maritalStatus', 'ethnicity', 'occupation', 'neighbourhood', 'experiences.occupation', 'educations.educationLevel', 'educations.academicDiscipline', 'courses', 'skills', 'languages', 'wantedOccupations', ]); $canPhoto = Schema::hasColumn('candidates', 'photo_path'); $usuario = (object) [ 'foto' => $canPhoto ? CandidateService::photoPublicUrl($candidate->photo_path) : null, 'nome' => $candidate->name, 'cargo' => optional($candidate->occupation)->name, 'perfil' => $candidate->cv_summary, 'data_nascimento' => $candidate->birth_date ? $candidate->birth_date->format('d/m/Y') : '', 'sexo' => optional($candidate->gender)->name, 'telefone' => $candidate->cellphone ?: $candidate->telephone, 'estado_civil' => optional($candidate->maritalStatus)->name, 'outro_campo' => optional($candidate->ethnicity)->name, 'status' => $candidate->special_needs ? 'PCD' : '', ]; $experiencias = $candidate->experiences->map(fn ($exp) => (object) [ 'id' => $exp->id, 'inicio' => $exp->date_start ? $exp->date_start->format('d/m/Y') : '', 'fim' => $exp->is_current ? 'Atual' : ($exp->date_end ? $exp->date_end->format('d/m/Y') : ''), 'date_start_raw' => $exp->date_start ? $exp->date_start->format('Y-m-d') : '', 'date_end_raw' => $exp->date_end ? $exp->date_end->format('Y-m-d') : '', 'is_current' => $exp->is_current, 'cargo' => optional($exp->occupation)->name ?? '', 'occupation_id' => $exp->occupation_id, 'empresa' => $exp->company ?? '', 'descricao' => $exp->description ?? '', 'business_line_id' => $exp->business_line_id, ]); $formacoes = $candidate->educations->map(fn ($edu) => (object) [ 'id' => $edu->id, 'inicio' => $edu->date_start ? $edu->date_start->format('d/m/Y') : '', 'fim' => $edu->date_end ? $edu->date_end->format('d/m/Y') : '', 'date_start_raw' => $edu->date_start ? $edu->date_start->format('Y-m-d') : '', 'date_end_raw' => $edu->date_end ? $edu->date_end->format('Y-m-d') : '', 'nivel' => optional($edu->educationLevel)->name ?? '', 'disciplina' => optional($edu->academicDiscipline)->name ?? '', 'education_level_id' => $edu->education_level_id, 'academic_discipline_id' => $edu->academic_discipline_id, 'instituicao' => $edu->institution ?? '', 'certificado' => $edu->specialization ?? '', ]); $conhecimentos = $candidate->courses->map(fn ($course) => (object) [ 'id' => $course->id, 'inicio' => $course->date_start ? $course->date_start->format('d/m/Y') : '', 'fim' => $course->date_end ? $course->date_end->format('d/m/Y') : '', 'date_start_raw' => $course->date_start ? $course->date_start->format('Y-m-d') : '', 'date_end_raw' => $course->date_end ? $course->date_end->format('Y-m-d') : '', 'titulo' => $course->name ?? '', 'instituicao' => $course->institution ?? '', 'carga' => $course->duration ?? '', ]); $idiomas = $candidate->languages->map(function ($lang) { $nivel = $lang->pivot->language_proficiency_id ? optional(LanguageProficiency::find($lang->pivot->language_proficiency_id))->name ?? '' : ''; return (object) [ 'id' => $lang->id, 'nome' => $lang->name ?? '', 'nivel' => $nivel, 'porcentagem' => self::$levelPct[self::normalizeText($nivel)] ?? 0, ]; }); $habilidades = $candidate->skills->map(fn ($skill) => (object) [ 'id' => $skill->id, 'descricao' => $skill->name ?? '', ]); $areasInteresse = $candidate->wantedOccupations->map(fn ($occ) => (object) [ 'id' => $occ->id, 'nome' => $occ->name, ]); return compact('usuario', 'experiencias', 'formacoes', 'conhecimentos', 'idiomas', 'habilidades', 'candidate', 'areasInteresse'); } public static function photoDataUri(Candidate $candidate): ?string { return CandidateService::photoDataUri($candidate); } public static function downloadResponse(Candidate $candidate): Response { $payload = self::build($candidate); $photoDataUri = self::photoDataUri($candidate); $slug = Str::slug(Str::limit($candidate->name ?? 'curriculo', 80, '')); $filename = 'curriculo-'.($slug !== '' ? $slug : 'candidato').'.pdf'; $pdf = Pdf::loadView('pdf.curriculum', array_merge($payload, compact('photoDataUri'))) ->setPaper('a4', 'portrait'); return $pdf->download($filename); } public static function streamResponse(Candidate $candidate): Response { $payload = self::build($candidate); $photoDataUri = self::photoDataUri($candidate); $slug = Str::slug(Str::limit($candidate->name ?? 'curriculo', 80, '')); $filename = 'curriculo-'.($slug !== '' ? $slug : 'candidato').'.pdf'; $pdf = Pdf::loadView('pdf.curriculum', array_merge($payload, compact('photoDataUri'))) ->setPaper('a4', 'portrait'); return $pdf->stream($filename); } private static function normalizeText(string $text): string { return preg_replace('/[^a-zA-Z]/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $text) ?: $text); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings