2022-07-05 14:08:14 +02:00
|
|
|
<?php
|
|
|
|
|
2023-11-09 10:27:43 +01:00
|
|
|
namespace WerkraumMedia\Events\Service\DestinationDataImportService;
|
2022-07-05 14:08:14 +02:00
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
|
2022-07-05 14:08:14 +02:00
|
|
|
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
|
2023-11-09 10:27:43 +01:00
|
|
|
use WerkraumMedia\Events\Domain\Model\Category;
|
|
|
|
use WerkraumMedia\Events\Domain\Repository\CategoryRepository;
|
|
|
|
use WerkraumMedia\Events\Service\DestinationDataImportService\CategoriesAssignment\Import;
|
2022-07-05 14:08:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
/**
|
|
|
|
* @var PersistenceManager
|
|
|
|
*/
|
|
|
|
private $persistenceManager;
|
|
|
|
|
2022-07-05 14:08:14 +02:00
|
|
|
public function __construct(
|
2023-11-06 08:44:03 +01:00
|
|
|
CategoryRepository $repository,
|
|
|
|
PersistenceManager $persistenceManager
|
2022-07-05 14:08:14 +02:00
|
|
|
) {
|
|
|
|
$this->repository = $repository;
|
2023-11-06 08:44:03 +01:00
|
|
|
$this->persistenceManager = $persistenceManager;
|
2022-07-05 14:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ObjectStorage<Category>
|
|
|
|
*/
|
|
|
|
public function getCategories(
|
|
|
|
Import $import
|
|
|
|
): ObjectStorage {
|
|
|
|
$categories = new ObjectStorage();
|
|
|
|
|
2022-08-03 08:41:54 +02:00
|
|
|
if ($import->getParentCategory() === null || $import->getPid() === null) {
|
2022-07-05 14:08:14 +02:00
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($import->getCategoryTitles() as $categoryTitle) {
|
|
|
|
$category = $this->repository->findOneForImport(
|
|
|
|
$import->getParentCategory(),
|
|
|
|
$import->getPid(),
|
|
|
|
$categoryTitle
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$category instanceof Category) {
|
2023-08-14 12:09:28 +02:00
|
|
|
$category = new Category(
|
|
|
|
$import->getParentCategory(),
|
|
|
|
$import->getPid(),
|
|
|
|
$categoryTitle,
|
|
|
|
$import->getHideByDefault() ? true : false
|
|
|
|
);
|
2022-07-05 14:08:14 +02:00
|
|
|
$this->repository->add($category);
|
|
|
|
}
|
|
|
|
|
|
|
|
$categories->attach($category);
|
|
|
|
}
|
|
|
|
|
2023-11-06 08:44:03 +01:00
|
|
|
$this->persistenceManager->persistAll();
|
|
|
|
|
2022-07-05 14:08:14 +02:00
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
}
|