File manager - Edit - /var/www/html/portalHomolog/app/Http/Services/IndicadoresTi/GerenciarAssuntosService.php
Back
<?php namespace App\Http\Services\IndicadoresTi; use App\Models\IndicadoresTi\Assunto; use App\Models\IndicadoresTi\Setor; use App\Models\IndicadoresTi\Subassunto; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; class GerenciarAssuntosService { public function getSetoresComAssuntos(): Collection { return Setor::with([ 'unidade', 'assuntos' => fn ($q) => $q ->withCount('subassuntos') ->with(['subassuntos' => fn ($q2) => $q2->orderBy('nome')]) ->orderBy('nome'), ])->orderBy('nome')->get(); } public function criarSetor(array $dados): Setor { return Setor::create($dados); } public function setorJaExiste(string $nome, ?int $ignorarId = null): bool { return Setor::when($ignorarId, fn ($q) => $q->where('id', '!=', $ignorarId)) ->whereRaw('LOWER(nome) = ?', [mb_strtolower($nome)]) ->exists(); } public function atualizarSetor(Setor $setor, array $dados): void { $setor->update($dados); } public function excluirSetor(Setor $setor): bool { if ($setor->assuntos()->exists()) { return false; } $setor->delete(); return true; } public function criarAssunto(array $dados): Assunto { return Assunto::create($dados); } public function assuntoJaExiste(int $setorId, string $nome, ?int $ignorarId = null): bool { return Assunto::where('setor_id', $setorId) ->when($ignorarId, fn ($q) => $q->where('id', '!=', $ignorarId)) ->whereRaw('LOWER(nome) = ?', [mb_strtolower($nome)]) ->exists(); } public function atualizarAssunto(Assunto $assunto, array $dados): void { $assunto->update($dados); } public function excluirAssunto(Assunto $assunto): bool { if ($assunto->subassuntos()->exists()) { return false; } $assunto->delete(); return true; } public function criarSubassunto(array $dados): Subassunto { return Subassunto::create($dados); } public function subassuntoJaExiste(int $assuntoId, string $nome, ?int $ignorarId = null): bool { return Subassunto::where('assunto_id', $assuntoId) ->when($ignorarId, fn ($q) => $q->where('id', '!=', $ignorarId)) ->whereRaw('LOWER(nome) = ?', [mb_strtolower($nome)]) ->exists(); } public function atualizarSubassunto(Subassunto $subassunto, array $dados): void { $subassunto->update($dados); } public function excluirSubassunto(Subassunto $subassunto): void { $subassunto->delete(); } public function togglePublico(Model $model): void { $model->update(['publico' => !$model->publico]); } public function getSetoresPublicos(): Collection { return Setor::where('publico', true) ->with([ 'assuntos' => fn ($q) => $q ->where('publico', true) ->with(['subassuntos' => fn ($q2) => $q2->where('publico', true)->orderBy('nome')]) ->orderBy('nome'), ]) ->orderBy('nome') ->get(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings