diff --git a/doc/classificationstore.md b/doc/classificationstore.md index 4e507b8..49f10ae 100644 --- a/doc/classificationstore.md +++ b/doc/classificationstore.md @@ -9,6 +9,10 @@ different display modes for classification store keys in the output definition c ##### DisplayMode `all` or `relevant` and type is folder or the object has no assigned group ![image](img/classification_all.jpg) +##### DisplayMode `all` and Grouped `true` +![image](img/classification_all_grouped.jpg) + + ##### DisplayMode `object` or `relevant` and object has any assigned group ![image](img/classification_relevant.jpg) diff --git a/doc/img/classification_all_grouped.jpg b/doc/img/classification_all_grouped.jpg new file mode 100644 index 0000000..0145f89 Binary files /dev/null and b/doc/img/classification_all_grouped.jpg differ diff --git a/src/Controller/ClassController.php b/src/Controller/ClassController.php index fe7dbf7..8b98510 100644 --- a/src/Controller/ClassController.php +++ b/src/Controller/ClassController.php @@ -17,14 +17,17 @@ use Doctrine\DBAL\Exception\TableNotFoundException; use OutputDataConfigToolkitBundle\Constant\ColumnConfigDisplayMode; +use OutputDataConfigToolkitBundle\Event; use Pimcore\Controller\Traits\JsonHelperTrait; use Pimcore\Controller\UserAwareController; use Pimcore\Db; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Classificationstore; +use Pimcore\Model\FactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Class ClassController @@ -39,6 +42,9 @@ class ClassController extends UserAwareController /* @var string $classificationDisplayMode */ protected $classificationDisplayMode; + /* @var bool $classificationGroupedDisplay */ + protected bool $classificationGroupedDisplay; + /** * @Route("/get-class-definition-for-column-config", methods={"GET"}) * @@ -48,7 +54,7 @@ class ClassController extends UserAwareController * * @throws \Exception */ - public function getClassDefinitionForColumnConfigAction(Request $request) + public function getClassDefinitionForColumnConfigAction(Request $request, EventDispatcherInterface $eventDispatcher, FactoryInterface $factory) { $classId = $request->query->getString('id'); $class = DataObject\ClassDefinition::getById($classId); @@ -103,7 +109,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request) } } - $this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result); + $this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result, $eventDispatcher, $factory); return $this->jsonResponse($result); } @@ -114,7 +120,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request) * @param array $fieldDefinitions * @param array $result */ - private function considerClassificationStoreForColumnConfig(Request $request, ?DataObject\ClassDefinition $class, array $fieldDefinitions, array &$result): void + private function considerClassificationStoreForColumnConfig(Request $request, ?DataObject\ClassDefinition $class, array $fieldDefinitions, array &$result, EventDispatcherInterface $eventDispatcher, FactoryInterface $factory): void { $displayMode = $this->getClassificationDisplayMode(); @@ -123,6 +129,7 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D } $enrichment = false; + $grouped = $this->getClassificationGroupedDisplay(); if ($displayMode == ColumnConfigDisplayMode::DATA_OBJECT || $displayMode == ColumnConfigDisplayMode::RELEVANT) { $targetObjectId = $request->query->getInt('target_oid'); @@ -142,7 +149,48 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D } } - if ($displayMode == ColumnConfigDisplayMode::ALL || ($displayMode == ColumnConfigDisplayMode::RELEVANT && !$enrichment)) { + if ($displayMode == ColumnConfigDisplayMode::ALL && $grouped === true) { + $class->setFieldDefinitions($fieldDefinitions); + $classString = 'Pimcore\\Model\\DataObject\\' . $class->getName(); + $targetObjectId = intval($request->get('target_oid')); + $targetObject = DataObject\Concrete::getById($targetObjectId); + $tmpObject = $factory->build($classString); + /** @var DataObject\Concrete $tmpObject */ + $db = Db::get(); + foreach ($class->getFieldDefinitions() as $fieldDefinition) { + if (!$fieldDefinition instanceof DataObject\ClassDefinition\Data\Classificationstore) { + continue; + } + + $storeId = $fieldDefinition->getStoreId(); + $store = new DataObject\Classificationstore(); + + $groupIds = []; + $sql = 'SELECT `id` FROM `classificationstore_groups`'; + if ($storeId > 0) { + $sql = 'SELECT `id` FROM `classificationstore_groups` WHERE `storeId` = ' . intval($storeId); + } + + $queryResult = $db->executeQuery($sql); + + while ($row = $queryResult->fetchAssociative()) { + $groupIds[intval($row['id'])] = true; + } + + $event = new Event\GroupClassificationStoreEvent($targetObject, $tmpObject, $fieldDefinition, $groupIds, $storeId); + $eventDispatcher->dispatch($event, Event\OutputDataConfigToolkitEvents::GROUP_CLASSIFICATION_STORE_EVENT); + + $store->setActiveGroups($event->getActiveGroups()); + $store->setClass($class); + $store->setFieldname($fieldDefinition->getName()); + $store->setObject($tmpObject); + $tmpObject->set($fieldDefinition->getName(), $store); + } + + DataObject\Service::enrichLayoutDefinition($result['objectColumns']['children'][0], $tmpObject); + } + + if ($grouped === false && $displayMode == ColumnConfigDisplayMode::ALL || ($displayMode == ColumnConfigDisplayMode::RELEVANT && !$enrichment)) { $keyConfigDefinitions = []; $keyConfigs = new Classificationstore\KeyConfig\Listing(); $keyConfigs = $keyConfigs->load(); @@ -180,4 +228,21 @@ public function getClassificationDisplayMode(): string { return $this->classificationDisplayMode; } + + /** + * @param bool $grouped + */ + public function setClassificationGroupedDisplay(bool $grouped) + { + $this->classificationGroupedDisplay = $grouped; + } + + /** + * + * @return bool + */ + public function getClassificationGroupedDisplay(): bool + { + return $this->classificationGroupedDisplay; + } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d79af3d..5d3884a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -42,6 +42,7 @@ public function getConfigTreeBuilder() ]) ->defaultValue('relevant') ->end() + ->booleanNode('grouped')->defaultFalse()->end() ->end() ->end() ->arrayNode('tab_options') diff --git a/src/DependencyInjection/OutputDataConfigToolkitExtension.php b/src/DependencyInjection/OutputDataConfigToolkitExtension.php index 5cda80a..a2077f8 100644 --- a/src/DependencyInjection/OutputDataConfigToolkitExtension.php +++ b/src/DependencyInjection/OutputDataConfigToolkitExtension.php @@ -40,12 +40,14 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration($configuration, $configs); $displayMode = $config['classification_store']['display_mode']; + $grouped = $config['classification_store']['grouped']; $defaultGrid = $config['tab_options']['default_classes']; $orderByName = $config['tab_options']['order_by_name']; $container ->getDefinition(ClassController::class) - ->addMethodCall('setClassificationDisplayMode', [$displayMode]); + ->addMethodCall('setClassificationDisplayMode', [$displayMode]) + ->addMethodCall('setClassificationGroupedDisplay', [$grouped]); $container ->getDefinition(AdminController::class) diff --git a/src/Event/GroupClassificationStoreEvent.php b/src/Event/GroupClassificationStoreEvent.php new file mode 100644 index 0000000..d32925d --- /dev/null +++ b/src/Event/GroupClassificationStoreEvent.php @@ -0,0 +1,85 @@ +targetObject = $targetObject; + } + + public function getTargetObject(): ?DataObject\AbstractObject + { + return $this->targetObject; + } + + public function setDestinationObject(DataObject\AbstractObject $destinationObject): void + { + $this->destinationObject = $destinationObject; + } + + public function getDestinationObject(): DataObject\AbstractObject + { + return $this->destinationObject; + } + + public function setClassificationstoreDefinition( + DataObject\ClassDefinition\Data\Classificationstore $classificationstoreDefinition + ): void { + $this->classificationstoreDefinition = $classificationstoreDefinition; + } + + public function getClassificationstoreDefinition(): DataObject\ClassDefinition\Data\Classificationstore + { + return $this->classificationstoreDefinition; + } + + public function getActiveGroups(): array + { + return $this->activeGroups; + } + + public function setActiveGroups(array $activeGroups): void + { + $this->activeGroups = $activeGroups; + } + + public function setStoreId(int $storeId): void + { + $this->storeId = $storeId; + } + + public function getStoreId(): int + { + return $this->storeId; + } +} diff --git a/src/Event/OutputDataConfigToolkitEvents.php b/src/Event/OutputDataConfigToolkitEvents.php index 91f7ccc..f16fd2e 100644 --- a/src/Event/OutputDataConfigToolkitEvents.php +++ b/src/Event/OutputDataConfigToolkitEvents.php @@ -35,4 +35,11 @@ class OutputDataConfigToolkitEvents * @var string */ const SAVE_CONFIG_EVENT = 'outputDataConfigToolkit.saveEvent'; + + /** + * @Event("OutputDataConfigToolkitBundle\Event\GroupClassificationStoreEvent") + * + * @var string + */ + const GROUP_CLASSIFICATION_STORE_EVENT = 'outputDataConfigToolkit.groupClassificationStoreEvent'; }