Skip to content

Commit

Permalink
Add an accessor for the params class variable on the grid Export class
Browse files Browse the repository at this point in the history
  • Loading branch information
cpkdevries committed Jun 22, 2023
1 parent 4aa1c1d commit f731f01
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/Grid/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class Export implements ExportInterface
{
public const DEFAULT_TEMPLATE = '@APYDataGrid/blocks.html.twig';

private string $title;
private string $title = '';

private string $fileName;

Expand Down Expand Up @@ -57,18 +57,17 @@ abstract class Export implements ExportInterface
private ?string $role;

public function __construct(
string $title,
string $fileName = 'export',
array $params = [],
string $charset = 'UTF-8',
string $title,
string $fileName = 'export',
array $params = [],
string $charset = 'UTF-8',
?string $role = null
)
{
$this->title = $title;
) {
$this->title = $title;
$this->fileName = $fileName;
$this->params = $params;
$this->charset = $charset;
$this->role = $role;
$this->params = $params;
$this->charset = $charset;
$this->role = $role;
}

public function setTwig(Environment $twig): self
Expand Down Expand Up @@ -105,20 +104,20 @@ public function getResponse(): Response
$kernelCharset = $this->kernelCharset;
if ($this->charset != $kernelCharset && function_exists('mb_strlen')) {
$this->content = mb_convert_encoding($this->content, $this->charset, $kernelCharset);
$filesize = mb_strlen($this->content, '8bit');
$filesize = mb_strlen($this->content, '8bit');
} else {
$filesize = strlen($this->content);
$filesize = strlen($this->content);
$this->charset = $kernelCharset;
}

$headers = [
'Content-Description' => 'File Transfer',
'Content-Type' => $this->getMimeType(),
'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()),
'Content-Description' => 'File Transfer',
'Content-Type' => $this->getMimeType(),
'Content-Disposition' => sprintf('attachment; filename="%s"', $this->getBaseName()),
'Content-Transfer-Encoding' => 'binary',
'Cache-Control' => 'must-revalidate',
'Pragma' => 'public',
'Content-Length' => $filesize,
'Cache-Control' => 'must-revalidate',
'Pragma' => 'public',
'Content-Length' => $filesize,
];

$response = new Response($this->content, 200, $headers);
Expand Down Expand Up @@ -157,7 +156,7 @@ protected function getGridData(Grid $grid): array

protected function getRawGridData(Grid $grid): array
{
$result = [];
$result = [];
$this->grid = $grid;

if ($this->grid->isTitleSectionVisible()) {
Expand Down Expand Up @@ -209,7 +208,7 @@ protected function getGridTitles(): array

$titlesClean = array_map([$this, 'cleanHTML'], $matches[0]);

$i = 0;
$i = 0;
$titles = [];

foreach ($this->grid->getColumns() as $column) {
Expand Down Expand Up @@ -244,7 +243,7 @@ protected function getGridRows(): array
foreach ($this->grid->getRows() as $i => $row) {
foreach ($this->grid->getColumns() as $column) {
if ($column->isVisible(true)) {
$cellHTML = $this->getGridCell($column, $row);
$cellHTML = $this->getGridCell($column, $row);
$rows[$i][$column->getId()] = $this->cleanHTML($cellHTML);
}
}
Expand Down Expand Up @@ -278,21 +277,17 @@ protected function getGridCell(Column $column, Row $row): string

$separator = $column->getSeparator();

$block = null;
$block = null;
$return = [];
foreach ($values as $sourceValue) {
$value = $column->renderCell($sourceValue, $row, $this->router);

$id = $this->grid->getId();

if (
($id != ''
&& ($block !== null
if (($id != '' && ($block !== null
|| $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getRenderBlockId() . '_cell')
|| $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getType() . '_cell')
|| $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell')
)
)
|| $this->hasBlock($block = 'grid_' . $id . '_column_' . $column->getParentType() . '_cell')))
|| $this->hasBlock($block = 'grid_' . $id . '_column_id_' . $column->getRenderBlockId() . '_cell')
|| $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getType() . '_cell')
|| $this->hasBlock($block = 'grid_' . $id . '_column_type_' . $column->getParentType() . '_cell')
Expand All @@ -304,7 +299,7 @@ protected function getGridCell(Column $column, Row $row): string
|| $this->hasBlock($block = 'grid_column_type_' . $column->getParentType() . '_cell')) {
$html = $this->renderBlock($block, ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]);
} else {
$html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]);
$html = $this->renderBlock('grid_column_cell', ['grid' => $this->grid, 'column' => $column, 'row' => $row, 'value' => $value, 'sourceValue' => $sourceValue]);
$block = null;
}

Expand Down Expand Up @@ -356,7 +351,7 @@ public function setTemplate(\Twig\TemplateWrapper|string|null $template): self
{
if (is_string($template)) {
if (substr($template, 0, 8) === '__SELF__') {
$this->templates = $this->getTemplatesFromString(substr($template, 8));
$this->templates = $this->getTemplatesFromString(substr($template, 8));
$this->templates[] = $this->twig->load(static::DEFAULT_TEMPLATE);
} else {
$this->templates = $this->getTemplatesFromString($template);
Expand All @@ -377,7 +372,7 @@ protected function getTemplatesFromString(string|TemplateWrapper $theme): array
$template = $this->twig->load($theme);
while ($template instanceof \Twig\TemplateWrapper) {
$templates[] = $template;
$template = $template->getParent([]);
$template = $template->getParent([]);
}

return $templates;
Expand Down Expand Up @@ -507,6 +502,11 @@ public function getParameter(string $name): string
return $this->parameters[$name];
}

public function getParams(): array
{
return $this->params;
}

public function setRole(?string $role): self
{
$this->role = $role;
Expand Down

0 comments on commit f731f01

Please sign in to comment.