src/Controller/DefaultController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use GraphQL\Graph;
  4. use GuzzleHttp\Client;
  5. use Pimcore\Db;
  6. use Pimcore\Model\DataObject\ClassDefinition\Data\ManyToManyObjectRelation;
  7. use Pimcore\Model\DataObject\DemiEventCategoryExternal;
  8. use Pimcore\Model\DataObject\DemiEventMapping;
  9. use Pimcore\Model\DataObject\DemiFacility;
  10. use Pimcore\Model\DataObject\DemiInfraMapping;
  11. use Pimcore\Model\DataObject\DemiInfrastructureCategoryExternal;
  12. use Pimcore\Model\DataObject\DemiInfrastructureTopic;
  13. use Pimcore\Model\DataObject\DemiInfrastructureType;
  14. use Pimcore\Model\DataObject\Fieldcollection\Data\DemiEventMappingRow;
  15. use Pimcore\Model\DataObject\Objectbrick;
  16. use Pimcore\Version;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. class DefaultController extends AbstractController
  21. {
  22.     /**
  23.      * @Template
  24.      **/
  25.     public function defaultAction(Request $request)
  26.     {
  27.     }
  28.     /**
  29.      * @param Request $request
  30.      * @param Client $client
  31.      * @route("/mappingtest")
  32.      */
  33.     public function mappingTestAction(Request $request) {
  34.         try {
  35.             $eventmapping DemiEventMapping::getById(389693);
  36.             $inframapping DemiInfraMapping::getById(438224);
  37.             foreach ($inframapping->getCategoryMapping()->getItems() as $item) {
  38.                 $newMappingObject DemiInfrastructureCategoryExternal::getByFId($item->getFid(), 1);
  39.                 foreach ($item->getMappedObjects() as $mappedObject) {
  40.                     if ($mappedObject instanceof DemiInfrastructureTopic || $mappedObject instanceof DemiInfrastructureType) {
  41.                         if ($mappedObject->getDemiExtension() === null) {
  42.                             $mappedObject->setDemiExtension(new Objectbrick($mappedObject"demiExtension"));
  43.                         }
  44.                         $mappingBrick $mappedObject->getDemiExtension()->getDemiInfrastructureCategoryExternalMapping();
  45.                         if (!$mappingBrick instanceof Objectbrick\Data\DemiInfrastructureCategoryExternalMapping) {
  46.                             $mappingBrick = new Objectbrick\Data\DemiInfrastructureCategoryExternalMapping($mappedObject);
  47.                         }
  48.                         $mappedEventCats $mappingBrick->getMappedCategories();
  49.                         if (!in_array($newMappingObject$mappedEventCats)) {
  50.                             $mappedEventCats[] = $newMappingObject;
  51.                         }
  52.                         $mappingBrick->setMappedCategories($mappedEventCats);
  53.                         $mappedObject->getDemiExtension()->setDemiInfrastructureCategoryExternalMapping($mappingBrick);
  54.                         $mappedObject->save();
  55.                     }
  56.                 }
  57.             }
  58.         } catch (\Throwable $exception) {
  59.             throw $exception;
  60.         }
  61.     }
  62. }