Skip to content

Commit f8dda86

Browse files
authored
Merge pull request #163 from oFandangos/master
AgendamentoService mudado; Migration de alteração e busca na aba "Comunicação" por filtro de ano
2 parents f594b42 + 33bddc6 commit f8dda86

11 files changed

Lines changed: 206 additions & 69 deletions

File tree

app/Http/Controllers/AgendamentoController.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,33 @@ class AgendamentoController extends Controller
2828
public function index(Request $request)
2929
{
3030
$this->authorize('admin');
31-
$query = Agendamento::orderBy('data_horario', 'asc');
32-
$query2 = Docente::orderBy('nome', 'asc');
33-
if($request->filtro_busca == 'numero_nome') {
34-
$query->where('codpes', '=', $request->busca);
35-
if($query->count() == null){
36-
$query->orWhere('nome', 'LIKE', "%$request->busca%");
37-
}
38-
$query2->where('nome', 'LIKE', "%$request->busca%");
39-
foreach($query2->get() as $orientador){
40-
$query->orWhere('orientador', '=', $orientador->n_usp);
41-
}
42-
}
43-
elseif($request->filtro_busca == 'data'){
44-
$validated = $request->validate([
45-
'busca_data' => 'required|date_format:d/m/Y', //arrumado para date_format
46-
]);
47-
$data = Carbon::CreatefromFormat('d/m/Y H:i', $validated['busca_data']." 00:00");
48-
$query->whereDate('data_horario','=', $data);
49-
}
50-
else{
51-
$query->where('data_horario','>=',date('Y-m-d H:i:s'));
52-
}
53-
$agendamentos = $query->paginate(20);
5431

55-
if ($agendamentos->count() == null) {
56-
$request->session()->flash('alert-danger', 'Não há registros!');
57-
}
58-
return view('agendamentos.index')->with('agendamentos',$agendamentos);
32+
if($request->busca || $request->filled('busca_data')){
33+
$query = Agendamento::orderBy('data_horario', 'desc');
34+
$query2 = Docente::orderBy('nome', 'desc');
35+
if($request->filtro_busca == 'numero_nome') {
36+
$query->where('codpes', '=', $request->busca);
37+
if($query->count() == null){
38+
$query->orWhere('nome', 'LIKE', "%$request->busca%");
39+
}
40+
$query2->where('nome', 'LIKE', "%$request->busca%");
41+
foreach($query2->get() as $orientador){
42+
$query->orWhere('orientador', '=', $orientador->n_usp);
43+
}
44+
45+
}elseif($request->filtro_busca == 'data'){
46+
$validated = $request->validate([
47+
'busca_data' => 'required|date_format:d/m/Y', //arrumado para date_format
48+
]);
49+
$data = Carbon::CreatefromFormat('d/m/Y H:i', $validated['busca_data']." 00:00");
50+
$query->whereDate('data_horario','=', $data);
51+
}else{
52+
$query->where('data_horario','>=',date('Y-m-d H:i:s'));
53+
}
54+
}
55+
return view('agendamentos.index', [
56+
'agendamentos' => $request->busca || $request->busca_data ? $query->paginate(20) : []
57+
]);
5958
}
6059

6160
public function create()

app/Http/Controllers/CommunicationController.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313

1414
class CommunicationController extends Controller
1515
{
16-
public function index(){
16+
public function index(Request $request){
1717
Gate::authorize('comunicacao');
18+
1819
$agendamentos = Agendamento::where('status',1)
19-
->orderBy('data_horario', 'desc')
20-
->paginate(15);
21-
22-
return view('comunicacao.index', ['agendamentos' => $agendamentos]);
20+
->orderBy('data_publicacao','desc')
21+
->where('data_publicacao',">=","$request->filtro_ano" . '-01-01 00:00:00')
22+
->where('data_publicacao',"<=","$request->filtro_ano" . '-12-31 23:59:59'); // Não dá pra fazer group by com id...
23+
return view('comunicacao.index', ['agendamentos' => $agendamentos->paginate(15)]);
2324
}
24-
25+
2526
public function show(Agendamento $agendamento){
2627
Gate::authorize('comunicacao');
27-
$dadosJanus = ReplicadoUtils::retornarDadosJanus($agendamento->codpes);
28+
$dadosJanus = ReplicadoUtils::retornarDadosComunicacao($agendamento->codpes);
2829
return view('comunicacao.show', ['agendamento' => $agendamento, 'dadosJanus' => $dadosJanus]);
2930
}
3031
}

app/Http/Requests/JanusRequest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public function rules(): array
3030
'data' => 'required|date_format:d/m/Y',
3131
'horario' => 'required|date_format:H:i',
3232
'sala' => 'required',
33-
'regimento' => 'required',
34-
'orientador_votante' => 'required',
35-
'tipo_defesa' => 'required'
33+
'regimento' => 'nullable',
34+
'orientador_votante' => 'nullable',
35+
'tipo_defesa' => 'required',
36+
'sala_virtual' => 'nullable'
3637
];
3738
}
3839

