vendor/pimcore/data-hub/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/ImageGallery.php line 82

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectQueryFieldConfigGenerator\Helper;
  16. use GraphQL\Type\Definition\ResolveInfo;
  17. use Pimcore\Bundle\DataHubBundle\GraphQL\ElementDescriptor;
  18. use Pimcore\Bundle\DataHubBundle\GraphQL\Service as GraphQlService;
  19. use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait;
  20. use Pimcore\Bundle\DataHubBundle\WorkspaceHelper;
  21. use Pimcore\Model\Asset;
  22. use Pimcore\Model\DataObject\ClassDefinition;
  23. use Pimcore\Model\DataObject\Data\Hotspotimage;
  24. use Pimcore\Model\DataObject\Fieldcollection;
  25. use Pimcore\Model\Element\Service;
  26. /**
  27.  * Class ImageGallery
  28.  *
  29.  * @package Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectQueryFieldConfigGenerator\Helper
  30.  */
  31. class ImageGallery
  32. {
  33.     use ServiceTrait;
  34.     /**
  35.      * @var ClassDefinition\Data\ImageGallery
  36.      */
  37.     public $fieldDefinition;
  38.     /**
  39.      * @var ClassDefinition|Fieldcollection\Definition
  40.      */
  41.     public $class;
  42.     /**
  43.      * @var string
  44.      */
  45.     public $attribute;
  46.     /**
  47.      * @param GraphQlService $graphQlService
  48.      * @param string $attribute
  49.      * @param ClassDefinition\Data\ImageGallery $fieldDefinition
  50.      * @param ClassDefinition|Fieldcollection\Definition $class
  51.      */
  52.     public function __construct(
  53.         GraphQlService $graphQlService,
  54.         $attribute,
  55.         ClassDefinition\Data\ImageGallery $fieldDefinition,
  56.         $class
  57.     ) {
  58.         $this->fieldDefinition $fieldDefinition;
  59.         $this->class $class;
  60.         $this->attribute $attribute;
  61.         $this->setGraphQLService($graphQlService);
  62.     }
  63.     /**
  64.      * @param mixed $value
  65.      * @param array $args
  66.      * @param array $context
  67.      * @param ResolveInfo|null $resolveInfo
  68.      *
  69.      * @return ElementDescriptor[]|null
  70.      *
  71.      * @throws \Exception
  72.      */
  73.     public function resolve($value null$args = [], $context = [], ResolveInfo $resolveInfo null)
  74.     {
  75.         $result = [];
  76.         $relations GraphQlService::resolveValue($value$this->fieldDefinition$this->attribute$args);
  77.         if ($relations) {
  78.             foreach ($relations as $relation) {
  79.                 if ($relation instanceof Hotspotimage) {
  80.                     $image $relation->getImage();
  81.                 } else {
  82.                     continue;
  83.                 }
  84.                 if ($image instanceof Asset) {
  85.                     if (!WorkspaceHelper::checkPermission($image'read')) {
  86.                         continue;
  87.                     }
  88.                     $data = new ElementDescriptor($image);
  89.                     $this->getGraphQlService()->extractData($data$image$args$context$resolveInfo);
  90.                     $data['data'] = isset($data['data']) ? base64_encode($data['data']) : null;
  91.                     $data['crop'] = $relation->getCrop();
  92.                     $data['hotspots'] = $relation->getHotspots();
  93.                     $data['marker'] = $relation->getMarker();
  94.                     $data['img'] = $image;
  95.                     $data['image'] = $image->getType();
  96.                     $data['__elementType'] = Service::getType($image);
  97.                     $data['__elementSubtype'] = $image->getType();
  98.                 } else {
  99.                     continue;
  100.                 }
  101.                 $result[] = $data;
  102.             }
  103.         }
  104.         return !empty($result) ? $result null;
  105.     }
  106. }