Skip to content

Commit

Permalink
whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lintaba committed Feb 1, 2022
1 parent d5b871e commit 8268d9f
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Exports/QuickExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Lintaba\OrchidTables\Exports;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand All @@ -14,7 +13,6 @@
use Maatwebsite\Excel\Concerns;
use Orchid\Screen\Layouts\Table;
use Orchid\Screen\TD;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use ReflectionClass;
use ReflectionMethod;
Expand Down Expand Up @@ -44,7 +42,6 @@ public function iterator(): Iterator
yield array_values($headers);
$rowNum++;


foreach ($this->getData() as $entry) {
yield $columns->map(function ($col, $colIndex) use ($entry, $rowNum) {
return $this->exportField($colIndex, $rowNum, $col, $entry);
Expand Down Expand Up @@ -72,27 +69,33 @@ protected function hackyGetColumns(Table $table)

protected function isDate($value, $entry, $fieldName): bool
{
return $value instanceof DateTimeInterface || Str::of($fieldName)->endsWith('_at') || ($entry instanceof Model && $entry->hasCast(
$fieldName,
['date', 'datetime', 'immutable_date', 'immutable_datetime']
));
return $value instanceof DateTimeInterface
|| Str::of($fieldName)->endsWith('_at')
|| ($entry instanceof Model && $entry->hasCast(
$fieldName,
['date', 'datetime', 'immutable_date', 'immutable_datetime']
));
}

protected function getName(): string
{
return Str::slug((new ReflectionClass($this->builder instanceof \Illuminate\Database\Eloquent\Builder ?
$this->builder->getModel() : $this->builder))->getShortName());
return Str::slug(
(new ReflectionClass(
$this->builder instanceof \Illuminate\Database\Eloquent\Builder ?
$this->builder->getModel() : $this->builder
))->getShortName()
);
}

protected function exportField(int $colIndex, int $rowNum, $col, $entry)
{
if(method_exists($col,'getStyle')) {
if (method_exists($col, 'getStyle')) {
$this->computedStyles[$this->indexToLetter($colIndex + 1) . $rowNum] = $col->getStyle($entry);
}

$fieldName = $col->getName();
$value = is_object($entry) && method_exists($entry,'getContent') ? $entry->getContent($fieldName) : data_get
($entry, $fieldName);
$value = is_object($entry) && method_exists($entry, 'getContent') ?
$entry->getContent($fieldName) : data_get($entry, $fieldName);

$value = $col->exportGetValue($value, $entry, $rowNum);

Expand All @@ -109,13 +112,16 @@ protected function exportField(int $colIndex, int $rowNum, $col, $entry)
$value = (string)$value;
}
if (is_array($value)) {
$value = implode(', ', array_map(static function ($v) {
if (is_array($v)) {
$v = $v['name'] ?? Arr::first($v);
}

return (string)$v;
}, $value));
$value = implode(
', ',
array_map(static function ($v) {
if (is_array($v)) {
$v = $v['name'] ?? Arr::first($v);
}

return (string)$v;
}, $value)
);
}

return $value;
Expand Down

0 comments on commit 8268d9f

Please sign in to comment.