Skip to content

Commit

Permalink
Generiranje pdf prek konzole
Browse files Browse the repository at this point in the history
  • Loading branch information
malamalca committed Jun 6, 2023
1 parent 8aa716f commit 365d0e4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Command/IzracunProjekta.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public function run($projectId = null)
(new IzracunCone())->run($projectId);
(new IzracunStavbe())->run($projectId);
(new IzracunTSS())->run($projectId);
(new PdfIzkaz())->run($projectId);
}
}
54 changes: 54 additions & 0 deletions src/Command/PdfIzkaz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

namespace App\Command;

use App\Core\App;
use App\Core\Command;
use App\Core\Configure;
use App\Core\Pdf;
use App\Core\View;

class PdfIzkaz extends Command
{
/**
* Command run routine
*
* @param string|null $projectId Project id.
* @return void
*/
public function run($projectId = null)
{
parent::run();

$view = new View([], ['layout' => 'pdf']);
$view->set('splosniPodatki', App::loadProjectData($projectId, 'splosniPodatki'));
$view->set('okolje', App::loadProjectCalculation($projectId, 'okolje'));
$view->set('stavba', App::loadProjectCalculation($projectId, 'stavba'));
$view->set('cone', App::loadProjectCalculation($projectId, 'cone'));
$view->set('tKons', App::loadProjectCalculation($projectId, 'konstrukcije' . DS . 'transparentne'));
$view->set('ntKons', App::loadProjectCalculation($projectId, 'konstrukcije' . DS . 'netransparentne'));
$view->set('sistemiOgrevanja', App::loadProjectCalculation($projectId, 'TSS' . DS . 'ogrevanje'));
$view->set('sistemiRazsvetljave', App::loadProjectCalculation($projectId, 'TSS' . DS . 'razsvetljava'));
$view->set('sistemiPrezracevanja', App::loadProjectCalculation($projectId, 'TSS' . DS . 'prezracevanje'));

$tssFolder = App::getProjectFolder($projectId, 'izracuni') . 'TSS' . DS;
$view->set('sistemi', array_filter((array)scandir($tssFolder), fn($d) => is_file($tssFolder . $d)));

$splosniPodatki = $view->render('Izkazi', 'splosniPodatki');
$podrocjeGf = $view->render('Izkazi', 'podrocjeGf');
$podrocjeSnes = $view->render('Izkazi', 'podrocjeSNES');

$pdf = new Pdf(Configure::read('Pdf', []));
$pdf->newPage((string)$splosniPodatki);
$pdf->newPage((string)$podrocjeGf);
$pdf->newPage((string)$podrocjeSnes);

$pdfFolder = App::getProjectFolder($projectId, 'pdf');
if (!is_dir($pdfFolder)) {
mkdir($pdfFolder, 0777, true);
}

$pdf->saveAs($pdfFolder . 'izkaz.pdf');
}
}
6 changes: 4 additions & 2 deletions src/Controller/IzkaziController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use App\Core\App;
use App\Core\Configure;
use App\Core\Pdf;
use App\Core\View;

class IzkaziController
{
Expand Down Expand Up @@ -63,7 +65,7 @@ public function podrocjeSNES($projectId)
*/
public function pdf($projectId)
{
$view = new \App\Core\View([], ['layout' => 'pdf']);
$view = new View([], ['layout' => 'pdf']);
$view->set('splosniPodatki', App::loadProjectData($projectId, 'splosniPodatki'));
$view->set('okolje', App::loadProjectCalculation($projectId, 'okolje'));
$view->set('stavba', App::loadProjectCalculation($projectId, 'stavba'));
Expand All @@ -81,7 +83,7 @@ public function pdf($projectId)
$podrocjeGf = $view->render('Izkazi', 'podrocjeGf');
$podrocjeSnes = $view->render('Izkazi', 'podrocjeSNES');

$pdf = new \App\Core\TCPDFEngine(Configure::read('Pdf', []));
$pdf = new Pdf(Configure::read('Pdf', []));
$pdf->newPage((string)$splosniPodatki);
$pdf->newPage((string)$podrocjeGf);
$pdf->newPage((string)$podrocjeSnes);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/TCPDFEngine.php → src/Core/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace App\Core;

class TCPDFEngine extends \TCPDF
class Pdf extends \TCPDF
{
private array $_options = [];

Expand Down

0 comments on commit 365d0e4

Please sign in to comment.