File manager - Edit - /var/www/html/portalHomolog/app/Http/Services/Admin/SecretariaService.php
Back
<?php namespace App\Http\Services\Admin; use App\Models\Structure; use App\Models\Endereco; use App\Http\Controllers\Controller; use Illuminate\Database\Eloquent\Collection; use Illuminate\Pagination\LengthAwarePaginator; class SecretariaService extends Controller { /** * Lista todas as secretarias ativas * * @return Collection */ public function getAllSecretarias(): Collection { return Structure::where("status", "ATIVADO") ->orderBy("name", "ASC") ->get(); } /** * Lista todas as estruturas por tipo * * @param string $type * @return Collection */ public function getByType(string $type): Collection { return Structure::where("type", $type) ->orderBy('name', 'asc') ->get(); } /** * Lista estruturas ativas por tipo * * @param string $type * @return Collection */ public function getActiveByType(string $type): Collection { return Structure::where("type", $type) ->where("status", "=", "ATIVADO") ->orderBy('name', 'asc') ->get(); } /** * Lista estruturas por múltiplos tipos * * @param array $types * @return Collection */ public function getByTypes(array $types): Collection { return Structure::whereIn('type', $types) ->orderBy('name', 'asc') ->get(); } /** * Lista estruturas sem parent (principais) * * @return Collection */ public function getMainStructures(): Collection { return Structure::select("id", "name", "abbreviation") ->where("structure_id", "=", null) ->orderBy('name', 'asc') ->get(); } /** * Conta estruturas por tipo * * @param string $type * @return int */ public function countByType(string $type): int { return Structure::where("type", $type)->count(); } /** * Cria uma nova estrutura/secretaria * * @param array $data * @return Structure */ public function create(array $data): Structure { return Structure::create($data); } /** * Atualiza uma estrutura/secretaria existente * * @param Structure $structure * @param array $data * @return Structure */ public function update(Structure $structure, array $data): Structure { $structure->update($data); return $structure; } /** * Exclui uma estrutura/secretaria * * @param Structure $structure * @return void */ public function delete(Structure $structure): void { Structure::destroy($structure->id); } /** * Atualiza o status de uma estrutura/secretaria * * @param Structure $structure * @param string $status * @return Structure */ public function updateStatus(Structure $structure, string $status): Structure { $structure->fill(['status' => $status]); $structure->save(); return $structure; } /** * Cria ou atualiza o endereço de uma estrutura/secretaria * * @param Structure $structure * @param array $enderecoData * @param string $userId * @return Endereco */ public function createOrUpdateEndereco(Structure $structure, array $enderecoData, string $userId): Endereco { $existeEndereco = Endereco::where("owner_id", $structure->id)->first(); if ($existeEndereco) { $existeEndereco->update($enderecoData); return $existeEndereco; } else { $enderecoData['user_id'] = $userId; $enderecoData['owner_id'] = $structure->id; return Endereco::create($enderecoData); } } /** * Exclui o endereço de uma estrutura/secretaria * * @param Structure $structure * @return void */ public function deleteEndereco(Structure $structure): void { if (isset($structure->endereco->id)) { Endereco::destroy($structure->endereco->id); } } /** * Busca estruturas ativas por slug * * @param string $slug * @return Structure|null */ public function getBySlug(string $slug): ?Structure { return Structure::select("*") ->where("slug", "=", $slug) ->where("status", "=", "ATIVADO") ->orderBy('name', 'asc') ->first(); } /** * Busca desdobramentos de uma estrutura por tipo * * @param string $structureId * @param string $type * @return Collection */ public function getDesdobramentos(string $structureId, string $type): Collection { return Structure::select("id", "slug", "name", "type") ->where("structure_id", "=", $structureId) ->where("type", "=", $type) ->where("status", "=", "ATIVADO") ->orderBy('name', 'asc') ->get(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings