diff --git a/app/Avaliador.php b/app/Avaliador.php index b1c813708bfb0208d9fd7c374d3a9ef3695ad6b4..4ac1b051a7586719c499b450db9ba67e1b43e111 100755 --- a/app/Avaliador.php +++ b/app/Avaliador.php @@ -19,7 +19,7 @@ class Avaliador extends Model return $this->belongsTo('App\User'); } public function trabalhos(){ - return $this->belongsToMany('App\Trabalho')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at','pontuacao'); + return $this->belongsToMany('App\Trabalho')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at','pontuacao','acesso'); } public function planoTrabalhos(){ return $this->belongsToMany('App\Arquivo', '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 648e6f74dbc05daaee27cab5065dcfb82b79a69a..6073f3630d3e40ed0712cc46281334debcc81a96 100755 --- a/app/Http/Controllers/AdministradorController.php +++ b/app/Http/Controllers/AdministradorController.php @@ -642,25 +642,47 @@ class AdministradorController extends Controller $trabalho = Trabalho::where('id', $request->trabalho_id)->first(); $evento = Evento::where('id', $request->evento_id)->first(); - if($request->avaliadores_internos_id == null){ - $avaliadoresInternos = []; - }else{ - $avaliadoresInternos = $request->avaliadores_internos_id; + if($request->avaliadores_internos_id != null){ + foreach ($request->avaliadores_internos_id as $avaliador) { + $aval = Avaliador::find($avaliador); + if($aval->trabalhos()->where("trabalho_id",$trabalho->id)->first() != null){ + $aval->trabalhos() + ->updateExistingPivot($trabalho->id,['acesso'=>3]); + }else{ + $trabalho->avaliadors()->attach($aval,['acesso'=>2]); + $evento->avaliadors()->syncWithoutDetaching($aval); + } + } } - if($request->avaliadores_externos_id == null){ - $avaliadoresExternos = []; - }else{ - $avaliadoresExternos = $request->avaliadores_externos_id; - } - $idsAvaliadores = array_merge($avaliadoresInternos, $avaliadoresExternos); - if($idsAvaliadores == null){ - redirect()->back()->with(['error' => 'Selecione ao menos um avaliador.', 'trabalho' => $trabalho->id]); - } - $avaliadores = Avaliador::whereIn('id', $idsAvaliadores)->get(); - $trabalho->avaliadors()->attach($avaliadores); - $evento->avaliadors()->syncWithoutDetaching($avaliadores); - $trabalho->save(); + + if($request->avaliadores_externos_id != null){ + foreach ($request->avaliadores_externos_id as $avaliador) { + + $aval = Avaliador::find($avaliador); + if(Avaliador::where('id',$avaliador)->where('tipo',"Interno")->count()>0){ + if($aval->trabalhos()->where("trabalho_id",$trabalho->id)->first() != null){ + $aval->trabalhos() + ->updateExistingPivot($trabalho->id,['acesso'=>3]); + }else{ + $trabalho->avaliadors()->attach($aval,['acesso'=>1]); + $evento->avaliadors()->syncWithoutDetaching($aval); + } + }else{ + $trabalho->avaliadors()->attach($aval,['acesso'=>1]); + $evento->avaliadors()->syncWithoutDetaching($aval); + } + } + } + + if($request->avaliadores_externos_id == null & $request->avaliadores_internos_id == null ){ + redirect()->back()->with(['error' => 'Selecione ao menos um avaliador.', 'trabalho' => $trabalho->id]); + } + + $avaliadores = Avaliador::whereIn('id', (array)$request->avaliadores_externos_id) + ->orWhereIn('id', (array)$request->avaliadores_internos_id)->get(); + $trabalho->save(); + foreach ($avaliadores as $avaliador){ diff --git a/app/Http/Controllers/AvaliadorController.php b/app/Http/Controllers/AvaliadorController.php index 0212edf5bc544f9c9db77a75513d689da6289037..159b12e781352f83103afea04181de814abac861 100755 --- a/app/Http/Controllers/AvaliadorController.php +++ b/app/Http/Controllers/AvaliadorController.php @@ -71,11 +71,22 @@ class AvaliadorController extends Controller $user = User::find(Auth::user()->id); $evento = Evento::where('id', $request->evento_id)->first(); - $trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); + //$trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); + $trabalhosEx = []; + $trabalhosIn = []; + $aval = $user->avaliadors->where('user_id',$user->id)->first(); + foreach ($aval->trabalhos as $trab){ + if($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 2 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3 ){ + array_push($trabalhosIn,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + if ($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 1 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3){ + array_push($trabalhosEx,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + } //dd(); - return view('avaliador.listarTrabalhos', ['trabalhos'=>$trabalhos, 'evento'=>$evento]); + return view('avaliador.listarTrabalhos', ['trabalhosEx'=>$trabalhosEx,'trabalhosIn'=>$trabalhosIn, 'evento'=>$evento]); } @@ -121,7 +132,18 @@ class AvaliadorController extends Controller public function enviarParecerInterno(Request $request){ $user = User::find(Auth::user()->id); $evento = Evento::where('id', $request->evento_id)->first(); - $trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); + //$trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); + $trabalhosEx = []; + $trabalhosIn = []; + $aval = $user->avaliadors->where('user_id',$user->id)->first(); + foreach ($aval->trabalhos as $trab){ + if($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 2 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3 ){ + array_push($trabalhosIn,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + if ($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 1 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3){ + array_push($trabalhosEx,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + } $avaliador = $user->avaliadors->where('user_id',$user->id)->first(); $trabalho = $avaliador->trabalhos->find($request->trabalho_id); $parecerInterno = ParecerInterno::where([['avaliador_id',$avaliador->id],['trabalho_id',$trabalho->id]])->first(); @@ -168,7 +190,7 @@ class AvaliadorController extends Controller $parecerInterno->update(); } - return view('avaliador.listarTrabalhos', ['trabalhos'=>$trabalhos, 'evento'=>$evento]); + return view('avaliador.listarTrabalhos', ['trabalhosEx'=>$trabalhosEx,'trabalhosIn'=>$trabalhosIn, 'evento'=>$evento]); } public function parecerPlano(Request $request){ @@ -188,8 +210,19 @@ class AvaliadorController extends Controller $evento = Evento::find($request->evento_id); - $trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); - $avaliador = $user->avaliadors->where('user_id',$user->id)->first(); + //$trabalhos = $user->avaliadors->where('user_id',$user->id)->first()->trabalhos->where('evento_id', $request->evento_id); + $trabalhosEx = []; + $trabalhosIn = []; + $aval = $user->avaliadors->where('user_id',$user->id)->first(); + foreach ($aval->trabalhos as $trab){ + if($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 2 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3 ){ + array_push($trabalhosIn,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + if ($aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 1 || $aval->trabalhos()->where("trabalho_id",$trab->id)->first()->pivot->acesso == 3){ + array_push($trabalhosEx,$aval->trabalhos()->where("trabalho_id",$trab->id)->first()); + } + } + $avaliador = $user->avaliadors->where('user_id',$user->id)->first(); $trabalho = $avaliador->trabalhos->find($request->trabalho_id); $trabalho->status = 'avaliado'; $trabalho->save(); @@ -221,7 +254,7 @@ class AvaliadorController extends Controller // dd($trabalho); - return view('avaliador.listarTrabalhos', ['trabalhos'=>$trabalhos, 'evento'=>$evento ]); + return view('avaliador.listarTrabalhos', ['trabalhosEx'=>$trabalhosEx,'trabalhosIn'=>$trabalhosIn, 'evento'=>$evento ]); } public function conviteResposta(Request $request){ //dd($request->all()); diff --git a/app/Trabalho.php b/app/Trabalho.php index 4cf04c391a08b09853c3a1947837e96029661799..99eea018fed7523f26108428afa3b80d87450335 100755 --- a/app/Trabalho.php +++ b/app/Trabalho.php @@ -102,7 +102,7 @@ class Trabalho extends Model return $this->belongsTo('App\CoordenadorComissao'); } public function avaliadors(){ - return $this->belongsToMany('App\Avaliador')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at','pontuacao'); + return $this->belongsToMany('App\Avaliador')->withPivot('status', 'AnexoParecer', 'parecer', 'recomendacao', 'created_at','pontuacao','acesso'); } public function substituicaos(){ diff --git a/database/migrations/2022_06_07_073221_add_acesso_to_avaliadors_trabalhos_table.php b/database/migrations/2022_06_07_073221_add_acesso_to_avaliadors_trabalhos_table.php new file mode 100644 index 0000000000000000000000000000000000000000..6e47105066f6cfc193aee7a47e72b289f5b12a8e --- /dev/null +++ b/database/migrations/2022_06_07_073221_add_acesso_to_avaliadors_trabalhos_table.php @@ -0,0 +1,32 @@ +string('acesso')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('avaliador_trabalho', function (Blueprint $table) { + $table->dropColumn('acesso'); + }); + } +} diff --git a/resources/views/administrador/analisarProposta.blade.php b/resources/views/administrador/analisarProposta.blade.php index f58cf7817bc5c4afc4a09c041488273581762ece..7eb5ebc318498ff1628211676c26994e8ed593bb 100644 --- a/resources/views/administrador/analisarProposta.blade.php +++ b/resources/views/administrador/analisarProposta.blade.php @@ -835,19 +835,28 @@
{{ $trabalho->created_at->format('d/m/Y') }} | @@ -132,6 +137,78 @@
Nome do Projeto | +Data de Criação | +Projeto | +Plano de Trabalho | +Parecer Externo | + +
---|---|---|---|---|
{{ $trabalho->created_at->format('d/m/Y') }} | +
+ {{-- --}}
+
+ |
+
+ @foreach( $trabalho->participantes as $participante)
+ @php
+ if( App\Arquivo::where('participanteId', $participante->id)->first() != null){
+ $planoTrabalho = App\Arquivo::where('participanteId', $participante->id)->first()->nome;
+ }else{
+ $planoTrabalho = null;
+ }
+ @endphp
+ @if ($planoTrabalho != null)
+
+ |
+
+
+
+
+ |
+