Commit 5f9ce747 authored by alinetenorio's avatar alinetenorio
Browse files

adicionar participante ao editar projeto

parent 5af65369
......@@ -441,6 +441,8 @@ class TrabalhoController extends Controller
foreach ($request->emailParticipante as $key => $value) {
// criando novos participantes que podem ter sido adicionados
if (!(in_array($request->emailParticipante[$key], $emailParticipantes, false))) {
$userParticipante = User::where('email', $value)->first();
if($userParticipante == null){
$passwordTemporario = Str::random(8);
Mail::to($value)->send(new EmailParaUsuarioNaoCadastrado(Auth()->user()->name, ' ', 'Participante', $evento->nome, $passwordTemporario));
$usuario = User::create([
......@@ -457,6 +459,21 @@ class TrabalhoController extends Controller
$participante->funcao_participante_id = $request->funcaoParticipante[$key];
$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 .'/';
$nome = $request->nomePlanoTrabalho[$key] .".pdf";
$file = $request->anexoPlanoTrabalho[$key];
......@@ -474,6 +491,9 @@ class TrabalhoController extends Controller
//atualizando os participantes que já estão no projeto e planos de trabalho se enviados
if (in_array($request->emailParticipante[$key], $emailParticipantes, false)) {
$userParticipante = User::where('email', $value)->first();
//dd($userParticipante);
if($userParticipante != null){
$user = User::where('email', $request->emailParticipante[$key])->first();
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
......@@ -507,12 +527,14 @@ class TrabalhoController extends Controller
}
}
}
}
// Atualizando possiveis usuários removidos
$participantesUsersIds = Participante::where('trabalho_id', '=', $trabalho->id)->select('user_id')->get();
$users = User::whereIn('id', $participantesUsersIds)->get();
foreach ($users as $user) {
//dd($user);
if (!(in_array($user->email, $request->emailParticipante, false))) {
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
$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