Unverified Commit 490fc4da authored by Aline Tenório's avatar Aline Tenório Committed by GitHub
Browse files

Merge pull request #26 from lmts-ufape/fix-add-participante

Fix add participante
parents 5da05a73 d3892171
...@@ -437,6 +437,8 @@ class TrabalhoController extends Controller ...@@ -437,6 +437,8 @@ class TrabalhoController extends Controller
foreach ($request->emailParticipante as $key => $value) { foreach ($request->emailParticipante as $key => $value) {
// criando novos participantes que podem ter sido adicionados // criando novos participantes que podem ter sido adicionados
if (!(in_array($request->emailParticipante[$key], $emailParticipantes, false))) { if (!(in_array($request->emailParticipante[$key], $emailParticipantes, false))) {
$userParticipante = User::where('email', $value)->first();
if($userParticipante == null){
$passwordTemporario = Str::random(8); $passwordTemporario = Str::random(8);
Mail::to($value)->send(new EmailParaUsuarioNaoCadastrado(Auth()->user()->name, ' ', 'Participante', $evento->nome, $passwordTemporario)); Mail::to($value)->send(new EmailParaUsuarioNaoCadastrado(Auth()->user()->name, ' ', 'Participante', $evento->nome, $passwordTemporario));
$usuario = User::create([ $usuario = User::create([
...@@ -453,6 +455,21 @@ class TrabalhoController extends Controller ...@@ -453,6 +455,21 @@ class TrabalhoController extends Controller
$participante->funcao_participante_id = $request->funcaoParticipante[$key]; $participante->funcao_participante_id = $request->funcaoParticipante[$key];
$participante->save(); $participante->save();
}else{
$participante = new Participante();
$participante->user_id = $userParticipante->id;
$participante->trabalho_id = $trabalho->id;
$participante->funcao_participante_id = $request->funcaoParticipante[$key];
$participante->save();
$participante->trabalhos()->save($trabalho);
$subject = "Participante de Projeto";
$email = $value;
Mail::to($email)
->send(new SubmissaoTrabalho($userParticipante, $subject));
}
$path = 'trabalhos/' . $request->editalId . '/' . $trabalho->id .'/'; $path = 'trabalhos/' . $request->editalId . '/' . $trabalho->id .'/';
$nome = $request->nomePlanoTrabalho[$key] .".pdf"; $nome = $request->nomePlanoTrabalho[$key] .".pdf";
$file = $request->anexoPlanoTrabalho[$key]; $file = $request->anexoPlanoTrabalho[$key];
...@@ -470,6 +487,8 @@ class TrabalhoController extends Controller ...@@ -470,6 +487,8 @@ class TrabalhoController extends Controller
//atualizando os participantes que já estão no projeto e planos de trabalho se enviados //atualizando os participantes que já estão no projeto e planos de trabalho se enviados
if (in_array($request->emailParticipante[$key], $emailParticipantes, false)) { if (in_array($request->emailParticipante[$key], $emailParticipantes, false)) {
$userParticipante = User::where('email', $value)->first();
if($userParticipante != null){
$user = User::where('email', $request->emailParticipante[$key])->first(); $user = User::where('email', $request->emailParticipante[$key])->first();
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first(); $participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
...@@ -503,12 +522,14 @@ class TrabalhoController extends Controller ...@@ -503,12 +522,14 @@ class TrabalhoController extends Controller
} }
} }
} }
}
// Atualizando possiveis usuários removidos // Atualizando possiveis usuários removidos
$participantesUsersIds = Participante::where('trabalho_id', '=', $trabalho->id)->select('user_id')->get(); $participantesUsersIds = Participante::where('trabalho_id', '=', $trabalho->id)->select('user_id')->get();
$users = User::whereIn('id', $participantesUsersIds)->get(); $users = User::whereIn('id', $participantesUsersIds)->get();
foreach ($users as $user) { foreach ($users as $user) {
//dd($user);
if (!(in_array($user->email, $request->emailParticipante, false))) { if (!(in_array($user->email, $request->emailParticipante, false))) {
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first(); $participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
$arquivo = Arquivo::where('participanteId', $participante->id); $arquivo = Arquivo::where('participanteId', $participante->id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment