File Controller, Booking Organisation, import Draft, old arrangements

This commit is contained in:
Kevin Adametz 2025-09-04 10:35:45 +02:00
parent 4eb83def39
commit 8fd1f4d451
289 changed files with 36649 additions and 10877 deletions

View file

@ -1,4 +1,5 @@
<?php
namespace App\Libraries;
//use FPDI in myMerge v2
@ -10,10 +11,10 @@ class MyPDFMerger
private $_files; //['form.pdf'] ["1,2,4, 5-19"]
private $_fpdi;
public function __construct()
{
/* if(!class_exists("FPDF")) {
/* if(!class_exists("FPDF")) {
require_once(__DIR__.'/fpdf/fpdf.php');
}
if(!class_exists("FPDI")) {
@ -39,12 +40,14 @@ class MyPDFMerger
public function myMerge($outputmode = 'browser', $outputpath = 'newfile.pdf', $theme = false)
{
if (!isset($this->_files) || !is_array($this->_files)): throw new \exception("No PDFs to merge."); endif;
//$theme = false;
if (!isset($this->_files) || !is_array($this->_files)): throw new \exception("No PDFs to merge.");
endif;
$fpdi = new \setasign\Fpdi\Fpdi();
$first = 1;
//
//merger operations
foreach ($this->_files as $file) {
$filename = $file[0];
@ -60,30 +63,29 @@ class MyPDFMerger
$template = $fpdi->importPage($i);
$size = $fpdi->getTemplateSize($template);
$orientation = ($size['height'] > $size['width']) ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['width'], $size['height']));
if($theme){
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/'.$theme.'-'.$first.'.pdf');
if($first == 1){
if ($theme) {
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/' . $theme . '-' . $first . '.pdf');
if ($first == 1) {
$first = 2;
}
$backId = $fpdi->importPage(1);
$fpdi->useTemplate($backId);
}
$fpdi->useTemplate($template);
}
} else {
foreach ($filepages as $page) {
$count = $fpdi->setSourceFile($filename);
if (!$template = $fpdi->importPage($page)): throw new \exception("Could not load page '$page' in PDF '$filename'. Check that the page exists."); endif;
if (!$template = $fpdi->importPage($page)): throw new \exception("Could not load page '$page' in PDF '$filename'. Check that the page exists.");
endif;
$size = $fpdi->getTemplateSize($template);
$orientation = ($size['h'] > $size['w']) ? 'P' : 'L';
$fpdi->AddPage($orientation, array($size['w'], $size['h']));
if($theme){
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/'.$theme.'-'.$first.'.pdf');
if($first == 1){
if ($theme) {
$fpdi->setSourceFile(__DIR__ . '/../../public/pdf/' . $theme . '-' . $first . '.pdf');
if ($first == 1) {
$first = 2;
}
$backId = $fpdi->importPage(1);
@ -110,11 +112,9 @@ class MyPDFMerger
return false;
}
}
}
/**
/**
* FPDI uses single characters for specifying the output location. Change our more descriptive string into proper format.
* @param $mode
* @return Character
@ -140,7 +140,7 @@ class MyPDFMerger
}
}
/**
/**
* Takes our provided pages in the form of 1,3,4,16-50 and creates an array of all pages
* @param $pages
* @return array
@ -160,11 +160,13 @@ class MyPDFMerger
$y = $ind[1]; //end page
if ($x > $y): throw new \exception("Starting page, '$x' is greater than ending page '$y'.");
return false; endif;
return false;
endif;
//add middle pages
while ($x <= $y): $newpages[] = (int)$x;
$x++; endwhile;
$x++;
endwhile;
} else {
$newpages[] = (int)$ind[0];
}