diff --git a/lib/Alchemy/Phrasea/Controller/Admin/DataboxController.php b/lib/Alchemy/Phrasea/Controller/Admin/DataboxController.php index e1c2b4ee21..f1e8e5e6a0 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/DataboxController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/DataboxController.php @@ -15,7 +15,6 @@ use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\Authenticator; use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Model\Manipulator\TaskManipulator; -use Alchemy\Phrasea\Out\Module\PDFCgu; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -245,10 +244,6 @@ class DataboxController extends Controller foreach ($request->request->get('TOU', []) as $loc => $terms) { $databox->update_cgus($loc, $terms, !!$request->request->get('valid', false)); } - - // generate cgu for the databox - $pdfCgu = new PDFCgu($this->app, $databox_id); - $pdfCgu->save(); } catch (\Exception $e) { return $this->app->redirectPath('admin_database_display_cgus', [ 'databox_id' => $databox_id, diff --git a/lib/Alchemy/Phrasea/Out/Module/PDFCgu.php b/lib/Alchemy/Phrasea/Out/Module/PDFCgu.php index 8680725d21..e12f8e17c8 100644 --- a/lib/Alchemy/Phrasea/Out/Module/PDFCgu.php +++ b/lib/Alchemy/Phrasea/Out/Module/PDFCgu.php @@ -3,18 +3,21 @@ namespace Alchemy\Phrasea\Out\Module; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Out\Tool\PhraseaPDF; class PDFCgu extends PDF { private $databoxId; private $htmlContent = ''; + private $recordIds; - public function __construct(Application $app, $databoxId) + public function __construct(Application $app, $databoxId, array $recordIds) { parent::__construct($app); $this->app = $app; $this->databoxId = $databoxId; + $this->recordIds = $recordIds; $this->printCgu(); } @@ -73,9 +76,114 @@ class PDFCgu extends PDF $this->pdf->AddPage(); $this->pdf->writeHTML($this->htmlContent); + // add thumbnail in cgu + $this->print_thumbnail_list(); } } + private function print_thumbnail_list() + { + $this->pdf->AddPage(); + + $oldMargins = $this->pdf->getMargins(); + + $lmargin = $oldMargins['left']; + $rmargin = $oldMargins['right']; + + $this->pdf->SetLeftMargin($lmargin + 55); + + $ndoc = 0; + foreach ($this->recordIds as $recordId) { + /* @var \record_adapter $rec */ + $rec = new \record_adapter($this->app, $this->databoxId, $recordId); + $subdef = $rec->get_subdef('thumbnail'); + + $fimg = $subdef->getRealPath(); + + $wimg = $himg = 50; + // 1px = 3.77952 mm + $finalWidth = round($subdef->get_width() / 3.779528, 2); + $finalHeight = round($subdef->get_height() / 3.779528, 2); + $aspectH = $finalWidth/$finalHeight; + $aspectW = $finalHeight/$finalWidth; + + if ($finalWidth > 0 && $finalHeight > 0) { + if ($finalWidth > $finalHeight && $finalWidth > $wimg) { + $finalWidth = $wimg; + $finalHeight = $wimg * $aspectW; + } else if ($finalHeight > $finalWidth && $finalHeight > $himg) { + $finalHeight = $himg; + $finalWidth = $himg * $aspectH; + } else if ($finalHeight == $finalWidth & $finalWidth > $wimg) { + $finalHeight = $wimg; + $finalWidth = $himg; + } + } + + if ($this->pdf->GetY() > $this->pdf->getPageHeight() - (6 + $finalHeight + 20)) + $this->pdf->AddPage(); + + $title = "record : " . $rec->get_title(); + + $y = $this->pdf->GetY(); + + $t = \phrasea::bas_labels($rec->getBaseId(), $this->app); + $this->pdf->SetFont(PhraseaPDF::FONT, '', 10); + $this->pdf->SetFillColor(220, 220, 220); + $this->pdf->SetLeftMargin($lmargin); + $this->pdf->SetRightMargin($rmargin); + $this->pdf->SetX($lmargin); + $this->pdf->SetY($y); + + $this->pdf->out = false; + $this->pdf->MultiCell(140, 4, $title, "LTR", "L", 1); + $y2 = $this->pdf->GetY(); + $h = $y2 - $y; + $this->pdf->out = true; + $this->pdf->SetX($lmargin); + $this->pdf->SetY($y); + $this->pdf->Cell(0, $h, "", "LTR", 1, "R", 1); + $this->pdf->SetX($lmargin); + $this->pdf->SetY($y); + $this->pdf->Cell(0, 4, $t, "", 1, "R"); + $this->pdf->SetX($lmargin); + $this->pdf->SetY($y); + $this->pdf->MultiCell(140, 4, $title, "", "L"); + $this->pdf->SetX($lmargin); + $this->pdf->SetY($y = $y2); + + $this->pdf->SetLeftMargin($lmargin + 55); + $this->pdf->SetY($y + 2); + + if ($fimg) { + $y = $this->pdf->GetY(); + $this->pdf->Image($fimg, $lmargin, $y, $finalWidth, $finalHeight); + $this->pdf->SetY($y + 3); + } + + $nf = 0; + $this->pdf->SetX($lmargin + 55); + $p0 = $this->pdf->PageNo(); + $y0 = $this->pdf->GetY(); + foreach ($rec->get_caption()->get_fields() as $field) { + /* @var $field \caption_field */ + + $this->pdf->SetFont(PhraseaPDF::FONT, 'B', 12); + $this->pdf->Write(5, $field->get_name() . " : "); + + $this->pdf->SetFont(PhraseaPDF::FONT, '', 12); + $this->pdf->Write(5, $field->get_serialized_values()); + + $this->pdf->Write(6, "\n"); + $nf++; + } + if ($this->pdf->PageNo() == $p0 && ($this->pdf->GetY() - $y0) < $finalHeight) + $this->pdf->SetY($y0 + $finalHeight); + $ndoc++; + } + $this->pdf->SetLeftMargin($lmargin); + } + private function isContentEmpty() { return (trim($this->htmlContent) === '') ? true : false; diff --git a/lib/classes/set/export.php b/lib/classes/set/export.php index e039e80ef7..55abec8b03 100644 --- a/lib/classes/set/export.php +++ b/lib/classes/set/export.php @@ -694,6 +694,12 @@ class set_export extends set_abstract $toRemove = []; $archiveFiles = []; $databoxIds = []; + $recordIdsPerDatabox = []; + + // group recordId per databoxId + foreach ($files as $file) { + $recordIdsPerDatabox[$file['databox_id']][] = $file['record_id']; + } foreach ($files as $record) { if (isset($record["subdefs"])) { @@ -717,24 +723,21 @@ class set_export extends set_abstract // add also the databox cgu in the zip $databoxIds[] = $record['databox_id']; - // if empty do not add pdf in zip + // if cgu content empty, do not add pdf in zip if (!PDFCgu::isDataboxCguEmpty($app, $record['databox_id'])) { - $databoxCguPath = PDFCgu::getDataboxCguPath($app, $record['databox_id']); + try { + $pdfCgu = new PDFCgu($app, $record['databox_id'], $recordIdsPerDatabox[$record['databox_id']]); + $pdfCgu->save(); - if (!is_file($databoxCguPath)) { - try { - $pdfCgu = new PDFCgu($app, $record['databox_id']); - $pdfCgu->save(); + $databoxCguPath = PDFCgu::getDataboxCguPath($app, $record['databox_id']); + } catch (\Exception $e) { + $app['logger']->error("Exception occurred when generating cgu pdf : " . $e->getMessage()); - $databoxCguPath = PDFCgu::getDataboxCguPath($app, $record['databox_id']); - } catch (\Exception $e) { - $app['logger']->error("Exception occurred when generating cgu pdf : " . $e->getMessage()); - - continue; - } + continue; } $archiveFiles[$app['unicode']->remove_diacritics($obj["folder"].PDFCgu::getDataboxCguPdfName($app, $record['databox_id']))] = $databoxCguPath; + $toRemove[] = $databoxCguPath; } } }