Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Walter Felipe
submeta
Commits
490fc4da
Unverified
Commit
490fc4da
authored
Jun 12, 2020
by
Aline Tenório
Committed by
GitHub
Jun 12, 2020
Browse files
Merge pull request #26 from lmts-ufape/fix-add-participante
Fix add participante
parents
5da05a73
d3892171
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/TrabalhoController.php
View file @
490fc4da
...
...
@@ -428,30 +428,47 @@ class TrabalhoController extends Controller
// criando novos participantes que podem ter sido adicionados
$participantesUsersIds
=
Participante
::
where
(
'trabalho_id'
,
'='
,
$trabalho
->
id
)
->
select
(
'user_id'
)
->
get
();
$users
=
User
::
whereIn
(
'id'
,
$participantesUsersIds
)
->
get
();
$users
=
User
::
whereIn
(
'id'
,
$participantesUsersIds
)
->
get
();
$emailParticipantes
=
[];
foreach
(
$users
as
$user
)
{
array_push
(
$emailParticipantes
,
$user
->
email
);
}
foreach
(
$request
->
emailParticipante
as
$key
=>
$value
)
{
// criando novos participantes que podem ter sido adicionados
foreach
(
$request
->
emailParticipante
as
$key
=>
$value
)
{
// criando novos participantes que podem ter sido adicionados
if
(
!
(
in_array
(
$request
->
emailParticipante
[
$key
],
$emailParticipantes
,
false
)))
{
$passwordTemporario
=
Str
::
random
(
8
);
Mail
::
to
(
$value
)
->
send
(
new
EmailParaUsuarioNaoCadastrado
(
Auth
()
->
user
()
->
name
,
' '
,
'Participante'
,
$evento
->
nome
,
$passwordTemporario
));
$usuario
=
User
::
create
([
'email'
=>
$value
,
'password'
=>
bcrypt
(
$passwordTemporario
),
'usuarioTemp'
=>
true
,
'name'
=>
$request
->
nomeParticipante
[
$key
],
'tipo'
=>
'participante'
,
]);
$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
([
'email'
=>
$value
,
'password'
=>
bcrypt
(
$passwordTemporario
),
'usuarioTemp'
=>
true
,
'name'
=>
$request
->
nomeParticipante
[
$key
],
'tipo'
=>
'participante'
,
]);
$participante
=
new
Participante
();
$participante
->
user_id
=
$usuario
->
id
;
$participante
->
trabalho_id
=
$trabalho
->
id
;
$participante
->
funcao_participante_id
=
$request
->
funcaoParticipante
[
$key
];
$participante
->
save
();
$participante
=
new
Participante
();
$participante
->
user_id
=
$usuario
->
id
;
$participante
->
trabalho_id
=
$trabalho
->
id
;
$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"
;
...
...
@@ -470,35 +487,38 @@ 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
))
{
$user
=
User
::
where
(
'email'
,
$request
->
emailParticipante
[
$key
])
->
first
();
$participante
=
Participante
::
where
([[
'user_id'
,
'='
,
$user
->
id
],
[
'trabalho_id'
,
'='
,
$trabalho
->
id
]])
->
first
();
$userParticipante
=
User
::
where
(
'email'
,
$value
)
->
first
();
if
(
$userParticipante
!=
null
){
$user
=
User
::
where
(
'email'
,
$request
->
emailParticipante
[
$key
])
->
first
();
$participante
=
Participante
::
where
([[
'user_id'
,
'='
,
$user
->
id
],
[
'trabalho_id'
,
'='
,
$trabalho
->
id
]])
->
first
();
$user
->
name
=
$request
->
nomeParticipante
[
$key
];
$user
->
update
();
$participante
->
funcao_participante_id
=
$request
->
funcaoParticipante
[
$key
];
$participante
->
update
();
//atualizando planos de trabalho
if
(
array_key_exists
(
$key
,
$request
->
anexoPlanoTrabalho
))
{
if
(
!
(
is_null
(
$request
->
anexoPlanoTrabalho
[
$key
])))
{
$arquivo
=
Arquivo
::
where
(
'participanteId'
,
$participante
->
id
)
->
first
();
Storage
::
delete
(
$arquivo
->
nome
);
$arquivo
->
delete
();
$path
=
'trabalhos/'
.
$request
->
editalId
.
'/'
.
$trabalho
->
id
.
'/'
;
$nome
=
$request
->
nomePlanoTrabalho
[
$key
]
.
".pdf"
;
$file
=
$request
->
anexoPlanoTrabalho
[
$key
];
Storage
::
putFileAs
(
$path
,
$file
,
$nome
);
$arquivo
=
new
Arquivo
();
$arquivo
->
titulo
=
$request
->
nomePlanoTrabalho
[
$key
];
$arquivo
->
nome
=
$path
.
$nome
;
$arquivo
->
trabalhoId
=
$trabalho
->
id
;
$arquivo
->
data
=
$mytime
;
$arquivo
->
participanteId
=
$participante
->
id
;
$arquivo
->
versaoFinal
=
true
;
$arquivo
->
save
();
$user
->
name
=
$request
->
nomeParticipante
[
$key
];
$user
->
update
();
$participante
->
funcao_participante_id
=
$request
->
funcaoParticipante
[
$key
];
$participante
->
update
();
//atualizando planos de trabalho
if
(
array_key_exists
(
$key
,
$request
->
anexoPlanoTrabalho
))
{
if
(
!
(
is_null
(
$request
->
anexoPlanoTrabalho
[
$key
])))
{
$arquivo
=
Arquivo
::
where
(
'participanteId'
,
$participante
->
id
)
->
first
();
Storage
::
delete
(
$arquivo
->
nome
);
$arquivo
->
delete
();
$path
=
'trabalhos/'
.
$request
->
editalId
.
'/'
.
$trabalho
->
id
.
'/'
;
$nome
=
$request
->
nomePlanoTrabalho
[
$key
]
.
".pdf"
;
$file
=
$request
->
anexoPlanoTrabalho
[
$key
];
Storage
::
putFileAs
(
$path
,
$file
,
$nome
);
$arquivo
=
new
Arquivo
();
$arquivo
->
titulo
=
$request
->
nomePlanoTrabalho
[
$key
];
$arquivo
->
nome
=
$path
.
$nome
;
$arquivo
->
trabalhoId
=
$trabalho
->
id
;
$arquivo
->
data
=
$mytime
;
$arquivo
->
participanteId
=
$participante
->
id
;
$arquivo
->
versaoFinal
=
true
;
$arquivo
->
save
();
}
}
}
}
...
...
@@ -509,6 +529,7 @@ class TrabalhoController extends Controller
$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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment