-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce formatters for columns in content element
Related: #10
- Loading branch information
1 parent
050fd59
commit 30d3a99
Showing
36 changed files
with
901 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "jobrouter_data" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\JobRouterData\Domain\Converter; | ||
|
||
use Brotkrueml\JobRouterData\Domain\Model\Column; | ||
use Brotkrueml\JobRouterData\Domain\Model\Dataset; | ||
use Brotkrueml\JobRouterData\Event\ModifyColumnContentEvent; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DatasetConverter | ||
{ | ||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $eventDispatcher; | ||
|
||
public function __construct(EventDispatcherInterface $eventDispatcher) | ||
{ | ||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param Column[] $columns | ||
* @param Dataset[] $datasets | ||
* @return list<array<string, float|int|string|null>> | ||
*/ | ||
public function convertFromJsonToArray(array $columns, array $datasets, string $locale): array | ||
{ | ||
$rows = []; | ||
foreach ($datasets as $datasetJson) { | ||
$datasetArray = \json_decode($datasetJson->getDataset(), true, 512, \JSON_THROW_ON_ERROR); | ||
|
||
$row = []; | ||
foreach ($columns as $column) { | ||
if ($datasetArray[$column->getName()] ?? false) { | ||
/** @var float|int|string|null $content */ | ||
$content = $datasetArray[$column->getName()]; | ||
if ($content === null || $content === '') { | ||
$row[$column->getName()] = ''; | ||
continue; | ||
} | ||
|
||
$event = new ModifyColumnContentEvent($column, $content, $locale); | ||
/** @var ModifyColumnContentEvent $event */ | ||
$event = $this->eventDispatcher->dispatch($event); | ||
$row[$column->getName()] = $event->getContent(); | ||
} | ||
} | ||
$rows[] = $row; | ||
} | ||
|
||
return $rows; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.