app/Models/Agendamento.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Models\Communication;
1515
use Uspdev\Replicado\Pessoa;
1616
use App\Models\User;
17+
use Illuminate\Support\Facades\DB as QueryBuilder;
1718

1819
class Agendamento extends Model
1920
{
@@ -125,6 +126,16 @@ public static function statusApprovalOptions(){
125126
'Reprovado'
126127
];
127128
}
129+
130+
public static function retornarAnoPublicacao(){
131+
$datas = QueryBuilder::select(
132+
"SELECT YEAR(data_publicacao) as data_publicacao FROM agendamentos
133+
GROUP BY YEAR(data_publicacao)
134+
ORDER BY YEAR(data_publicacao) DESC
135+
"
136+
);
137+
return $datas;
138+
}
128139

129140
public function docente() {
130141
return $this->hasOne(Docente::class, 'n_usp', 'orientador');

app/Services/AgendamentoService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public function newAgendamento(array $agendamentoData, array $dadosJanus): Agend
1818
$agendamento = new Agendamento();
1919
$agendamento->codpes = $agendamentoData['codpes'];
2020
$agendamento->sala = $agendamentoData['sala'];
21-
$agendamento->regimento = $agendamentoData['regimento'];
22-
$agendamento->orientador_votante = $agendamentoData['orientador_votante'];
2321
$agendamento->tipo = $agendamentoData['tipo_defesa'];
2422
$agendamento->data_horario = Carbon::createFromFormat('d/m/Y H:i', $agendamentoData['data'] . $agendamentoData['horario'])->format('Y-m-d H:i');
2523
$agendamento->nome = $dadosJanus['nompes'];
@@ -28,6 +26,7 @@ public function newAgendamento(array $agendamentoData, array $dadosJanus): Agend
2826
$agendamento->nivel = $dadosJanus['nivpgm'] == "ME" ? 'Mestrado' : 'Doutorado';
2927
$agendamento->orientador = $dadosJanus['orientador'];
3028
$agendamento->resumo = $dadosJanus['rsutrb'];
29+
$agendamento->sala_virtual = $agendamentoData['sala_virtual'] ?? NULL;
3130
$agendamento->save();
3231

3332
return $agendamento;

app/Utils/ReplicadoUtils.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ public static function retornarDadosJanus($codpes){
159159
return DBreplicado::fetch($query, $param);
160160
}
161161

162+
public static function retornarDadosComunicacao($codpes){
163+
$query = "SELECT A.nivpgm, T.rsutrb
164+
FROM AGPROGRAMA AS A
165+
INNER JOIN DDTDEPOSITOTRABALHO AS D
166+
ON A.codpes = D.codpes
167+
INNER JOIN DDTENTREGATRABALHO AS T
168+
ON D.coddpodgttrb = T.coddpodgttrb
169+
WHERE A.codpes = convert(int, :codpes)";
170+
$param = [
171+
'codpes' => $codpes,
172+
];
173+
174+
return DBreplicado::fetch($query, $param);
175+
}
176+
162177
public static function retornarDadosBanca(int $codpes, int $numseqpgm){
163178
$query = "SELECT R.codpesdct, R.vinptpbantrb, P.nompes FROM R48PGMTRBDOC R
164179
INNER JOIN PESSOA P
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('agendamentos', function (Blueprint $table) {
15+
$table->string('orientador_votante')->nullable()->change();
16+
$table->string('regimento')->nullable()->change();
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::table('agendamentos', function (Blueprint $table) {
26+
//
27+
});
28+
}
29+
};

resources/views/agendamentos/index.blade.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
</form>
4141
</div>
4242
</div>
43+
@if(!request()->filled('busca') && !request()->filled('busca_data'))
44+
<div class="alert alert-info" style="margin-top:8px;">Para visualizar os agendamentos procure por algum no campo de pesquisa</div>
45+
@endif
46+
@if($agendamentos)
4347
<table class="table table-striped">
4448
<theader>
4549
<tr>
@@ -52,7 +56,7 @@
5256
</tr>
5357
</theader>
5458
<tbody>
55-
@foreach ($agendamentos as $agendamento)
59+
@forelse ($agendamentos as $agendamento)
5660
<tr>
5761
<td>{{ $agendamento->codpes }}</td>
5862
<td><a href="/agendamentos/{{$agendamento->id}}">{{ $agendamento->nome }}</a></td>
@@ -70,8 +74,11 @@
7074
</form>
7175
</td>
7276
</tr>
73-
@endforeach
77+
@empty
78+
<div class="alert alert-danger">Sem registros!</div>
79+
@endforelse
7480
</tbody>
7581
</table>
7682
{{ $agendamentos->appends(request()->query())->links() }}
83+
@endif
7784
@endsection('content')

resources/views/agendamentos/janus/form.blade.php

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,16 @@
88
<div class="row">
99
<div class="col">
1010
<label for="sala">Sala</label>
11-
<input type="text" class="form-control" name="sala" value="{{ old('sala') }}" placeholder="Insira a sala">
11+
<input type="text" class="form-control" name="sala" id="sala" value="{{ old('sala') }}" placeholder="Insira a sala">
1212
</div>
1313
<div class="col">
1414
<label for="tipo_defesa">Tipo da Defesa</label>
15-
<select class="form-control" name="tipo_defesa">
15+
<select class="form-control" name="tipo_defesa" id="tipo_defesa">
1616
@foreach($agendamento::tipoDefesaOptions() as $option)
1717
<option value="{{$option}}">{{$option}}</option>
1818
@endforeach
1919
</select>
2020
</div>
21-
<div class="col">
22-
<label for="regimento">Regimento</label>
23-
<select class="form-control" name="regimento">
24-
@foreach($agendamento::regimentoOptions() as $option)
25-
<option value="{{$option}}">{{$option}}</option>
26-
@endforeach
27-
</select>
28-
</div>
29-
30-
<div class="col">
31-
<label for="orientador_votante">Orientador Votante</label>
32-
<select class="form-control" name="orientador_votante">
33-
@foreach($agendamento::orientadorvotanteOptions() as $option)
34-
<option value="{{$option}}">{{$option}}</option>
35-
@endforeach
36-
</select>
37-
</div>
3821
</div>
3922

4023
<div class="row">
@@ -54,6 +37,49 @@
5437
</div>
5538
</div>
5639

40+
41+
<script>
42+
document.addEventListener('DOMContentLoaded', function() {
43+
let container = document.createElement('input');
44+
let tipoDefesaSelect = document.getElementById('tipo_defesa');
45+
46+
tipoDefesaSelect.addEventListener('change', function() {
47+
if (tipoDefesaSelect.value === 'Virtual') {
48+
createInput();
49+
} else {
50+
removeInput();
51+
}
52+
});
53+
54+
function createInput() {
55+
let div = document.createElement('div');
56+
let row = document.createElement('div');
57+
let label = document.createElement('label');
58+
label.innerHTML = 'Link da sala virtual';
59+
container.classList.add('form-control');
60+
container.name = 'sala_virtual';
61+
container.placeholder = 'Insira o link da sala virtual';
62+
row.id = 'sala_virtual';
63+
row.classList.add('col');
64+
div.appendChild(label);
65+
row.appendChild(div);
66+
div.appendChild(container);
67+
let parentDiv = tipoDefesaSelect.closest('.row');
68+
69+
if (!document.querySelector('input[name="sala_virtual"]')) {
70+
parentDiv.appendChild(row);
71+
}
72+
}
73+
74+
function removeInput() {
75+
let div = document.querySelector('div[id="sala_virtual"]');
76+
if(document.querySelector('div[class="row"')){
77+
div.remove();
78+
}
79+
}
80+
});
81+
</script>
82+
5783
<style>
5884
.row{
5985
margin-top:5px;

0 commit comments

Comments
 (0)