Resolve design template

This commit is contained in:
David Bomba 2022-12-23 13:46:52 +11:00
parent 1d28a98a55
commit bce476977b
2 changed files with 64 additions and 0 deletions

View File

@ -12,6 +12,7 @@
namespace App\Services\Pdf; namespace App\Services\Pdf;
use App\Services\Pdf\PdfConfiguration; use App\Services\Pdf\PdfConfiguration;
use App\Utils\HtmlEngine;
class PdfService class PdfService
{ {
@ -20,6 +21,12 @@ class PdfService
public PdfConfiguration $config; public PdfConfiguration $config;
public PdfBuilder $builder;
public PdfDesigner $designer;
public array $html_variables;
public function __construct($invitation) public function __construct($invitation)
{ {
@ -27,6 +34,17 @@ class PdfService
$this->config = (new PdfConfiguration($this))->init(); $this->config = (new PdfConfiguration($this))->init();
$this->html_variables = (new HtmlEngine($invitation))->generateLabelsAndValues();
$this->builder = (new PdfBuilder($this));
$this->designer = (new PdfDesigner($this))->build();
}
public function build()
{
$this->builder->build();
} }
public function getPdf() public function getPdf()
@ -39,4 +57,30 @@ class PdfService
} }
// $state = [
// 'template' => $template->elements([
// 'client' => $this->client,
// 'entity' => $this->entity,
// 'pdf_variables' => (array) $this->company->settings->pdf_variables,
// '$product' => $design->design->product,
// 'variables' => $variables,
// ]),
// 'variables' => $variables,
// 'options' => [
// 'all_pages_header' => $this->entity->client->getSetting('all_pages_header'),
// 'all_pages_footer' => $this->entity->client->getSetting('all_pages_footer'),
// ],
// 'process_markdown' => $this->entity->client->company->markdown_enabled,
// ];
// $maker = new PdfMakerService($state);
// $maker
// ->design($template)
// ->build();
} }

View File

@ -65,4 +65,24 @@ class PdfServiceTest extends TestCase
$this->assertEquals(2, $service->config->design->id); $this->assertEquals(2, $service->config->design->id);
} }
public function testHtmlIsArray()
{
$invitation = $this->invoice->invitations->first();
$service = new PdfService($invitation);
$this->assertIsArray($service->html_variables);
}
public function testTemplateResolution()
{
$invitation = $this->invoice->invitations->first();
$service = new PdfService($invitation);
$this->assertIsString($service->designer->template);
}
} }