Commit 19cb5cc3 authored by alinetenorio's avatar alinetenorio
Browse files

armazenando anexos do projeto temporariamente

parent 737ab459
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class AnexosTemp extends Model
{
//
}
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\AnexosTemp;
use App\Trabalho;
use App\Coautor;
use App\Evento;
......@@ -22,6 +23,7 @@ use App\Avaliador;
use Carbon\Carbon;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use App\Mail\EmailParaUsuarioNaoCadastrado;
use Illuminate\Support\Facades\Mail;
......@@ -82,7 +84,10 @@ class TrabalhoController extends Controller
return redirect()->route('home');
}
}
//--Salvando os anexos da submissão temporariamente
$this->armazenarAnexosTemp($request, Auth::user()->id);
//O anexo de Decisão do CONSU dependo do tipo de edital
if( $evento->tipo == 'PIBIC' || $evento->tipo == 'PIBIC-EM'){
......@@ -99,12 +104,13 @@ class TrabalhoController extends Controller
'emailParticipante.*' => ['required', 'string'],
'funcaoParticipante.*' => ['required', 'string'],
'nomePlanoTrabalho.*' => ['required', 'string'],
'anexoProjeto' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
//--Verificando se anexos já foram submetidos
'anexoProjeto' => [($request->anexoProjetoPreenchido!=='sim'?'required':''), 'file', 'mimes:pdf', 'max:2000000'],
'anexoCONSU' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'botao' => ['required'],
'anexoComiteEtica' => ['required_without:justificativaAutorizacaoEtica', 'file', 'mimes:pdf', 'max:2000000'],
'justificativaAutorizacaoEtica' => ['required_without:anexoComiteEtica', 'file', 'mimes:pdf', 'max:2000000'],
'anexoLatterCoordenador' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoLattesCoordenador' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanilha' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanoTrabalho.*' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
]);
......@@ -126,10 +132,10 @@ class TrabalhoController extends Controller
'proponente_id' => $proponente->id,
//Anexos
'anexoCONSU' => $request->anexoCONSU,
'anexoProjeto' => $request->anexoProjeto,
'anexoProjeto' => $request->anexoProjeto != null ? $request->anexoProjeto : "",
'anexoAutorizacaoComiteEtica' => $request->anexoComiteEtica,
'justificativaAutorizacaoEtica' => $request->justificativaAutorizacaoEtica,
'anexoLattesCoordenador' => $request->anexoLatterCoordenador,
'anexoLattesCoordenador' => $request->anexoLattesCoordenador,
'anexoPlanilhaPontuacao' => $request->anexoPlanilha,
]);
//dd($trabalho);
......@@ -149,7 +155,7 @@ class TrabalhoController extends Controller
'funcaoParticipante.*' => ['required', 'string'],
'nomePlanoTrabalho.*' => ['required', 'string'],
'anexoProjeto' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoLatterCoordenador' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoLattesCoordenador' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanilha' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
'anexoPlanoTrabalho.*' => ['required', 'file', 'mimes:pdf', 'max:2000000'],
]);
......@@ -172,7 +178,7 @@ class TrabalhoController extends Controller
'anexoProjeto' => $request->anexoProjeto,
'anexoAutorizacaoComiteEtica' => $request->anexoComiteEtica,
'justificativaAutorizacaoEtica' => $request->justificativaAutorizacaoEtica,
'anexoLattesCoordenador' => $request->anexoLatterCoordenador,
'anexoLattesCoordenador' => $request->anexoLattesCoordenador,
'anexoPlanilhaPontuacao' => $request->anexoPlanilha,
]);
......@@ -248,11 +254,21 @@ class TrabalhoController extends Controller
$trabalho->justificativaAutorizacaoEtica = Storage::putFileAs($pasta, $request->justificativaAutorizacaoEtica, "Justificativa.pdf");
}
$trabalho->anexoProjeto = Storage::putFileAs($pasta, $request->anexoProjeto, "Projeto.pdf");
$trabalho->anexoLattesCoordenador = Storage::putFileAs($pasta, $request->anexoLatterCoordenador, "Latter_Coordenador.pdf");
if(!isset($request->anexoProjeto) && $request->anexoProjetoPreenchido == 'sim'){
$anexosTemp = AnexosTemp::where('eventoId', $request->editalId)->where('proponenteId', Auth::user()->id)
->orderByDesc('updated_at')->first();
Storage::move($anexosTemp->anexoProjeto, $pasta . '/Projeto.pdf');
$trabalho->anexoProjeto = $pasta . '/Projeto.pdf';
}else{
$trabalho->anexoProjeto = Storage::putFileAs($pasta, $request->anexoProjeto, "Projeto.pdf");
}
$trabalho->anexoLattesCoordenador = Storage::putFileAs($pasta, $request->anexoLattesCoordenador, "Latter_Coordenador.pdf");
$trabalho->anexoPlanilhaPontuacao = Storage::putFileAs($pasta, $request->anexoPlanilha, "Planilha.pdf");
$trabalho->update();
//Deletando arquivos temporários
Storage::deleteDirectory('anexosTemp/' . $request->editalId . '/' . Auth::user()->id);
//dd($trabalho);
$subject = "Submissão de Trabalho";
......@@ -263,6 +279,54 @@ class TrabalhoController extends Controller
return redirect()->route('evento.visualizar',['id'=>$request->editalId]);
}
//Armazena temporariamente anexos da submissão, no banco de dados e no storage
public function armazenarAnexosTemp(Request $request, $proponenteId){
//---Anexos do Projeto
$anexosTemp = AnexosTemp::where('eventoId', $request->editalId)->where('proponenteId', $proponenteId)
->orderByDesc('updated_at')->first();
if($anexosTemp == null){
$anexosTemp = new AnexosTemp();
$jaExiste = false;
}else{
$jaExiste = true;
}
$pasta = 'anexosTemp/' . $request->editalId . '/' . $proponenteId;
if(!(is_null($request->anexoCONSU)) ) {
$anexosTemp->anexoDecisaoCONSU = Storage::putFileAs($pasta, $request->anexoCONSU, "CONSU.pdf");
}
if (!(is_null($request->anexoComiteEtica))) {
$anexosTemp->anexoAutorizacaoComiteEtica = Storage::putFileAs($pasta, $request->anexoComiteEtica, "Comite_de_etica.pdf");
}
if (!(is_null($request->justificativaAutorizacaoEtica))) {
$anexosTemp->justificativaAutorizacaoEtica = Storage::putFileAs($pasta, $request->justificativaAutorizacaoEtica, "Justificativa.pdf");
}
if (!(is_null($request->anexoProjeto))) {
$anexosTemp->anexoProjeto = Storage::putFileAs($pasta, $request->anexoProjeto, "Projeto.pdf");
}
if (!(is_null($request->anexoLattesCoordenador))) {
$anexosTemp->anexoLattesCoordenador = Storage::putFileAs($pasta, $request->anexoLattesCoordenador, "Latter_Coordenador.pdf");
}
if (!(is_null($request->anexoPlanilha))) {
$anexosTemp->anexoPlanilhaPontuacao = Storage::putFileAs($pasta, $request->anexoPlanilha, "Planilha.pdf");
}
$anexosTemp->eventoId = $request->editalId;
$anexosTemp->proponenteId = $proponenteId;
if(!$jaExiste){
$anexosTemp->save();
}else{
$anexosTemp->update();
}
//---Anexos planos de trabalho
}
/**
* Display the specified resource.
*
......@@ -414,9 +478,9 @@ class TrabalhoController extends Controller
$trabalho->anexoAutorizacaoComiteEtica = Storage::putFileAs($pasta, $request->anexoComiteEtica, "Comite_de_etica.pdf");
}
if (!(is_null($request->anexoLatterCoordenador))) {
if (!(is_null($request->anexoLattesCoordenador))) {
Storage::delete($trabalho->anexoLattesCoordenador);
$trabalho->anexoLattesCoordenador = Storage::putFileAs($pasta, $request->anexoLatterCoordenador, "Latter_Coordenador.pdf");
$trabalho->anexoLattesCoordenador = Storage::putFileAs($pasta, $request->anexoLattesCoordenador, "Latter_Coordenador.pdf");
}
if (!(is_null($request->anexoPlanilha))) {
......@@ -753,4 +817,13 @@ class TrabalhoController extends Controller
$projeto = Trabalho::find($id);
return Storage::download($projeto->justificativaAutorizacaoEtica);
}
public function baixarAnexoTemp($eventoId, $nomeAnexo) {
$proponenteId = Auth::user()->id;
$anexosTemp = AnexosTemp::where('eventoId', $eventoId)->where('proponenteId', $proponenteId)
->orderByDesc('updated_at')->first();
return Storage::download($anexosTemp->$nomeAnexo);
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnexosTempsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('anexos_temps', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->string('anexoProjeto')->nullable();
$table->string('anexoDecisaoCONSU')->nullable();
$table->string('anexoPlanilhaPontuacao')->nullable();
$table->string('anexoLattesCoordenador')->nullable();
$table->string('anexoAutorizacaoComiteEtica')->nullable();
$table->string('justificativaAutorizacaoEtica')->nullable();
$table->integer('eventoId');
$table->integer('proponenteId');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('anexos_temps');
}
}
......@@ -132,11 +132,15 @@
{{-- Arquivo --}}
<div class="col-sm-6">
<label for="anexoProjeto" class="col-form-label">{{ __('Anexo Projeto*:') }}</label>
@if(old('anexoProjetoPreenchido') != null)
<a id="anexoProjetoTemp" href="{{ route('baixar.anexo.temp', ['eventoId' => $edital->id,
'nomeAnexo' => 'anexoProjeto' ])}}">Arquivo atual</a>
@endif
<input type="hidden" id="anexoProjetoPreenchido" name="anexoProjetoPreenchido" value="{{ old('anexoProjetoPreenchido') }}" >
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input @error('anexoProjeto') is-invalid @enderror" id="anexoProjeto" aria-describedby="inputGroupFileAddon01" name="anexoProjeto">
<input type="file" class="custom-file-input @error('anexoProjeto') is-invalid @enderror" id="anexoProjeto" aria-describedby="inputGroupFileAddon01" name="anexoProjeto" onchange="exibirAnexoTemp(this)">
<label class="custom-file-label" id="custom-file-label" for="anexoProjeto">O arquivo deve ser no formato PDF de até 2mb.</label>
</div>
</div>
......@@ -148,16 +152,16 @@
</div>
<div class="col-sm-6">
<label for="anexoLatterCoordenador" class="col-form-label">{{ __('Anexo do Lattes do Coordenador*:') }}</label>
<label for="anexoLattesCoordenador" class="col-form-label">{{ __('Anexo do Lattes do Coordenador*:') }}</label>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input @error('anexoLatterCoordenador') is-invalid @enderror" id="inputGroupFile01" aria-describedby="anexoLatterCoordenador" name="anexoLatterCoordenador">
<input type="file" class="custom-file-input @error('anexoLattesCoordenador') is-invalid @enderror" id="inputGroupFile01" aria-describedby="anexoLattesCoordenador" name="anexoLattesCoordenador">
<label class="custom-file-label" id="custom-file-label" for="inputGroupFile01">O arquivo deve ser no formato PDF de até 2mb.</label>
</div>
</div>
@error('anexoLatterCoordenador')
@error('anexoLattesCoordenador')
<span class="invalid-feedback" role="alert" style="overflow: visible; display:block">
<strong>{{ $message }}</strong>
</span>
......@@ -627,6 +631,13 @@
})
}
function exibirAnexoTemp(file){
console.log(file.id);
if(file.id === "anexoProjeto"){
var anexoProjetoPreenchido = document.getElementById('anexoProjetoPreenchido');
anexoProjetoPreenchido.value = "sim";
}
}
window.onload = areas();
</script>
@endsection
\ No newline at end of file
......@@ -120,6 +120,7 @@ Route::group(['middleware' => ['isTemp', 'auth', 'verified']], function(){
Route::get('/baixar/anexo-lattes/{id}', 'TrabalhoController@baixarAnexoLattes' )->name('baixar.anexo.lattes');
Route::get('/baixar/anexo-planilha/{id}','TrabalhoController@baixarAnexoPlanilha' )->name('baixar.anexo.planilha');
Route::get('/baixar/plano-de-trabalho/{id}', 'ArquivoController@baixarPlano' )->name('baixar.plano');
Route::get('/baixar/anexo-temp/{eventoId}/{nomeAnexo}', 'TrabalhoController@baixarAnexoTemp' )->name('baixar.anexo.temp');
});
Route::prefix('usuarios')->name('admin.')->group(function(){
......
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