diff --git a/app/Arquivo.php b/app/Arquivo.php index 197c57f01c16b128b19004a5e1993c10762b2ed4..32877871e80316fcc23e5011a79dcb03fef07299 100755 --- a/app/Arquivo.php +++ b/app/Arquivo.php @@ -15,7 +15,7 @@ class Arquivo extends Model use SoftDeletes; protected $fillable = [ - 'nome','titulo', 'versao', 'versaoFinal', 'data', 'trabalhoId', 'participanteId' + 'nome','titulo', 'versao', 'versaoFinal', 'data', 'trabalhoId', 'participanteId', 'proponenteId' ]; public function trabalho(){ @@ -29,6 +29,11 @@ class Arquivo extends Model public function participante() { return $this->belongsTo('App\Participante', 'participanteId'); } + + public function proponente() { + return $this->belongsTo('App\Proponente', 'proponenteId'); + } + public function avaliadors(){ return $this->belongsToMany('App\Avaliador', 'avaliadors_plano_trabalho')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at'); } diff --git a/app/Http/Controllers/AdministradorController.php b/app/Http/Controllers/AdministradorController.php index 8efda1599c54efc7d1d1a0cccd1049608792a608..d9bba1eac44a49ed8b5a417da756e37412a251b5 100755 --- a/app/Http/Controllers/AdministradorController.php +++ b/app/Http/Controllers/AdministradorController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Administrador; use App\AdministradorResponsavel; use App\Area; +use App\Arquivo; use App\AvaliacaoRelatorio; use App\Avaliador; use App\CoordenadorComissao; @@ -123,6 +124,24 @@ class AdministradorController extends Controller //$avaliacoesRelatorio = [];->join('users','users.id','=','candidatos.user_id') $AvalRelatParcial = []; $AvalRelatFinal = []; + if ($evento->numParticipantes == 0) { + $arquivo = Arquivo::where("trabalhoId", $trabalho->id)->first(); + + if (isset($arquivo)) { + $avals = AvaliacaoRelatorio::where('arquivo_id', $arquivo->id)->get(); + } else { + $avals = []; + } + + foreach ($avals as $aval) { + if ($aval->tipo == 'Parcial') { + array_push($AvalRelatParcial, $aval); + } else { + array_push($AvalRelatFinal, $aval); + } + } + + } foreach ($trabalho->participantes as $participante) { if (isset($participante->planoTrabalho)) { $avals = AvaliacaoRelatorio::where('arquivo_id', $participante->planoTrabalho->id)->get(); diff --git a/app/Http/Controllers/ArquivoController.php b/app/Http/Controllers/ArquivoController.php index fa9b6ce25f44647aeef4956d7820daa44c115b79..87c03928f1a15cb7108a2ef8c4de201aa8d4e6c2 100755 --- a/app/Http/Controllers/ArquivoController.php +++ b/app/Http/Controllers/ArquivoController.php @@ -124,6 +124,7 @@ class ArquivoController extends Controller $trabalho = Trabalho::where('id',$id)->first(); $participantes = $trabalho->participantes; + $evento = $trabalho->evento; // Verficação de pendencia de substituição $aux = count(Substituicao::where('status','Em Aguardo')->whereIn('participanteSubstituido_id',$trabalho->participantes->pluck('id'))->get()); @@ -139,12 +140,18 @@ class ArquivoController extends Controller return redirect()->back(); } - foreach ($participantes as $participante){ - array_push($arquivos, $participante->planoTrabalho); + if ($evento->numParticipantes != 0) { + foreach ($participantes as $participante){ + array_push($arquivos, $participante->planoTrabalho); + } + } else { + $arquivo = Arquivo::where("trabalhoId", $trabalho->id)->first(); + array_push($arquivos, $arquivo); } + $hoje = Carbon::today('America/Recife'); $hoje = $hoje->toDateString(); - return view('planosTrabalho.listar')->with(['arquivos' => $arquivos, 'hoje' => $hoje, 'trabalho' => $trabalho]); + return view('planosTrabalho.listar')->with(['arquivos' => $arquivos, 'hoje' => $hoje, 'trabalho' => $trabalho, 'evento' => $evento]); } public function anexarRelatorio(Request $request){ diff --git a/app/Http/Controllers/AvaliacaoRelatorioController.php b/app/Http/Controllers/AvaliacaoRelatorioController.php index 97a31aa99051e6819e146aaa595df3c222f6a3ac..dd1af6268b341515613c6ffe6a78b404ce8b4cc7 100644 --- a/app/Http/Controllers/AvaliacaoRelatorioController.php +++ b/app/Http/Controllers/AvaliacaoRelatorioController.php @@ -86,9 +86,11 @@ class AvaliacaoRelatorioController extends Controller public function atribuicaoAvaliador(Request $request){ $trabalho = Trabalho::find($request->trabalho_id); - foreach ($trabalho->participantes as $participante){ - $avaliadoresId= $request->input('avaliadores_'.$participante->planoTrabalho->id.'_id'); - // utilizado desta forma pois a versão do PHP 7.2 é preciso que o $array usado na função count($array) não pode ser um valor NULL. + $evento = $trabalho->evento; + if ($evento->numParticipantes == 0) { + $arquivo = Arquivo::where("trabalhoId", $trabalho->id)->first(); + + $avaliadoresId = $request->input('avaliadores_'.$arquivo->id.'_id'); $numeroDeItens = is_countable( $avaliadoresId ) ? count( $avaliadoresId ) : 0; for ($i = 0; $i < $numeroDeItens; $i++){ @@ -97,7 +99,7 @@ class AvaliacaoRelatorioController extends Controller 'comentario'=>'', 'nota'=>null, 'user_id'=>$avaliadoresId[$i], - 'arquivo_id'=>$participante->planoTrabalho->id, + 'arquivo_id'=>$arquivo->id, ]); $avaliacao->save(); Notification::send( $avaliacao->user, new AtribuicaoAvaliadorRelatorioNotification($avaliacao->tipo, $avaliacao->plano, $trabalho, $avaliacao->user)); @@ -115,6 +117,38 @@ class AvaliacaoRelatorioController extends Controller $avaliador->save(); } } + + } else { + foreach ($trabalho->participantes as $participante){ + $avaliadoresId= $request->input('avaliadores_'.$participante->planoTrabalho->id.'_id'); + // utilizado desta forma pois a versão do PHP 7.2 é preciso que o $array usado na função count($array) não pode ser um valor NULL. + $numeroDeItens = is_countable( $avaliadoresId ) ? count( $avaliadoresId ) : 0; + + for ($i = 0; $i < $numeroDeItens; $i++){ + $avaliacao = AvaliacaoRelatorio::create([ + 'tipo'=>$request->tipo_relatorio, + 'comentario'=>'', + 'nota'=>null, + 'user_id'=>$avaliadoresId[$i], + 'arquivo_id'=>$participante->planoTrabalho->id, + ]); + $avaliacao->save(); + Notification::send( $avaliacao->user, new AtribuicaoAvaliadorRelatorioNotification($avaliacao->tipo, $avaliacao->plano, $trabalho, $avaliacao->user)); + + if(Avaliador::where('user_id',$avaliadoresId[$i])->get()->count()==0){ + $userTemp = User::find($avaliadoresId[$i]); + if($userTemp->instituicao==null || $userTemp->instituicao == "UFAPE" || $userTemp->instituicao == "Universidade Federal do Agreste de Pernambuco"){ + $tipoAvaliador = "Interno"; + }else{ + $tipoAvaliador = "Externo"; + } + $avaliador = new Avaliador(); + $avaliador->tipo = $tipoAvaliador; + $avaliador->user_id = $avaliadoresId[$i]; + $avaliador->save(); + } + } + } } return redirect()->back(); } diff --git a/app/Http/Controllers/TrabalhoController.php b/app/Http/Controllers/TrabalhoController.php index 39898d2f421d82725f7e24b04f0da483e3288b63..be89feab598abc93771360f2c9ed7b78b70d7225 100755 --- a/app/Http/Controllers/TrabalhoController.php +++ b/app/Http/Controllers/TrabalhoController.php @@ -391,6 +391,7 @@ class TrabalhoController extends Controller $participantesUsersIds = Participante::where('trabalho_id', $id)->select('user_id')->get(); $users = User::whereIn('id', $participantesUsersIds)->get(); $arquivos = Arquivo::where('trabalhoId', $id)->get(); + $proponente = Proponente::where('user_id', $projeto->proponente->user_id)->first(); // Verficação de pendencia de substituição $aux = count(Substituicao::where('status','Em Aguardo')->whereIn('participanteSubstituido_id',$projeto->participantes->pluck('id'))->get()); @@ -413,6 +414,7 @@ class TrabalhoController extends Controller 'enum_turno' => Participante::ENUM_TURNO, 'areasTematicas' => $areasTematicas, 'flagSubstituicao' =>$flagSubstituicao, + 'proponente' => $proponente, ]); } @@ -480,6 +482,7 @@ class TrabalhoController extends Controller 'estados' => $this->estados, 'areaTematicas' => $areaTematicas, 'listaOds' => $ODS, + 'proponente' => $proponente, ]); } @@ -850,6 +853,7 @@ class TrabalhoController extends Controller ]); $trabalho = Trabalho::find($id); $trabalho->ods()->sync($request->ods); + $proponente = Proponente::where('user_id', Auth::user()->id)->first(); DB::beginTransaction(); if (!$trabalho) { @@ -872,27 +876,29 @@ class TrabalhoController extends Controller $trabalho = $this->armazenarAnexosFinais($request, $pasta, $trabalho, $evento); $trabalho->save(); - - if ($request->marcado == null) { - $idExcluido = $trabalho->participantes->pluck('id'); - - } else { - $idExcluido = []; - } - - foreach ($request->participante_id as $key => $value) { - if ($request->marcado != null && array_search($key, $request->marcado) === false) { - if ($value !== null) - array_push($idExcluido, $value); + + if ($evento->numParticipantes != 0) { + if ($request->marcado == null) { + $idExcluido = $trabalho->participantes->pluck('id'); + + } else { + $idExcluido = []; } + + foreach ($request->participante_id as $key => $value) { + if ($request->marcado != null && array_search($key, $request->marcado) === false) { + if ($value !== null) + array_push($idExcluido, $value); + } + } + + + foreach ($idExcluido as $key => $value) { + $trabalho->participantes()->find($value)->delete(); + } + $trabalho->refresh(); } - - foreach ($idExcluido as $key => $value) { - $trabalho->participantes()->find($value)->delete(); - } - $trabalho->refresh(); - if ($request->has('marcado')) { foreach ($request->marcado as $key => $part) { $part = intval($part); @@ -1015,6 +1021,39 @@ class TrabalhoController extends Controller } + } else { + $data['nomePlanoTrabalho'] = $request->nomePlanoTrabalho; + + if (Arquivo::where('proponenteId', $proponente->id)->where('trabalhoId', $trabalho->id)->count()) { + $arquivo = Arquivo::where('proponenteId', $proponente->id)->where('trabalhoId', $trabalho->id)->first(); + $path = 'trabalhos/' . $evento->id . '/' . $trabalho->id . '/'; + $nome = $data['nomePlanoTrabalho'] . ".pdf"; + $titulo = $data['nomePlanoTrabalho']; + if ($request->has('anexoPlanoTrabalho')) { + $file = $request->anexoPlanoTrabalho; + Storage::putFileAs($path, $file, $nome); + } else { + Storage::rename( $arquivo->nome, $path.$nome ); + } + $arquivo->update([ + 'titulo' => $titulo, + 'nome' => $path . $nome, + 'data' => now(), + ]); + } else { + $path = 'trabalhos/' . $evento->id . '/' . $trabalho->id . '/'; + $nome = $data['nomePlanoTrabalho'] . ".pdf"; + $file = $request->anexoPlanoTrabalho; + Storage::putFileAs($path, $file, $nome); + $arquivo = new Arquivo(); + $arquivo->titulo = $data['nomePlanoTrabalho']; + $arquivo->nome = $path . $nome; + $arquivo->trabalhoId = $trabalho->id; + $arquivo->data = now(); + $arquivo->proponenteId = $proponente->id; + $arquivo->versaoFinal = true; + $arquivo->save(); + } } DB::commit(); @@ -1047,6 +1086,7 @@ class TrabalhoController extends Controller ]); } $evento = Evento::find($request->editalId); + $proponente = Proponente::where('user_id', Auth::user()->id)->first(); $request->merge([ 'coordenador_id' => $evento->coordenadorComissao->id ]); @@ -1146,6 +1186,23 @@ class TrabalhoController extends Controller } + } + } else { + $data['nomePlanoTrabalho'] = $request->nomePlanoTrabalho; + if ($request->has('anexoPlanoTrabalho')) { + $path = 'trabalhos/' . $evento->id . '/' . $trabalho->id . '/'; + $nome = $data['nomePlanoTrabalho'] . ".pdf"; + $file = $request->anexoPlanoTrabalho; + Storage::putFileAs($path, $file, $nome); + $arquivo = new Arquivo(); + $arquivo->titulo = $data['nomePlanoTrabalho']; + $arquivo->nome = $path . $nome; + $arquivo->trabalhoId = $trabalho->id; + $arquivo->data = now(); + $arquivo->proponenteId = $proponente->id; + $arquivo->versaoFinal = true; + $arquivo->save(); + } } diff --git a/app/Http/Requests/StoreTrabalho.php b/app/Http/Requests/StoreTrabalho.php index 4cc981ca88936f97f51372b5bf72070c1c8d1160..8c7edd08624ce6768831ddf6798aa16e93f2a896 100755 --- a/app/Http/Requests/StoreTrabalho.php +++ b/app/Http/Requests/StoreTrabalho.php @@ -31,9 +31,6 @@ class StoreTrabalho extends FormRequest $evento = Evento::find($this->editalId); $rules = []; - if(!($this->has('marcado'))){ - $rules['erro'] = ['required']; - } if($this->has('marcado')){ foreach ($this->get('marcado') as $key => $value) { if( intval($value) == $key){ @@ -67,6 +64,9 @@ class StoreTrabalho extends FormRequest } } + } else { + $rules['anexoPlanoTrabalho'] = ['required']; + $rules['nomePlanoTrabalho'] = ['required', 'string']; } if($this->has('rascunho')) { diff --git a/app/Http/Requests/UpdateTrabalho.php b/app/Http/Requests/UpdateTrabalho.php index 4d8cff53606e972f91870ae01f69e420d413b583..83534ac6bce9723515cf2c87259bd6d3f522437d 100755 --- a/app/Http/Requests/UpdateTrabalho.php +++ b/app/Http/Requests/UpdateTrabalho.php @@ -6,6 +6,7 @@ use App\Arquivo; use App\Evento; use App\Participante; use App\Trabalho; +use App\Proponente; use Illuminate\Validation\Rule; use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Http\FormRequest; @@ -32,9 +33,6 @@ class UpdateTrabalho extends FormRequest $projeto = Trabalho::find($this->id); $evento = Evento::find($this->editalId); - if(!($this->has('marcado'))){ - $rules['erro'] = ['required']; - } if($this->has('marcado')){ foreach ($this->get('marcado') as $key => $value) { if( intval($value) == $key){ @@ -67,20 +65,17 @@ class UpdateTrabalho extends FormRequest if($evento->tipo != "PIBEX") { $rules['media_do_curso.' . $value] = ['required', 'string']; } + $rules['anexoPlanoTrabalho.'.$value] = [Rule::requiredIf($participante->planoTrabalho == null)]; $rules['nomePlanoTrabalho.'.$value] = ['required', 'string']; - - if($participante !=null){ - $arquivo = Arquivo::where('participanteId',$participante->id)->where('trabalhoId',$projeto->id)->first(); - if($arquivo == null || $this->nomePlanoTrabalho[$value] != $arquivo->titulo){ - $rules['anexoPlanoTrabalho.'.$value] = ['required', 'mimes:pdf']; - } - }else{ - $rules['anexoPlanoTrabalho.'.$value] = ['required', 'mimes:pdf']; - } - + } } + } else { + $arquivo = Arquivo::where("trabalhoId", $projeto->id)->first(); + $rules['anexoPlanoTrabalho'] = [Rule::requiredIf($arquivo == null)]; + $rules['nomePlanoTrabalho'] = [Rule::requiredIf($arquivo->titulo == null), 'string']; } + // dd($this->all()); if ($this->has('rascunho')) { $rules = []; diff --git a/app/Proponente.php b/app/Proponente.php index 3a4f9de5bb7566bcde8386237a961b8b2cd5d230..40ebd4777767db54cedc9559ffea0926ea01d99b 100755 --- a/app/Proponente.php +++ b/app/Proponente.php @@ -11,6 +11,9 @@ class Proponente extends Model public function user(){ return $this->belongsTo('App\User'); } + public function planoTrabalho() { + return $this->hasOne('App\Arquivo', 'proponenteId'); + } public function trabalhos(){ return $this->hasMany('App\Trabalho'); } diff --git a/database/migrations/2022_11_21_161801_alter_table_arquivos3.php b/database/migrations/2022_11_21_161801_alter_table_arquivos3.php new file mode 100644 index 0000000000000000000000000000000000000000..5726f4fd781f19e8c0222e1be10d95dfe098272d --- /dev/null +++ b/database/migrations/2022_11_21_161801_alter_table_arquivos3.php @@ -0,0 +1,30 @@ +integer('participanteId')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/database/migrations/2022_11_22_115005_add_proponente_arquivos_table.php b/database/migrations/2022_11_22_115005_add_proponente_arquivos_table.php new file mode 100644 index 0000000000000000000000000000000000000000..48a1d24e6b62d4755a9fc3f5e84bf0b7d47cc193 --- /dev/null +++ b/database/migrations/2022_11_22_115005_add_proponente_arquivos_table.php @@ -0,0 +1,32 @@ +integer('proponenteId')->nullable(); + + $table->foreign('proponenteId')->references('id')->on('proponentes'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/administrador/analisar.blade.php b/resources/views/administrador/analisar.blade.php index 488d52f35d53061f28af4629b9a71359ec9842be..4a7daed38906a8cf5280697d0730066509dfa87c 100755 --- a/resources/views/administrador/analisar.blade.php +++ b/resources/views/administrador/analisar.blade.php @@ -103,12 +103,13 @@

Proponente: {{ App\Proponente::find($trabalho->proponente_id)->user->name }}

- + @if ($evento->numParticipantes != 0)

Discentes: @foreach($trabalho->participantes as $participante) {{$participante->user->name}}; @endforeach

+ @endif @if($trabalho->grande_area_id != null && $trabalho->area_id != null && $trabalho->sub_area_id != null)
{{$trabalho->grandeArea->nome}} > {{$trabalho->area->nome}} > {{$trabalho->subArea->nome}}
diff --git a/resources/views/administrador/analisarProposta.blade.php b/resources/views/administrador/analisarProposta.blade.php index 8c68681a909c11fbd5a5e60361d627f1360fcfc3..7d8f5768584a0ead7512c03d19e4d70e560c17f3 100644 --- a/resources/views/administrador/analisarProposta.blade.php +++ b/resources/views/administrador/analisarProposta.blade.php @@ -140,6 +140,24 @@ {{$trabalho->modalidade}}
@endif + @if ($evento->numParticipantes == 0) + @php + $arquivo = App\Arquivo::where("trabalhoId", $trabalho->id)->first(); + @endphp +
+
+ Título do Plano de Trabalho: + {{$arquivo->titulo}} +
+
+
+ + + + +
+ @endif @if ($trabalho->conflitosInteresse != null)

@@ -154,6 +172,7 @@
+ @if ($evento->numParticipantes != 0)
@@ -295,6 +314,7 @@
+ @endif {{--Janelas para aprovação ou reprovação de substituição--}}