1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00
invoiceninja/app/Services/Pdf/PdfDesigner.php

81 lines
2.1 KiB
PHP
Raw Normal View History

2022-12-23 03:58:08 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Pdf;
class PdfDesigner
{
2024-01-14 05:05:00 +01:00
public const BOLD = 'bold';
public const BUSINESS = 'business';
public const CLEAN = 'clean';
public const CREATIVE = 'creative';
public const ELEGANT = 'elegant';
public const HIPSTER = 'hipster';
public const MODERN = 'modern';
public const PLAIN = 'plain';
public const PLAYFUL = 'playful';
public const CUSTOM = 'custom';
public const CALM = 'calm';
public const DELIVERY_NOTE = 'delivery_note';
public const STATEMENT = 'statement';
public const PURCHASE_ORDER = 'purchase_order';
2022-12-23 03:58:08 +01:00
public string $template;
2023-02-21 08:39:07 +01:00
public function __construct(public PdfService $service)
2022-12-23 03:58:08 +01:00
{
}
2024-01-14 05:05:00 +01:00
public function build(): self
2022-12-23 03:58:08 +01:00
{
/*If the design is custom*/
2023-02-21 08:39:07 +01:00
if ($this->service->config->design->is_custom) {
2022-12-23 03:58:08 +01:00
$this->template = $this->composeFromPartials(json_decode(json_encode($this->service->config->design->design), true));
2023-02-21 08:39:07 +01:00
} else {
$this->template = file_get_contents(config('ninja.designs.base_path') . strtolower($this->service->config->design->name) . '.html');
2022-12-23 03:58:08 +01:00
}
return $this;
}
public function buildFromPartials(array $partials): self
{
$this->template = $this->composeFromPartials($partials);
return $this;
}
2022-12-23 03:58:08 +01:00
/**
* If the user has implemented a custom design, then we need to rebuild the design at this point
*/
2022-12-28 11:28:58 +01:00
/**
2023-02-21 08:39:07 +01:00
* Returns the custom HTML design as
2022-12-28 11:28:58 +01:00
* a string
* @param array $partials
2022-12-28 11:28:58 +01:00
* @return string
*/
2024-01-14 05:05:00 +01:00
private function composeFromPartials(array $partials): string
2022-12-23 03:58:08 +01:00
{
$html = '';
$html .= $partials['includes'];
$html .= $partials['header'];
$html .= $partials['body'];
$html .= $partials['footer'];
return $html;
}
2023-02-21 08:39:07 +01:00
}