mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-26 00:36:11 +01:00
Daniel Siepmann
27ee70d0cf
A new PSR-14 event is added that allows to modify the categories to be assigned to an event. The event itself (including already existing categories) as well as the list of categories to be used after import are available. It is possible to change the categories to be assigned, e.g. keep some of the existing categories. That way it is possible for installations to add custom categories to events. Relates: #10623
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Wrm\Events\Service\DestinationDataImportService;
|
|
|
|
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
|
use Wrm\Events\Domain\Model\Category;
|
|
use Wrm\Events\Domain\Repository\CategoryRepository;
|
|
use Wrm\Events\Service\DestinationDataImportService\CategoriesAssignment\Import;
|
|
|
|
/**
|
|
* Provides APIs to work with categories that will be assigned to events during import.
|
|
*
|
|
* Categories mean TYPO3 sys_category records.
|
|
* Those are used for multiple records within destination data. E.g. categories or features.
|
|
*/
|
|
class CategoriesAssignment
|
|
{
|
|
/**
|
|
* @var CategoryRepository
|
|
*/
|
|
private $repository;
|
|
|
|
public function __construct(
|
|
CategoryRepository $repository
|
|
) {
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* @return ObjectStorage<Category>
|
|
*/
|
|
public function getCategories(
|
|
Import $import
|
|
): ObjectStorage {
|
|
$categories = new ObjectStorage();
|
|
|
|
if ($import->getParentCategory() === null || $import->getPid() === null) {
|
|
return $categories;
|
|
}
|
|
|
|
foreach ($import->getCategoryTitles() as $categoryTitle) {
|
|
$category = $this->repository->findOneForImport(
|
|
$import->getParentCategory(),
|
|
$import->getPid(),
|
|
$categoryTitle
|
|
);
|
|
|
|
if (!$category instanceof Category) {
|
|
$category = new Category(
|
|
$import->getParentCategory(),
|
|
$import->getPid(),
|
|
$categoryTitle,
|
|
$import->getHideByDefault() ? true : false
|
|
);
|
|
$this->repository->add($category);
|
|
}
|
|
|
|
$categories->attach($category);
|
|
}
|
|
|
|
return $categories;
|
|
}
|
|
}
|