File manager - Edit - /var/www/html/homologBancodetalentos/app/Http/Services/TalentBank/AngraSsoProvisioningService.php
Back
<?php namespace App\Http\Services\TalentBank; use App\Models\TalentBank\Candidate; use App\Models\TalentBank\Company; use Illuminate\Support\Str; /** * Cria ou atualiza candidato/empresa no BT a partir do perfil autenticado no Conta Angra (SSO). * Evita duplicidade por CPF/CNPJ e mantém nome/e-mail alinhados ao portal. * * Retorno de sync*(): true = registro era novo no BT, false = já existia (migrado ou acesso anterior). */ class AngraSsoProvisioningService { public function syncCandidate(string $cpfDigits, string $name, string $email, ?string $phoneDigits = null): bool { $name = trim($name) !== '' ? trim($name) : 'Candidato'; $email = trim(mb_strtolower($email)); $payload = [ 'name' => Str::limit($name, 255, ''), 'email' => Str::limit($email, 255, ''), 'active' => true, ]; $digits = $phoneDigits !== null && $phoneDigits !== '' ? preg_replace('/\D/', '', $phoneDigits) : null; if ($digits !== null && $digits !== '') { $payload['cellphone'] = Str::limit($digits, 30, ''); } $candidate = Candidate::query()->firstOrNew(['cpf' => $cpfDigits]); $isNew = ! $candidate->exists; if ($isNew) { // Candidato novo criado pelo SSO: profile_completed_at fica null → passará pelo fluxo de conclusão. $payload['special_needs'] = false; } $candidate->fill($payload); $candidate->save(); return $isNew; } public function syncCompany(string $cnpjDigits, string $name, string $email): bool { $name = trim($name) !== '' ? trim($name) : 'Empresa'; $email = trim(mb_strtolower($email)); $company = Company::query()->firstOrNew(['cnpj' => $cnpjDigits]); $isNew = ! $company->exists; $company->fill([ 'trading_name' => Str::limit($name, 255, ''), 'email' => Str::limit($email, 255, ''), 'active' => true, ]); $company->save(); return $isNew; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings