-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from EscolaDeSaudePublica/develop
Gerar Certificados
- Loading branch information
Showing
42 changed files
with
607 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?php | ||
|
||
namespace App\DAO\EnsinoPesquisaExtensao; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
|
||
class CertificadoDAO | ||
{ | ||
|
||
/** | ||
* Pega informações referentes a OfertaCurso e OfertaTurma | ||
* | ||
* @param integer $turmaid | ||
* @return array | ||
*/ | ||
public function getOfertaCursoTurma($turmaid) | ||
{ | ||
$select = DB::select( | ||
"SELECT | ||
OT.habilitada, OT.codigo, OT.ofertaturmaid, OT.ofertacursoid, OT.descricao as descricao_turma, OT.minimoalunos, OT.maximoalunos, OT.datainicialoferta, OT.datafinaloferta, OT.datainicialaulas, OT.datafinalaulas, OT.datainicialinscricao, OT.datafinalinscricao, OT.datainicialmatricula, OT.datafinalmatricula, OT.gradehorarioid, OT.situacao as situacao_turma, OT.centerid, OT.localid, | ||
OFC.ocorrenciacursoid, OFC.descricao as descricao_ofertacurso, OFC.situacao as situacao_ofertacurso, | ||
OC.situacao as situacao_ocorrenciacurso, OC.cursoid, OC.turnid | ||
FROM acpofertaturma OT | ||
INNER JOIN acpofertacurso OFC | ||
ON OT.ofertacursoid = OFC.ofertacursoid | ||
INNER JOIN acpocorrenciacurso OC | ||
ON OFC.ocorrenciacursoid = OC.ocorrenciacursoid | ||
WHERE OT.ofertaturmaid = :turmaid", | ||
['turmaid' => $turmaid] | ||
); | ||
|
||
$result = []; | ||
|
||
if (count($select)) { | ||
|
||
foreach ($select[0] as $key => $value) { | ||
$result[$key] = $value; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Unifica consultas e exibe unidades didáticas do curso via turmaid | ||
* | ||
* @param integer $turmaid | ||
* @return array | ||
*/ | ||
public function getCursoMatrizCurricular($turmaid) | ||
{ | ||
$ofertaCursoTurma = $this->getOfertaCursoTurma($turmaid); | ||
$cursoid = $ofertaCursoTurma['cursoid']; | ||
|
||
$select = DB::select( | ||
"SELECT | ||
C.nome AS nome_curso, | ||
C.datainicio, C.datafim, | ||
MC.descricao AS descricao_matriz, | ||
MCG.matrizcurriculargrupoid AS id_modulo, | ||
MCG.descricao AS descricao_modulo, | ||
CC.codigo cod_unidadedidatica, | ||
CC.nome AS nome_unidadedidatica, | ||
CCD.cargahorariapresencial, | ||
CCD.cargahorariaextraclasse, | ||
CCD.cargahoraria | ||
FROM acpcurso C | ||
INNER JOIN acpmatrizcurricular MC | ||
ON C.cursoid = MC.cursoid | ||
INNER JOIN acpmatrizcurriculargrupo MCG | ||
ON MC.matrizcurricularid = MCG.matrizcurricularid | ||
INNER JOIN acpcomponentecurricularmatriz CCM | ||
ON MCG.matrizcurriculargrupoid = CCM.matrizcurriculargrupoid | ||
INNER JOIN acpcomponentecurricular CC | ||
ON CCM.componentecurricularid = CC.componentecurricularid | ||
INNER JOIN acpcomponentecurriculardisciplina CCD | ||
ON CC.componentecurricularid = CCD.componentecurricularid | ||
WHERE C.cursoid = :cursoid | ||
ORDER BY MCG.ordem, CC.codigo, CC.nome", | ||
['cursoid' => $cursoid] | ||
); | ||
|
||
$curso = []; | ||
$modulos = []; | ||
|
||
if (count($select)) { | ||
|
||
$cargaHorariaCurso = 0; | ||
|
||
foreach ($select as $item) { | ||
|
||
if (!array_key_exists($item->id_modulo, $modulos)) { | ||
|
||
$modulos[$item->id_modulo] = [ | ||
'id_modulo' => $item->id_modulo, | ||
'descricao_modulo' => $item->descricao_modulo, | ||
'carga_horaria_modulo' => 0, | ||
'unidadedidatica' => [], | ||
]; | ||
} | ||
|
||
$modulos[$item->id_modulo]['unidadedidatica'][] = [ | ||
'cod_unidadedidatica' => $item->cod_unidadedidatica, | ||
'nome_unidadedidatica' => $item->nome_unidadedidatica, | ||
'cargahoraria_presencial' => $item->cargahorariapresencial, | ||
'cargahoraria_extraclasse' => $item->cargahorariaextraclasse, | ||
]; | ||
|
||
$modulos[$item->id_modulo]['carga_horaria_modulo'] += $item->cargahoraria; | ||
|
||
$cargaHorariaCurso += $item->cargahoraria; | ||
} | ||
|
||
$curso = [ | ||
'id_curso' => $cursoid, | ||
'curso' => $select[0]->nome_curso, | ||
'descricao_matriz' => $select[0]->descricao_matriz, | ||
'datainicial' => $ofertaCursoTurma['datainicialoferta'], | ||
'datafinal' => $ofertaCursoTurma['datafinaloferta'], | ||
'cargahoraria_curso' => $cargaHorariaCurso | ||
]; | ||
} | ||
|
||
return [ | ||
'curso' => $curso, | ||
'modulos' => $modulos, | ||
]; | ||
} | ||
|
||
/** | ||
* Pegar a lista de alunos inscritos na turma | ||
* | ||
* @param integer $ofertaturmaid | ||
* @param integer $inscricaoid | ||
* @param string $situacaoaluno 'Aprovado' | 'Reprovado' | 'Cancelado' | 'Pendente' | 'Matriculado' | ||
* @return array | ||
*/ | ||
public function getInscricoesDaTurma( | ||
$ofertaturmaid, | ||
$inscricaoid = null, | ||
$situacaoaluno = 'Aprovado' | ||
) { | ||
|
||
// sem inscricaoid | ||
if (is_null($inscricaoid)) { | ||
|
||
$select = DB::select( | ||
"SELECT DISTINCT | ||
ITG.inscricaoid, | ||
PERSON.name as nome, | ||
acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) as situacaoaluno | ||
FROM acpinscricaoturmagrupo ITG | ||
LEFT JOIN acpmatricula MAT | ||
ON (ITG.inscricaoturmagrupoid = MAT.inscricaoturmagrupoid) | ||
LEFT JOIN ONLY basperson PERSON | ||
ON (MAT.personid = PERSON.personid) | ||
WHERE ITG.ofertaturmaid = :ofertaturmaid | ||
AND acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) = :situacaoaluno | ||
ORDER BY PERSON.name", | ||
[ | ||
'ofertaturmaid' => $ofertaturmaid, | ||
'situacaoaluno' => $situacaoaluno, | ||
] | ||
); | ||
|
||
return $select; | ||
} | ||
|
||
// com inscricaoid | ||
$select = DB::select( | ||
"SELECT DISTINCT | ||
ITG.inscricaoid, | ||
PERSON.name as nome, | ||
acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) as situacaoaluno | ||
FROM acpinscricaoturmagrupo ITG | ||
LEFT JOIN acpmatricula MAT | ||
ON (ITG.inscricaoturmagrupoid = MAT.inscricaoturmagrupoid) | ||
LEFT JOIN ONLY basperson PERSON | ||
ON (MAT.personid = PERSON.personid) | ||
WHERE ITG.ofertaturmaid = :ofertaturmaid | ||
AND ITG.inscricaoid = :inscricaoid | ||
AND acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) = :situacaoaluno | ||
ORDER BY PERSON.name", | ||
[ | ||
'ofertaturmaid' => $ofertaturmaid, | ||
'inscricaoid' => $inscricaoid, | ||
'situacaoaluno' => $situacaoaluno, | ||
] | ||
); | ||
|
||
return $select; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/Http/Controllers/EnsinoPesquisaExtensao/CertificateController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\EnsinoPesquisaExtensao; | ||
|
||
use App\DAO\EnsinoPesquisaExtensao\CertificadoDAO; | ||
use App\Http\Controllers\Controller; | ||
use App\Services\EnsinoPesquisaExtensao\CertificateService; | ||
|
||
class CertificateController extends Controller | ||
{ | ||
private $certificate_service; | ||
|
||
function __construct() | ||
{ | ||
$this->certificate_service = new CertificateService(); | ||
} | ||
|
||
public function generateCertificateByStudent($turmaId, $incricaoid) | ||
{ | ||
$info = $this->generateCertificate($turmaId, $incricaoid); | ||
|
||
$this->certificate_service->generatePDF($info); | ||
} | ||
|
||
public function generateCertificateByClass($turmaId) | ||
{ | ||
$info = $this->generateCertificate($turmaId); | ||
|
||
$this->certificate_service->generatePDF($info); | ||
} | ||
|
||
private function generateCertificate($turmaId, $incricaoid = null) | ||
{ | ||
$certificadoDao = new CertificadoDAO(); | ||
$estudantes = $certificadoDao->getInscricoesDaTurma($turmaId, $incricaoid); | ||
$cursoMatrizCurricular = $certificadoDao->getCursoMatrizCurricular( | ||
$turmaId | ||
); | ||
|
||
return [ | ||
'curso' => $cursoMatrizCurricular['curso'], | ||
'modulos' => $cursoMatrizCurricular['modulos'], | ||
'estudantes' => $estudantes | ||
]; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
app/Services/EnsinoPesquisaExtensao/CertificateService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace App\Services\EnsinoPesquisaExtensao; | ||
|
||
use Carbon\Carbon; | ||
use DateTime; | ||
use ZipArchive; | ||
|
||
class CertificateService | ||
{ | ||
public function generatePDF($info) | ||
{ | ||
$zip = new ZipArchive(); | ||
$initial_date = new DateTime($info["curso"]["datainicial"]); | ||
$final_date = new DateTime($info["curso"]["datafinal"]); | ||
|
||
$period = "{$initial_date->format('d/m/Y')} a {$final_date->format('d/m/Y')}"; | ||
$curriculum_matrix_info = $this->mountCurriculumMatrixInfo($info, $period); | ||
$charToFilter = array('+', '-', ',', '\\', '/', ' '); | ||
$course_name_doc = str_replace($charToFilter, '_', trim($info["curso"]["curso"])); | ||
|
||
$zip->open("/tmp/mpdf/{$course_name_doc}.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE); | ||
|
||
foreach ($info["estudantes"] as $student) { | ||
$mpdf = $this->setMPDFSettings(); | ||
$pdf_info = $this->mountInfoPDF($student, $info, $period); | ||
$student_name_doc = str_replace($charToFilter, '_', trim($student->nome)); | ||
|
||
$mpdf->SetImportUse(); | ||
$mpdf->SetDocTemplate('/var/www/public/assets/docs/certificate/template.pdf'); | ||
$mpdf->WriteHTML($this->PDFInfo($pdf_info)); | ||
$mpdf->AddPage('P'); | ||
$mpdf->WriteHTML($this->renderCurriculumMatrix($curriculum_matrix_info)); | ||
|
||
$content = $mpdf->Output('', 'S'); | ||
|
||
$zip->addFromString("{$student_name_doc}.pdf", $content); | ||
} | ||
|
||
$zip->close(); | ||
|
||
header('Content-Description: File Transfer'); | ||
header('Content-Type: application/octet-stream'); | ||
header('Content-Disposition: attachment; filename="' . basename('/tmp/mpdf/' . $course_name_doc . '.zip') . '"'); | ||
header('Expires: 0'); | ||
header('Cache-Control: must-revalidate'); | ||
header('Pragma: public'); | ||
readfile('/tmp/mpdf/' . $course_name_doc . '.zip'); | ||
|
||
exit; | ||
} | ||
|
||
private function setMPDFSettings() | ||
{ | ||
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); | ||
$fontDirs = $defaultConfig['fontDir']; | ||
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); | ||
$fontData = $defaultFontConfig['fontdata']; | ||
|
||
$mpdf = new \Mpdf\Mpdf([ | ||
'tempDir' => '/tmp/mpdf', | ||
'mode' => 'utf-8', | ||
'format' => [210, 297], | ||
'orientation' => 'L', | ||
'margin_top' => 0, | ||
'fontDir' => array_merge($fontDirs, [ | ||
'/var/www/public/assets/fonts/archivo', | ||
'/var/www/public/assets/fonts/open-sans' | ||
]), | ||
'fontdata' => $fontData + [ | ||
'archivo' => [ | ||
'R' => 'Archivo-Regular.ttf' | ||
], | ||
'open-sans' => [ | ||
'R' => 'OpenSans-Regular.ttf' | ||
] | ||
] | ||
]); | ||
|
||
return $mpdf; | ||
} | ||
|
||
private function mountInfoPDF($student, $info, $period) | ||
{ | ||
$today_date = Carbon::now('America/Fortaleza')->locale('pt-BR')->isoFormat('DD \d\e MMMM \d\e YYYY'); | ||
|
||
$pdf_info = [ | ||
'student_name' => ucwords(mb_strtolower($student->nome)), | ||
'course_name' => ucwords(mb_strtolower($info["curso"]["curso"])), | ||
'course_period' => $period, | ||
'course_workload' => $info["curso"]["cargahoraria_curso"], | ||
'today_date' => $today_date | ||
]; | ||
|
||
return $pdf_info; | ||
} | ||
|
||
private function mountCurriculumMatrixInfo($info, $period) | ||
{ | ||
$curriculum_matrix_info = [ | ||
'course_name' => $info["curso"]["curso"], | ||
'matrix_name' => $info["curso"]["descricao_matriz"], | ||
'course_period' => $period, | ||
'modules' => $info["modulos"], | ||
'course_workload' => $info["curso"]["cargahoraria_curso"] | ||
]; | ||
|
||
return $curriculum_matrix_info; | ||
} | ||
|
||
private function PDFInfo($pdf_info) | ||
{ | ||
return view('certificate.info', $pdf_info); | ||
} | ||
|
||
private function renderCurriculumMatrix($curriculum_matrix_info) | ||
{ | ||
return view('certificate.curriculum-matrix', $curriculum_matrix_info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.