title; } protected function getTemplate(): string { return $this->template; } protected function getOptions(TimesheetQuery $query): array { $decimal = false; if (null !== $query->getCurrentUser()) { $decimal = $query->getCurrentUser()->isExportDecimal(); } elseif (null !== $query->getUser()) { $decimal = $query->getUser()->isExportDecimal(); } return ['decimal' => $decimal]; } public function getPdfOptions(): array { return $this->pdfOptions; } public function setPdfOption(string $key, string $value): void { $this->pdfOptions[$key] = $value; } /** * @param ExportableItem[] $exportItems * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ public function render(array $exportItems, TimesheetQuery $query): Response { $filename = new ExportFilename($query); $context = new PdfContext(); $context->setOption('filename', $filename->getFilename()); $summary = $this->calculateSummary($exportItems); // enable basic security measures if (!$this->twig->hasExtension(SandboxExtension::class)) { $this->twig->addExtension(new SandboxExtension(new StrictPolicy())); } $sandbox = $this->twig->getExtension(SandboxExtension::class); $sandbox->enableSandbox(); $content = $this->twig->render($this->getTemplate(), array_merge([ 'entries' => $exportItems, 'query' => $query, 'summaries' => $summary, 'budgets' => $this->calculateProjectBudget($exportItems, $query, $this->projectStatisticService), 'decimal' => false, 'pdfContext' => $context ], $this->getOptions($query))); $sandbox->disableSandbox(); $pdfOptions = array_merge($context->getOptions(), $this->getPdfOptions()); $content = $this->converter->convertToPdf($content, $pdfOptions); return $this->createPdfResponse($content, $context); } /** * @deprecated since 2.40.0 */ public function setTemplate(string $filename): void { $this->template = '@export/' . $filename; } /** * @deprecated since 2.40.0 */ public function setId(string $id): void { $this->id = $id; } /** * @deprecated since 2.40.0 */ public function setTitle(string $title): void { $this->title = $title; } public function getId(): string { return $this->id; } }