Skip to content

Commit

Permalink
Merge pull request #1158 from Intermesh/feature/1155
Browse files Browse the repository at this point in the history
#1155 Remove final from exportToBlob method, extract colorizeHeaders …
  • Loading branch information
mschering authored Jun 28, 2024
2 parents b7f390f + 1e215d2 commit 55a47d6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
4 changes: 2 additions & 2 deletions www/go/core/data/convert/AbstractConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ protected function finishImport(): void
* @param array $params
* @return Blob
*/
public final function exportToBlob(Query $entities, array $params = []): Blob
public function exportToBlob(Query $entities, array $params = []): Blob
{
$this->clientParams = $params;
$this->entitiesQuery = $entities;
Expand All @@ -310,7 +310,7 @@ public final function exportToBlob(Query $entities, array $params = []): Blob
/**
* @var Query
*/
private $entitiesQuery;
protected $entitiesQuery;

/**
* The query used for exporting entities
Expand Down
51 changes: 45 additions & 6 deletions www/go/core/data/convert/Spreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,39 @@ protected function exportEntity(Entity $entity): void
$this->writeRecord($record);
}

/**
* @param \go\core\orm\Query $entities
* @param array $params
* @return \go\core\fs\Blob
* @throws \go\core\orm\exception\SaveException
*/
public function exportToBlob(Query $entities, array $params = []): Blob
{
$this->clientParams = $params;
$this->entitiesQuery = $entities;
$this->initExport();

protected function finishExport(): Blob
$this->index = 0;
foreach($entities as $entity) {
$this->exportEntity($entity);
$this->index++;
}

$this->colorizeHeaders();

return $this->finishExport();
}

/**
* @return void
*/
protected function colorizeHeaders(): void
{
switch($this->extension) {
switch ($this->extension) {
case 'html':
fputs($this->fp, "</table></body></html>");
break;
case 'csv':

break;
default:

$headerStyle = [
'font' => [
'bold' => true,
Expand All @@ -258,7 +279,25 @@ protected function finishExport(): Blob
$colDim = $this->spreadsheet->getActiveSheet()->getColumnDimension($col->getColumnIndex());
$colDim->setAutoSize(true);
}
break;
}
}

/**
* @return \go\core\fs\Blob
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \go\core\orm\exception\SaveException
*/
protected function finishExport(): Blob
{
switch($this->extension) {
case 'html':
fputs($this->fp, "</table></body></html>");
break;
case 'csv':

break;
default:
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->spreadsheet);
$writer->setPreCalculateFormulas(false);
$writer->save($this->tempFile->getPath());
Expand Down

0 comments on commit 55a47d6

Please sign in to comment.