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
0fa0a637
Commit
0fa0a637
authored
Jun 03, 2023
by
unknown
Browse files
Criação de funções relacionada a adição de participantes para editais de extensão
parent
7821fa8f
Changes
2
Show whitespace changes
Inline
Side-by-side
app/Http/Controllers/TrabalhoController.php
View file @
0fa0a637
...
@@ -39,6 +39,7 @@ use Illuminate\Validation\Rule;
...
@@ -39,6 +39,7 @@ use Illuminate\Validation\Rule;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
use
App\Http\Requests\StoreTrabalho
;
use
App\Http\Requests\StoreTrabalho
;
use
App\Http\Requests\AdicionarIntegranteRequest
;
use
Illuminate\Support\Facades\Mail
;
use
Illuminate\Support\Facades\Mail
;
use
App\Http\Requests\UpdateTrabalho
;
use
App\Http\Requests\UpdateTrabalho
;
use
Illuminate\Support\Facades\Storage
;
use
Illuminate\Support\Facades\Storage
;
...
@@ -57,6 +58,7 @@ use App\Desligamento;
...
@@ -57,6 +58,7 @@ use App\Desligamento;
use
App\ObjetivoDeDesenvolvimentoSustentavel
;
use
App\ObjetivoDeDesenvolvimentoSustentavel
;
use
App\AvaliacaoRelatorio
;
use
App\AvaliacaoRelatorio
;
use
App\Curso
;
use
App\Curso
;
use
Illuminate\Support\Facades\Date
;
class
TrabalhoController
extends
Controller
class
TrabalhoController
extends
Controller
{
{
...
@@ -1202,6 +1204,77 @@ class TrabalhoController extends Controller
...
@@ -1202,6 +1204,77 @@ class TrabalhoController extends Controller
}
}
public
function
adicionarParticipante
(
AdicionarIntegranteRequest
$request
,
$id
){
$usuario
=
User
::
where
(
'cpf'
,
$request
->
cpf_consulta
)
->
first
();
if
(
!
$this
->
validarQtdParticipantesEdital
(
$id
)){
return
redirect
(
route
(
'trabalho.show'
,
[
'id'
=>
$id
]))
->
with
([
'mensagem'
=>
"Número máximo de integrantes do Edital alcançado, não é possivel inserir."
]);
}
if
(
!
$this
->
validarParticipanteRepetido
(
$usuario
->
id
,
$id
))
{
return
redirect
(
route
(
'trabalho.show'
,
[
'id'
=>
$id
]))
->
with
([
'mensagem'
=>
"Já existe um Integrante com esse CPF."
]);
}
$atributos
=
[
'user_id'
=>
$usuario
->
id
,
'funcao_participante_id'
=>
$request
->
funcao_participante
,
'trabalho_id'
=>
$id
,
'data_entrada'
=>
Date
::
now
()
->
format
(
'Y-m-d H:i:s'
)
];
$rg
=
Participante
::
where
(
'user_id'
,
$atributos
[
'user_id'
])
->
where
(
'rg'
,
'!='
,
null
)
->
latest
()
->
first
();
$data_de_nascimento
=
Participante
::
where
(
'user_id'
,
$atributos
[
'user_id'
])
->
where
(
'data_de_nascimento'
,
'!='
,
null
)
->
latest
()
->
first
();
$curso
=
Participante
::
where
(
'user_id'
,
$atributos
[
'user_id'
])
->
where
(
'curso'
,
'!='
,
null
)
->
latest
()
->
first
();
$linkLattes
=
Participante
::
where
(
'user_id'
,
$atributos
[
'user_id'
])
->
where
(
'linkLattes'
,
'!='
,
null
)
->
latest
()
->
first
();
$curso_id
=
Participante
::
where
(
'user_id'
,
$atributos
[
'user_id'
])
->
where
(
'curso_id'
,
'!='
,
null
)
->
latest
()
->
first
();
$atributo
[
'rg'
]
=
$rg
?
$rg
->
rg
:
null
;
$atributo
[
'data_de_nascimento'
]
=
$data_de_nascimento
?
$data_de_nascimento
->
data_de_nascimento
:
null
;
$atributo
[
'curso'
]
=
$curso
?
$curso
->
curso
:
null
;
$atributo
[
'linkLattes'
]
=
$linkLattes
?
$linkLattes
->
linkLattes
:
null
;
$atributo
[
'curso_id'
]
=
$curso_id
?
$curso_id
->
curso_id
:
null
;
Participante
::
create
(
$atributos
);
return
redirect
(
route
(
'trabalho.show'
,
[
'id'
=>
$id
]));
}
private
function
validarQtdParticipantesEdital
(
$id
)
{
$num_participantes_edital
=
Trabalho
::
where
(
'id'
,
$id
)
->
first
()
->
evento
->
numParticipantes
;
$num_participantes_projeto
=
count
(
Participante
::
where
(
'trabalho_id'
,
$id
)
->
get
());
if
(
$num_participantes_projeto
>=
$num_participantes_edital
){
return
false
;
}
return
true
;
}
private
function
validarParticipanteRepetido
(
$usuario_id
,
$trabalho_id
){
if
(
Participante
::
where
(
'user_id'
,
$usuario_id
)
->
where
(
'trabalho_id'
,
$trabalho_id
)
->
first
())
{
return
false
;
}
return
true
;
}
public
function
buscarUsuario
(
Request
$request
)
{
public
function
buscarUsuario
(
Request
$request
)
{
$usuario
=
User
::
where
(
'cpf'
,
$request
->
cpf_consulta
)
->
first
();
$usuario
=
User
::
where
(
'cpf'
,
$request
->
cpf_consulta
)
->
first
();
$funcao
=
FuncaoParticipantes
::
where
(
'id'
,
$request
->
funcao
)
->
first
();
$funcao
=
FuncaoParticipantes
::
where
(
'id'
,
$request
->
funcao
)
->
first
();
...
...
app/Participante.php
View file @
0fa0a637
...
@@ -12,7 +12,7 @@ class Participante extends Model
...
@@ -12,7 +12,7 @@ class Participante extends Model
protected
$fillable
=
[
'rg'
,
'data_de_nascimento'
,
'curso'
,
'funcao_participante_id'
,
'turno'
,
protected
$fillable
=
[
'rg'
,
'data_de_nascimento'
,
'curso'
,
'funcao_participante_id'
,
'turno'
,
'ordem_prioridade'
,
'periodo_atual'
,
'total_periodos'
,
'media_do_curso'
,
'linkLattes'
,
'ordem_prioridade'
,
'periodo_atual'
,
'total_periodos'
,
'media_do_curso'
,
'linkLattes'
,
'tipoBolsa'
,
'data_entrada'
,
'data_saida'
];
'tipoBolsa'
,
'data_entrada'
,
'data_saida'
,
'user_id'
,
'trabalho_id'
,
'curso_id'
];
public
function
user
(){
public
function
user
(){
return
$this
->
belongsTo
(
'App\User'
);
return
$this
->
belongsTo
(
'App\User'
);
...
...
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