Skip to content

Commit

Permalink
Merge pull request #48 from EscolaDeSaudePublica/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
jeff-doliveira1 authored Nov 16, 2022
2 parents 008cc13 + 9858005 commit d61cd03
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
17 changes: 14 additions & 3 deletions app/DAO/EnsinoPesquisaExtensao/CertificadoDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function getCursoMatrizCurricular($turmaid)
return [
'curso' => $curso,
'modulos' => $modulos,
'oferta' => $ofertaCursoTurma,
];
}

Expand All @@ -147,19 +148,25 @@ public function getInscricoesDaTurma(
$situacaoaluno = 'Aprovado'
) {

$basdocumentTypeCPF = 2;

// sem inscricaoid
if (is_null($inscricaoid)) {

$select = DB::select(
"SELECT DISTINCT
ITG.inscricaoid,
unmaskcpf(DOC.content) as cpf,
PERSON.miolousername,
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)
LEFT JOIN basdocument DOC
ON (PERSON.personid = DOC.personid) and DOC.documenttypeid = $basdocumentTypeCPF
WHERE ITG.ofertaturmaid = :ofertaturmaid
AND acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) = :situacaoaluno
ORDER BY PERSON.name",
Expand All @@ -175,14 +182,18 @@ public function getInscricoesDaTurma(
// com inscricaoid
$select = DB::select(
"SELECT DISTINCT
ITG.inscricaoid,
PERSON.name as nome,
acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) as situacaoaluno
ITG.inscricaoid,
unmaskcpf(DOC.content) as cpf,
PERSON.miolousername,
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)
LEFT JOIN basdocument DOC
ON (PERSON.personid = DOC.personid) and DOC.documenttypeid = $basdocumentTypeCPF
WHERE ITG.ofertaturmaid = :ofertaturmaid
AND ITG.inscricaoid = :inscricaoid
AND acp_obtersituacaopedagogicadainscricao(ITG.inscricaoid) = :situacaoaluno
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public function generateCertificateByStudent($turmaId, $incricaoid)
{
$info = $this->generateCertificate($turmaId, $incricaoid);

$this->certificate_service->generatePDF($info);
return $this->certificate_service->generatePDF($info);
}

public function generateCertificateByClass($turmaId)
{
$info = $this->generateCertificate($turmaId);

$this->certificate_service->generatePDF($info);
return $this->certificate_service->generatePDF($info);
}

private function generateCertificate($turmaId, $incricaoid = null)
Expand All @@ -40,6 +40,7 @@ private function generateCertificate($turmaId, $incricaoid = null)
return [
'curso' => $cursoMatrizCurricular['curso'],
'modulos' => $cursoMatrizCurricular['modulos'],
'oferta' => $cursoMatrizCurricular['oferta'],
'estudantes' => $estudantes
];
}
Expand Down
36 changes: 32 additions & 4 deletions app/Services/EnsinoPesquisaExtensao/CertificateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@ public function generatePDF($info)

$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"]));
$charToFilter = array(';', '+', ',', '\\', '/', ' ');

$course_name = $this->limitString($info["curso"]["curso"], 60);
$class_name = $this->limitString($info['oferta']['descricao_turma'], 40);

$course_name_doc = str_replace(
$charToFilter,
'_',
$course_name . '(' . $class_name . ')'
);

$zip->open("/tmp/mpdf/{$course_name_doc}.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE);

$zip->addEmptyDir($course_name_doc);

foreach ($info["estudantes"] as $student) {
$mpdf = $this->setMPDFSettings();
$pdf_info = $this->mountInfoPDF($student, $info, $period);
$student_name_doc = str_replace($charToFilter, '_', trim($student->nome));

$student_cpf = trim($student->cpf);
$student_name = trim($student->nome);

$student_name_doc = empty($student_cpf)
? str_replace($charToFilter, '_', $student_name)
: str_replace($charToFilter, '_', $student_name . '(' . $student_cpf . ')');

$mpdf->SetImportUse();
$mpdf->SetDocTemplate('/var/www/public/assets/docs/certificate/template.pdf');
Expand All @@ -34,7 +50,7 @@ public function generatePDF($info)

$content = $mpdf->Output('', 'S');

$zip->addFromString("{$student_name_doc}.pdf", $content);
$zip->addFromString("{$course_name_doc}/{$student_name_doc}.pdf", $content);
}

$zip->close();
Expand All @@ -50,6 +66,18 @@ public function generatePDF($info)
exit;
}

private function limitString($string, $length)
{
$start = 0;
$maxLength = $length + strlen('...');

if (strlen(trim($string)) > $maxLength) {
return mb_substr(trim($string), $start, $length) . '...';
}

return mb_substr(trim($string), $start, $length);
}

private function setMPDFSettings()
{
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
Expand Down

0 comments on commit d61cd03

Please sign in to comment.