File manager - Edit - /var/www/html/portal/app/Models/LicitacoesProcedimentos/Processo.php
Back
<?php namespace App\Models\LicitacoesProcedimentos; use App\Models\Structure; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; class Processo extends Model { use HasFactory; protected $table = 'licitacoes_procedimentos'; public const TIPOS_PROCESSO = ['licitacao', 'procedimento']; public const SETORES = [ 45 => 'Saúde', 46 => 'Desenvolvimento Regional', 47 => 'Desenvolvimento Social e Promoção da Cidadania', 52 => 'Instituto Municipal do Ambiente', 75 => 'Urbanização, Parques e Jardins', 20 => 'Prefeitura de Angra dos Reis', 61 => 'TurisAngra', 1 => 'SAAE', 59 => 'Hospital Municipal da Japuíba', 5 => 'AngraPrev', 50 => 'Obras Públicas e Habitação', 44 => 'Educação, Juventude e Inovação', 4 => 'Cultura', 6 => 'Proteção e Defesa Civil', 55 => 'Esportes', ]; public const SETORES_ALIAS = [ 3 => 45, 54 => 47, ]; public const TIPOS_LICITACAO = [ 1 => 'Pregão Eletrônico', 2 => 'Pregão Presencial', 3 => 'Concorrência Eletrônica', 4 => 'Concorrência Presencial', 5 => 'Concurso', 6 => 'Leilão', 7 => 'Diálogo Competitivo', ]; public const TIPOS_PROCEDIMENTO = [ 1 => 'Credenciamento', 2 => 'Pré Qualificação', 3 => 'Chamamento Público', 4 => 'Registro Cadastral', 5 => 'Inexigibilidade', 6 => 'Dispensa', 7 => 'Dispensa Eletrônica', 8 => 'Aviso', ]; public const STATUS_LICITACAO = [ 0 => 'Indefinido', 1 => 'Em Andamento', 2 => 'Cancelado', 3 => 'Suspenso', 4 => 'Aguardando', 5 => 'Não Homologado', 6 => 'Homologado', 7 => 'Fracassado', ]; public const STATUS_PROCEDIMENTO = [ 0 => 'Indefinido', 1 => 'Em Andamento', 2 => 'Cancelado', 3 => 'Suspenso', 4 => 'Aguardando', 5 => 'Não Homologado', 6 => 'Homologado', 7 => 'Fracassado', ]; protected $fillable = [ 'tipo_processo', 'id_setor', 'ds_objeto', 'nr_processo', 'nr_memorando', 'cd_tipo', 'nr_licitacao', 'dt_data', 'dt_encerramento', 'dt_homologacao', 'dt_hora', 'ds_favorecido', 'ds_bo', 'ds_urlbo', 'boletins', 'cd_status', 'id_usuario', ]; protected $casts = [ 'dt_data' => 'datetime', 'dt_encerramento' => 'datetime', 'dt_homologacao' => 'date', 'boletins' => 'array', ]; public function uploads(): HasMany { return $this->hasMany(ProcessoUpload::class, 'licitacao_procedimento_id', 'id'); } public static function isStructureSetorId(int|string|null $id): bool { if ($id === null || $id === '') { return false; } return (bool) preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', (string) $id ); } /** * @return array<int, string> */ public static function getStructureSetorTypes(): array { return ['SECRETARIA', 'SECRETARIA_EXECUTIVA', 'AUTARQUIA', 'FUNDACAO']; } public static function getSetorNomeById(int|string|null $id): ?string { if ($id === null || $id === '') { return null; } if (self::isStructureSetorId($id)) { return Structure::query() ->where('id', (string) $id) ->whereIn('type', self::getStructureSetorTypes()) ->value('name'); } $canonicalId = self::getCanonicalSetorId((int) $id); return self::SETORES[$canonicalId] ?? null; } public static function getCanonicalSetorId(int|string|null $id): ?int { if ($id === null || $id === '') { return null; } $setorId = (int) $id; if (array_key_exists($setorId, self::SETORES)) { return $setorId; } return self::SETORES_ALIAS[$setorId] ?? null; } public static function getSetorIdsForFilter(int|string|null $id): array { if ($id === null || $id === '') { return []; } if (self::isStructureSetorId($id)) { return [(string) $id]; } $canonicalId = self::getCanonicalSetorId($id); if ($canonicalId === null) { return []; } $ids = [(string) $canonicalId]; foreach (self::SETORES_ALIAS as $aliasId => $canonical) { if ($canonical === $canonicalId) { $ids[] = (string) $aliasId; } } return array_values(array_unique($ids)); } public static function getSetorOptionById(int|string|null $id): ?array { if ($id === null || $id === '') { return null; } if (self::isStructureSetorId($id)) { $structure = Structure::query() ->select(['id', 'name']) ->where('id', (string) $id) ->whereIn('type', self::getStructureSetorTypes()) ->first(); if (!$structure) { return null; } return [ 'value' => (string) $structure->id, 'label' => (string) $structure->name, ]; } $canonicalId = self::getCanonicalSetorId($id); if ($canonicalId === null) { return null; } $label = self::SETORES[$canonicalId] ?? null; if ($label === null) { return null; } return [ 'value' => (string) $canonicalId, 'label' => $label, ]; } public static function getValidSetorIds(): array { return array_values(array_unique(array_merge( array_keys(self::SETORES), array_keys(self::SETORES_ALIAS) ))); } public static function isValidSetorId(int|string|null $id): bool { if ($id === null || $id === '') { return false; } if (self::isStructureSetorId($id)) { return Structure::query() ->where('id', (string) $id) ->whereIn('type', self::getStructureSetorTypes()) ->exists(); } if (!ctype_digit((string) $id)) { return false; } return in_array((int) $id, self::getValidSetorIds(), true); } public function getNomeSetorAttribute(): ?string { return self::getSetorNomeById($this->id_setor); } public static function getProcedimentoLabelByCdTipo(int|string|null $cdTipo): ?string { if ($cdTipo === null || $cdTipo === '') { return null; } $codigo = (int) $cdTipo; return self::TIPOS_PROCEDIMENTO[$codigo] ?? null; } public function getProcedimentoLabelAttribute(): ?string { if ($this->tipo_processo !== 'procedimento') { return null; } return self::getProcedimentoLabelByCdTipo($this->cd_tipo); } public function getModalidadeLabelAttribute(): ?string { if ($this->tipo_processo !== 'licitacao') { return null; } return self::TIPOS_LICITACAO[(int) $this->cd_tipo] ?? null; } public function getCdStatusLabelAttribute(): ?string { $status = (int) $this->cd_status; if ($this->tipo_processo === 'licitacao') { return self::STATUS_LICITACAO[$status] ?? null; } return self::STATUS_PROCEDIMENTO[$status] ?? null; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.09 |
proxy
|
phpinfo
|
Settings