Commit e8ed04d2 authored by alinetenorio's avatar alinetenorio
Browse files

finalizando validação de planilha

parent 46fef0e3
...@@ -31,6 +31,7 @@ use Illuminate\Support\Facades\Log; ...@@ -31,6 +31,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Mail\SubmissaoTrabalho; use App\Mail\SubmissaoTrabalho;
use App\Mail\EventoCriado; use App\Mail\EventoCriado;
use Illuminate\Support\Facades\Validator;
class TrabalhoController extends Controller class TrabalhoController extends Controller
{ {
...@@ -125,23 +126,13 @@ class TrabalhoController extends Controller ...@@ -125,23 +126,13 @@ class TrabalhoController extends Controller
'anexoComiteEtica' => [($request->anexoComitePreenchido!=='sim'&&$request->anexoJustificativaPreenchido!=='sim'?'required_without:justificativaAutorizacaoEtica':''), 'file', 'mimes:pdf', 'max:2000000'], 'anexoComiteEtica' => [($request->anexoComitePreenchido!=='sim'&&$request->anexoJustificativaPreenchido!=='sim'?'required_without:justificativaAutorizacaoEtica':''), 'file', 'mimes:pdf', 'max:2000000'],
'justificativaAutorizacaoEtica' => [($request->anexoJustificativaPreenchido!=='sim'&&$request->anexoComitePreenchido!=='sim'?'required_without:anexoComiteEtica':''), 'file', 'mimes:pdf', 'max:2000000'], 'justificativaAutorizacaoEtica' => [($request->anexoJustificativaPreenchido!=='sim'&&$request->anexoComitePreenchido!=='sim'?'required_without:anexoComiteEtica':''), 'file', 'mimes:pdf', 'max:2000000'],
'anexoLattesCoordenador' => [($request->anexoLattesPreenchido!=='sim'?'required': ''), 'file', 'mimes:pdf', 'max:2000000'], 'anexoLattesCoordenador' => [($request->anexoLattesPreenchido!=='sim'?'required': ''), 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanilha' => [($request->anexoPlanilhaPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf,xls', 'max:2000000'], 'anexoPlanilha' => [($request->anexoPlanilhaPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf,xls,xlsx', 'max:2000000'],
'anexoPlanoTrabalho.*' => ['nullable', 'file', 'mimes:pdf', 'max:2000000'], 'anexoPlanoTrabalho.*' => ['nullable', 'file', 'mimes:pdf', 'max:2000000'],
]); ]);
//dd($request->all());
// $extensions = array("xls","xlsx");
// if(isset($request->anexoPlanilha )){
// $result = array($request->file('anexoPlanilha')->getClientOriginalExtension());
// if(in_array($result[0], $extensions)){
// }else{
// $validatedData = $request->validate([
// 'anexoPlanilha' => [($request->anexoPlanilhaPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf,xls,xlsx', 'max:2000000']
// ]);
// }
// }
if(gettype($this->validarAnexosRascunho($request, $trabalho)) != 'integer'){
return $this->validarAnexosRascunho($request, $trabalho);
}
//$trabalho = Trabalho::create([ //$trabalho = Trabalho::create([
$trabalho['titulo'] = $request->nomeProjeto; $trabalho['titulo'] = $request->nomeProjeto;
...@@ -182,10 +173,13 @@ class TrabalhoController extends Controller ...@@ -182,10 +173,13 @@ class TrabalhoController extends Controller
'nomePlanoTrabalho.*' => ['nullable', 'string'], 'nomePlanoTrabalho.*' => ['nullable', 'string'],
'anexoProjeto' => [($request->anexoProjetoPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf', 'max:2000000'], 'anexoProjeto' => [($request->anexoProjetoPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf', 'max:2000000'],
'anexoLattesCoordenador' => [($request->anexoLattesPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf', 'max:2000000'], 'anexoLattesCoordenador' => [($request->anexoLattesPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanilha' => [($request->anexoPlanilhaPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf,xls', 'max:2000000'], 'anexoPlanilha' => [($request->anexoPlanilhaPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf,xls,xlsx', 'max:2000000'],
'anexoPlanoTrabalho.*' => ['nullable', 'file', 'mimes:pdf', 'max:2000000'], 'anexoPlanoTrabalho.*' => ['nullable', 'file', 'mimes:pdf', 'max:2000000'],
]); ]);
if(gettype($this->validarAnexosRascunho($request, $trabalho)) != 'integer'){
return $this->validarAnexosRascunho($request, $trabalho);
}
//$trabalho = Trabalho::create([ //$trabalho = Trabalho::create([
$trabalho['titulo'] = $request->nomeProjeto; $trabalho['titulo'] = $request->nomeProjeto;
$trabalho['coordenador_id'] = $coordenador->id; $trabalho['coordenador_id'] = $coordenador->id;
...@@ -316,7 +310,7 @@ class TrabalhoController extends Controller ...@@ -316,7 +310,7 @@ class TrabalhoController extends Controller
//---Dados do Projeto //---Dados do Projeto
$trabalho = Trabalho::where('proponente_id', $proponente->id)->where('evento_id',$request->editalId)->where('status', 'Rascunho') $trabalho = Trabalho::where('proponente_id', $proponente->id)->where('evento_id',$request->editalId)->where('status', 'Rascunho')
->orderByDesc('updated_at')->first(); ->orderByDesc('updated_at')->first();
// dd($trabalho); //dd($trabalho);
if($trabalho == null){ if($trabalho == null){
$trabalho = new Trabalho(); $trabalho = new Trabalho();
$trabalho->proponente_id = $proponente->id; $trabalho->proponente_id = $proponente->id;
...@@ -330,7 +324,7 @@ class TrabalhoController extends Controller ...@@ -330,7 +324,7 @@ class TrabalhoController extends Controller
$trabalho->fill( $trabalho->fill(
array_fill_keys($stringKeys, "") + array_fill_keys($intKeys, 1) array_fill_keys($stringKeys, "") + array_fill_keys($intKeys, 1)
)->save(); )->save();
// dd($trabalho); //dd($trabalho);
} }
if(!(is_null($request->nomeProjeto)) ) { if(!(is_null($request->nomeProjeto)) ) {
...@@ -379,11 +373,24 @@ class TrabalhoController extends Controller ...@@ -379,11 +373,24 @@ class TrabalhoController extends Controller
//---Anexos planos de trabalho //---Anexos planos de trabalho
//dd($trabalho);
return $trabalho; return $trabalho;
} }
public function validarAnexosRascunho(Request $request, $trabalho){
//dd($trabalho->getAttributes());
$validator = Validator::make($trabalho->getAttributes(),[
'anexoPlanilhaPontuacao' => $request->anexoPlanilha==null?['planilha']:[],
]);
if ($validator->fails()) {
dd('asdf');
return back()->withErrors($validator)->withInput();
}
return 1;
}
public function armazenarAnexosFinais($request, $pasta, $trabalho, $evento){ public function armazenarAnexosFinais($request, $pasta, $trabalho, $evento){
// Anexo Projeto // Anexo Projeto
......
...@@ -27,5 +27,6 @@ class AppServiceProvider extends ServiceProvider ...@@ -27,5 +27,6 @@ class AppServiceProvider extends ServiceProvider
Validator::extend('cpf', '\App\Utils\CpfValidation@validate'); Validator::extend('cpf', '\App\Utils\CpfValidation@validate');
Validator::extend('link_lattes', '\App\Utils\LattesValidation@validate', 'Link inválido'); Validator::extend('link_lattes', '\App\Utils\LattesValidation@validate', 'Link inválido');
Validator::extend('link_grupo', '\App\Utils\GrupoPesquisaValidation@validate', 'Link inválido'); Validator::extend('link_grupo', '\App\Utils\GrupoPesquisaValidation@validate', 'Link inválido');
Validator::extend('planilha', '\App\Utils\ExtensaoValidation@validate', 'Extensão do arquivo é inválida');
} }
} }
<?php namespace App\Utils;
class ExtensaoValidation
{
public function validate($attribute, $value, $parameters, $validator)
{
$extensions = array("xls","xlsx", "pdf");
$result = pathinfo($value)['extension'];
if(!in_array($result, $extensions)){
return false;
}
return true;
}
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Enviar Projeto</h5> <h5 class="card-title">Enviar Projeto</h5>
<p class="card-text"> <p class="card-text">
<form method="POST" action="{{route('trabalho.store')}}" enctype="multipart/form-data"> <form method="POST" name="formTrabalho" action="{{route('trabalho.store')}}" enctype="multipart/form-data">
@csrf @csrf
<input type="hidden" name="editalId" value="{{$edital->id}}"> <input type="hidden" name="editalId" value="{{$edital->id}}">
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
'nomeAnexo' => 'anexoProjeto' ])}}">Arquivo atual</a> 'nomeAnexo' => 'anexoProjeto' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoProjetoPreenchido" name="anexoProjetoPreenchido" <input type="hidden" id="anexoProjetoPreenchido" name="anexoProjetoPreenchido"
@if( isset($rascunho) && $rascunho->anexoProjeto != "") value="sim" @else value="old('anexoProjetoPreenchido')" @endif > @if( isset($rascunho) && $rascunho->anexoProjeto != "") value="sim" @else value="{{old('anexoProjetoPreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
<div class="custom-file"> <div class="custom-file">
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
'nomeAnexo' => 'anexoLattesCoordenador' ])}}">Arquivo atual</a> 'nomeAnexo' => 'anexoLattesCoordenador' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoLattesPreenchido" name="anexoLattesPreenchido" <input type="hidden" id="anexoLattesPreenchido" name="anexoLattesPreenchido"
@if( isset($rascunho) && $rascunho->anexoLattesCoordenador != "") value="sim" @else value="old('anexoLattesPreenchido')" @endif > @if( isset($rascunho) && $rascunho->anexoLattesCoordenador != "") value="sim" @else value="{{old('anexoLattesPreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
'nomeAnexo' => 'anexoAutorizacaoComiteEtica' ])}}">Arquivo atual</a> 'nomeAnexo' => 'anexoAutorizacaoComiteEtica' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoComitePreenchido" name="anexoComitePreenchido" <input type="hidden" id="anexoComitePreenchido" name="anexoComitePreenchido"
@if( isset($rascunho) && $rascunho->anexoAutorizacaoComiteEtica != "") value="sim" @else value="old('anexoComitePreenchido')" @endif > @if( isset($rascunho) && $rascunho->anexoAutorizacaoComiteEtica != "") value="sim" @else value="{{old('anexoComitePreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
'nomeAnexo' => 'anexoPlanilhaPontuacao' ])}}">Arquivo atual</a> 'nomeAnexo' => 'anexoPlanilhaPontuacao' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoPlanilhaPreenchido" name="anexoPlanilhaPreenchido" <input type="hidden" id="anexoPlanilhaPreenchido" name="anexoPlanilhaPreenchido"
@if( isset($rascunho) && $rascunho->anexoPlanilhaPontuacao != "") value="sim" @else value="old('anexoPlanilhaPreenchido')" @endif > @if( isset($rascunho) && $rascunho->anexoPlanilhaPontuacao != "") value="sim" @else value="{{old('anexoPlanilhaPreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
<div class="custom-file"> <div class="custom-file">
...@@ -234,6 +234,11 @@ ...@@ -234,6 +234,11 @@
<strong>{{ $message }}</strong> <strong>{{ $message }}</strong>
</span> </span>
@enderror @enderror
@error('anexoPlanilhaPontuacao')
<span class="invalid-feedback" role="alert" style="overflow: visible; display:block">
<strong>{{ $message }}</strong>
</span>
@enderror
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
...@@ -243,7 +248,7 @@ ...@@ -243,7 +248,7 @@
'nomeAnexo' => 'justificativaAutorizacaoEtica' ])}}">Arquivo atual</a> 'nomeAnexo' => 'justificativaAutorizacaoEtica' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoJustificativaPreenchido" name="anexoJustificativaPreenchido" <input type="hidden" id="anexoJustificativaPreenchido" name="anexoJustificativaPreenchido"
@if( isset($rascunho) && $rascunho->justificativaAutorizacaoEtica != "") value="sim" @else value="old('anexoJustificativaPreenchido')" @endif > @if( isset($rascunho) && $rascunho->justificativaAutorizacaoEtica != "") value="sim" @else value="{{old('anexoJustificativaPreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
...@@ -268,7 +273,7 @@ ...@@ -268,7 +273,7 @@
'nomeAnexo' => 'anexoDecisaoCONSU' ])}}">Arquivo atual</a> 'nomeAnexo' => 'anexoDecisaoCONSU' ])}}">Arquivo atual</a>
@endif @endif
<input type="hidden" id="anexoConsuPreenchido" name="anexoConsuPreenchido" <input type="hidden" id="anexoConsuPreenchido" name="anexoConsuPreenchido"
@if( isset($rascunho) && $rascunho->anexoDecisaoCONSU != "") value="sim" @else value="old('anexoConsuPreenchido')" @endif > @if( isset($rascunho) && $rascunho->anexoDecisaoCONSU != "") value="sim" @else value="{{old('anexoConsuPreenchido')}}" @endif >
<div class="input-group"> <div class="input-group">
<div class="custom-file"> <div class="custom-file">
...@@ -770,6 +775,11 @@ ...@@ -770,6 +775,11 @@
anexoPlanilhaPreenchido.value = "sim"; anexoPlanilhaPreenchido.value = "sim";
} }
} }
function removerPlanilha(){
console.log('a');
$('#anexoPlanilhaPreenchido').val("");
}
window.onload = areas(); window.onload = areas();
window.onload = habilitarBotao(); window.onload = habilitarBotao();
</script> </script>
......
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