Skip to content

Commit

Permalink
Export vlastních polí pro NSJ (#966)
Browse files Browse the repository at this point in the history
* skip leaders

* custom inputs export

* rebase fix
  • Loading branch information
jan-stanek committed Apr 12, 2023
1 parent ab240b2 commit 71ac4bf
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions app/Services/ExcelExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,36 @@ public function exportNsjOthers($users, string $filename): ExcelResponse
$sheet->getColumnDimensionByColumn($column)->setAutoSize(false);
$sheet->getColumnDimensionByColumn($column++)->setWidth(15);

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
switch ($customInput->getType()) {
case CustomInput::TEXT:
case CustomInput::SELECT:
case CustomInput::MULTISELECT:
case CustomInput::DATETIME:
$width = 30;
break;

case CustomInput::DATE:
$width = 20;
break;

case CustomInput::CHECKBOX:
$width = 15;
break;

case CustomInput::FILE:
continue 2;

default:
throw new InvalidArgumentException();
}

$sheet->setCellValue([$column, $row], $this->translator->translate($customInput->getName()));
$sheet->getStyle([$column, $row])->getFont()->setBold(true);
$sheet->getColumnDimensionByColumn($column)->setAutoSize(false);
$sheet->getColumnDimensionByColumn($column++)->setWidth($width);
}

foreach ($users as $user) {
$row++;
$column = 1;
Expand All @@ -922,6 +952,25 @@ public function exportNsjOthers($users, string $filename): ExcelResponse
$sheet->setCellValue([$column++, $row], $user->getNote());
$sheet->setCellValue([$column++, $row], $user->getRolesText());
$sheet->setCellValue([$column++, $row], substr($user->getRolesApplication()?->getVariableSymbolText() ?: '', -4));

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$customInputValue = $user->getCustomInputValue($customInput);

if ($customInputValue === null) {
$column++;
continue;
}

if ($customInputValue instanceof CustomCheckboxValue) {
$value = $customInputValue->getValue()
? $this->translator->translate('common.export.common.yes')
: $this->translator->translate('common.export.common.no');
} else {
$value = $customInputValue->getValueText();
}

$sheet->setCellValue([$column++, $row], $value);
}
}

return new ExcelResponse($this->spreadsheet, $filename);
Expand Down

0 comments on commit 71ac4bf

Please sign in to comment.