-
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 0eddbef
Showing
36 changed files
with
940 additions
and
718 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,63 @@ | ||
<?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\Table; | ||
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; | ||
} | ||
|
||
/** | ||
* @return list<array<string, float|int|string|null>> | ||
*/ | ||
public function convertFromJsonToArray(Table $table, string $locale): array | ||
{ | ||
$rows = []; | ||
foreach ($table->getDatasets() as $datasetJson) { | ||
$datasetArray = \json_decode($datasetJson->getDataset(), true, 512, \JSON_THROW_ON_ERROR); | ||
|
||
$row = []; | ||
foreach ($table->getColumns() 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($table, $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.