<?php
namespace App\Controller;
use GraphQL\Graph;
use GuzzleHttp\Client;
use Pimcore\Db;
use Pimcore\Model\DataObject\ClassDefinition\Data\ManyToManyObjectRelation;
use Pimcore\Model\DataObject\DemiEventCategoryExternal;
use Pimcore\Model\DataObject\DemiEventMapping;
use Pimcore\Model\DataObject\DemiFacility;
use Pimcore\Model\DataObject\DemiInfraMapping;
use Pimcore\Model\DataObject\DemiInfrastructureCategoryExternal;
use Pimcore\Model\DataObject\DemiInfrastructureTopic;
use Pimcore\Model\DataObject\DemiInfrastructureType;
use Pimcore\Model\DataObject\Fieldcollection\Data\DemiEventMappingRow;
use Pimcore\Model\DataObject\Objectbrick;
use Pimcore\Version;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class DefaultController extends AbstractController
{
/**
* @Template
**/
public function defaultAction(Request $request)
{
}
/**
* @param Request $request
* @param Client $client
* @route("/mappingtest")
*/
public function mappingTestAction(Request $request) {
try {
$eventmapping = DemiEventMapping::getById(389693);
$inframapping = DemiInfraMapping::getById(438224);
foreach ($inframapping->getCategoryMapping()->getItems() as $item) {
$newMappingObject = DemiInfrastructureCategoryExternal::getByFId($item->getFid(), 1);
foreach ($item->getMappedObjects() as $mappedObject) {
if ($mappedObject instanceof DemiInfrastructureTopic || $mappedObject instanceof DemiInfrastructureType) {
if ($mappedObject->getDemiExtension() === null) {
$mappedObject->setDemiExtension(new Objectbrick($mappedObject, "demiExtension"));
}
$mappingBrick = $mappedObject->getDemiExtension()->getDemiInfrastructureCategoryExternalMapping();
if (!$mappingBrick instanceof Objectbrick\Data\DemiInfrastructureCategoryExternalMapping) {
$mappingBrick = new Objectbrick\Data\DemiInfrastructureCategoryExternalMapping($mappedObject);
}
$mappedEventCats = $mappingBrick->getMappedCategories();
if (!in_array($newMappingObject, $mappedEventCats)) {
$mappedEventCats[] = $newMappingObject;
}
$mappingBrick->setMappedCategories($mappedEventCats);
$mappedObject->getDemiExtension()->setDemiInfrastructureCategoryExternalMapping($mappingBrick);
$mappedObject->save();
}
}
}
} catch (\Throwable $exception) {
throw $exception;
}
}
}