File manager - Edit - /var/www/html/portalHomolog/app/Support/StructureSidebar.php
Back
<?php namespace App\Support; use App\Models\Html; use App\Models\Link; use App\Models\Phone; use App\Models\Structure; use Illuminate\Support\Collection; /** * Carrega dados do menu lateral padrão do órgão (links, serviços, telefones) * para páginas estáticas e componentes do portal público. */ class StructureSidebar { /** * @return array{ * secretaria: Structure|null, * links: Collection, * htmls: Collection, * telefones: array<int, array{telefone: string, numeros: array<int, array{numero: string, link: string}>}> * } */ public static function forStructure(?string $structureId): array { $empty = [ 'secretaria' => null, 'links' => collect(), 'htmls' => collect(), 'telefones' => [], ]; if (empty($structureId)) { return $empty; } $secretaria = Structure::query() ->where('id', $structureId) ->where('status', 'ATIVADO') ->first(); if (! $secretaria) { return $empty; } $links = Link::query() ->where('structure_id', $secretaria->id) ->orderBy('order', 'asc') ->get(); $htmls = Html::query() ->where('structure_id', $secretaria->id) ->where('visibility', 'ATIVADO') ->orderBy('created_at', 'asc') ->get(); $telefonesRaw = Phone::query() ->where('structure_id', $secretaria->id) ->orderBy('created_at', 'asc') ->get(); return [ 'secretaria' => $secretaria, 'links' => $links, 'htmls' => $htmls, 'telefones' => self::formatTelefones($telefonesRaw), ]; } /** * @param Collection<int, Phone> $telefonesRaw * @return array<int, array{telefone: string, numeros: array<int, array{numero: string, link: string}>}> */ private static function formatTelefones(Collection $telefonesRaw): array { $telefones = []; foreach ($telefonesRaw as $telefone) { $tels = array_map('trim', explode(',', $telefone->description ?? '')); $numeros = []; foreach ($tels as $tel) { if ($tel === '') { continue; } $numeros[] = [ 'numero' => $tel, 'link' => '+55' . str_replace(['+55', '-', ' ', ')', '('], '', $tel), ]; } $telefones[] = [ 'telefone' => $telefone->titulo, 'numeros' => $numeros, ]; } return $telefones; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings