1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace App\Http\Requests;
use App\Evento;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use App\User;
class StoreTrabalho extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::check();
}
protected function prepareForValidation()
{
$func = function ($value) {
return ['cpf' => $value];
};
$this->merge([
'cpfs' => array_map($func, $this->cpf),
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
//dd($this->all());
$evento = Evento::find($this->editalId);
$rules = [];
if ($this->has('marcado')) {
$rules['cpfs.*.cpf'] = ['distinct', 'nullable'];
foreach ($this->get('marcado') as $key => $value) {
if (intval($value) == $key) {
//user
$rules['name.' . $value] = ['required', 'string'];
$rules['email.' . $value] = ['required', 'string'];
$rules['instituicao.' . $value] = ['required', 'string'];
$rules['cpf.' . $value] = ['required', 'string'];
$rules['celular.' . $value] = ['required', 'string'];
if (User::where('cpf', $this->cpf[$value])->first()->tipo == "participante") {
//endereco
$rules['rua.' . $value] = ['required', 'string'];
$rules['numero.' . $value] = ['required', 'string'];
$rules['bairro.' . $value] = ['required', 'string'];
$rules['cidade.' . $value] = ['required', 'string'];
$rules['uf.' . $value] = ['required', 'string'];
$rules['cep.' . $value] = ['required', 'string'];
//participante
$rules['rg.' . $value] = ['required', 'string'];
$rules['data_de_nascimento.' . $value] = ['required', 'string'];
$rules['curso.' . $value] = ['required', 'string'];
//participantes da pesquisa
if ($evento->natureza_id != 3) {
$rules['turno.' . $value] = ['required', 'string'];
$rules['ordem_prioridade.' . $value] = ['required', 'string'];
$rules['periodo_atual.' . $value] = ['required', 'string'];
$rules['total_periodos.' . $value] = ['required', 'string'];
$rules['media_do_curso.' . $value] = ['required', 'string'];
}
if($evento->tipo != "CONTINUO" && ($this->funcaoParticipante[$value] == "Voluntário" || $this->funcaoParticipante[$value] == "Bolsista")){
$rules['anexoPlanoTrabalho.' . $value] = ['required'];
$rules['nomePlanoTrabalho.' . $value] = ['required', 'string'];
}
}
// if($evento->tipo != "PIBEX") {
// $rules['media_do_curso.' . $value] = ['required', 'string'];
// }
}
}
} else if ($evento->tipo != "CONTINUO") {
$rules['anexoPlanoTrabalho'] = ['required'];
$rules['nomePlanoTrabalho'] = ['required', 'string'];
}
if ($this->has('rascunho')) {
$rules = [];
return $rules;
} else {
//anexos
if ($evento->nome_docExtra != null) {
$rules['anexo_docExtra'] = [Rule::requiredIf($evento->obrigatoriedade_docExtra == true), 'file', 'mimes:zip,doc,docx,pdf', 'max:2048'];
}
if ($evento->tipo != "PIBEX" && $evento->tipo != "CONTINUO") {
//dd($this->preenchimentoFormFlag);
$rules['anexoPlanilhaPontuacao'] = ['required'];
$rules['anexoLattesCoordenador'] = ['required', 'mimes:pdf'];
$rules['anexoGrupoPesquisa'] = ['required', 'mimes:pdf'];
$rules['anexoAutorizacaoComiteEtica'] = [Rule::requiredIf($this->autorizacaoFlag == 'sim')];
$rules['justificativaAutorizacaoEtica'] = [Rule::requiredIf($this->autorizacaoFlag == 'nao')];
$rules['pontuacaoPlanilha'] = ['required', 'string'];
$rules['linkGrupoPesquisa'] = ['required', 'string'];
if($evento->tipo == "PIBIC"){
$rules['preenchimentoFormFlag'] = [Rule::in(['sim']), 'required'];
}
$rules['anexo_acao_afirmativa'] = [Rule::requiredIf($this->radioAcoesAfirmativas == 'sim')];
}
$rules['editalId'] = ['required', 'string'];
$rules['marcado.*'] = ['required'];
$rules['titulo'] = ['required', 'string'];
$rules['grande_area_id'] = [Rule::requiredIf($evento->natureza_id != 3), 'string'];
$rules['area_id'] = [Rule::requiredIf($evento->natureza_id != 3), 'string'];
if ($evento->natureza_id == 3) {
$rules['area_tematica_id'] = ['required', 'string'];
$rules['ods'] = ['required'];
}
$rules['linkLattesEstudante'] = ['required', 'string'];
if ($evento->tipo != "CONTINUO") {
$rules['anexoDecisaoCONSU'] = [Rule::requiredIf($evento->consu), 'mimes:pdf'];
$rules['anexoProjeto'] = ['required', 'mimes:pdf'];
} else {
$rules['anexo_SIPAC'] = ['required', 'mimes:pdf'];
}
// dd($rules, $evento);
return $rules;
}
}
public function messages()
{
return [
'titulo.required' => 'O :attribute é obrigatório',
'marcado.*.required' => 'Por favor selcione algum participante, é obrigatório',
'grande_area_id.required' => 'O campo grande área é obrigatório',
'anexoPlanoTrabalho.*.required' => 'O :attribute é obrigatório',
'anexoProjeto.required' => 'O :attribute é obrigatório',
'cpf.*.required' => 'O cpf é obrigatório',
'cpfs.*.cpf.distinct' => 'O integrante com CPF :input não pode ser adicionado mais de uma vez',
'name.*.required' => 'O :attribute é obrigatório',
'email.*.required' => 'O :attribute é obrigatório',
'instituicao.*.required' => 'O :attribute é obrigatório',
'emailParticipante.*.required' => 'O :attribute é obrigatório',
'celular.*.required' => 'O :attribute é obrigatório',
'rua.*.required' => 'O :attribute é obrigatório',
'numero.*.required' => 'O :attribute é obrigatório',
'bairro.*.required' => 'O :attribute é obrigatório',
'cidade.*.required' => 'O :attribute é obrigatório',
'uf.*.required' => 'O :attribute é obrigatório',
'cep.*.required' => 'O :attribute é obrigatório',
'complemento.*.required' => 'O :attribute é obrigatório',
'rg.*.required' => 'O :attribute é obrigatório',
'data_de_nascimento.*.required' => 'O :attribute é obrigatório',
'curso.*.required' => 'O :attribute é obrigatório',
'turno.*.required' => 'O :attribute é obrigatório',
'ordem_prioridade.*.required' => 'O :attribute é obrigatório',
'periodo_atual.*.required' => 'O :attribute é obrigatório',
'total_periodos.*.required' => 'O :attribute é obrigatório',
'media_do_curso.*.required' => 'O :attribute é obrigatório',
'anexoPlanoTrabalho.*.required' => 'O :attribute é obrigatório',
'nomePlanoTrabalho.*.required' => 'O :attribute é obrigatório',
'area_id' => "area id",
'area_tematica_id' => 'area tematica id',
'ods.*' => 'Deve ser selecionada pelo menos uma ODS',
'linkLattesEstudante.*' => "O link do currículo lattes do estudante é obrigatório",
'anexoDecisaoCONSU.*' => 'anexoDecisaoCONSU',
'anexo_SIPAC.*' => 'anexo_SIPAC'
];
}
}