1717
1818use Doctrine \DBAL \Exception \TableNotFoundException ;
1919use OutputDataConfigToolkitBundle \Constant \ColumnConfigDisplayMode ;
20+ use OutputDataConfigToolkitBundle \Event ;
2021use Pimcore \Controller \Traits \JsonHelperTrait ;
2122use Pimcore \Controller \UserAwareController ;
2223use Pimcore \Db ;
2324use Pimcore \Model \DataObject ;
2425use Pimcore \Model \DataObject \Classificationstore ;
26+ use Pimcore \Model \FactoryInterface ;
2527use Symfony \Component \HttpFoundation \JsonResponse ;
2628use Symfony \Component \HttpFoundation \Request ;
2729use Symfony \Component \Routing \Annotation \Route ;
30+ use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
2831
2932/**
3033 * Class ClassController
@@ -39,6 +42,9 @@ class ClassController extends UserAwareController
3942 /* @var string $classificationDisplayMode */
4043 protected $ classificationDisplayMode ;
4144
45+ /* @var bool $classificationGroupedDisplay */
46+ protected bool $ classificationGroupedDisplay ;
47+
4248 /**
4349 * @Route("/get-class-definition-for-column-config", methods={"GET"})
4450 *
@@ -48,7 +54,7 @@ class ClassController extends UserAwareController
4854 *
4955 * @throws \Exception
5056 */
51- public function getClassDefinitionForColumnConfigAction (Request $ request )
57+ public function getClassDefinitionForColumnConfigAction (Request $ request, EventDispatcherInterface $ eventDispatcher , FactoryInterface $ factory )
5258 {
5359 $ classId = $ request ->query ->getString ('id ' );
5460 $ class = DataObject \ClassDefinition::getById ($ classId );
@@ -103,7 +109,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request)
103109 }
104110 }
105111
106- $ this ->considerClassificationStoreForColumnConfig ($ request , $ class , $ fieldDefinitions , $ result );
112+ $ this ->considerClassificationStoreForColumnConfig ($ request , $ class , $ fieldDefinitions , $ result, $ eventDispatcher , $ factory );
107113
108114 return $ this ->jsonResponse ($ result );
109115 }
@@ -114,7 +120,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request)
114120 * @param array $fieldDefinitions
115121 * @param array $result
116122 */
117- private function considerClassificationStoreForColumnConfig (Request $ request , ?DataObject \ClassDefinition $ class , array $ fieldDefinitions , array &$ result ): void
123+ private function considerClassificationStoreForColumnConfig (Request $ request , ?DataObject \ClassDefinition $ class , array $ fieldDefinitions , array &$ result, EventDispatcherInterface $ eventDispatcher , FactoryInterface $ factory ): void
118124 {
119125 $ displayMode = $ this ->getClassificationDisplayMode ();
120126
@@ -123,6 +129,7 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D
123129 }
124130
125131 $ enrichment = false ;
132+ $ grouped = $ this ->getClassificationGroupedDisplay ();
126133 if ($ displayMode == ColumnConfigDisplayMode::DATA_OBJECT || $ displayMode == ColumnConfigDisplayMode::RELEVANT ) {
127134 $ targetObjectId = $ request ->query ->getInt ('target_oid ' );
128135
@@ -142,7 +149,48 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D
142149 }
143150 }
144151
145- if ($ displayMode == ColumnConfigDisplayMode::ALL || ($ displayMode == ColumnConfigDisplayMode::RELEVANT && !$ enrichment )) {
152+ if ($ displayMode == ColumnConfigDisplayMode::ALL && $ grouped === true ) {
153+ $ class ->setFieldDefinitions ($ fieldDefinitions );
154+ $ classString = 'Pimcore \\Model \\DataObject \\' . $ class ->getName ();
155+ $ targetObjectId = intval ($ request ->get ('target_oid ' ));
156+ $ targetObject = DataObject \Concrete::getById ($ targetObjectId );
157+ $ tmpObject = $ factory ->build ($ classString );
158+ /** @var DataObject\Concrete $tmpObject */
159+ $ db = Db::get ();
160+ foreach ($ class ->getFieldDefinitions () as $ fieldDefinition ) {
161+ if (!$ fieldDefinition instanceof DataObject \ClassDefinition \Data \Classificationstore) {
162+ continue ;
163+ }
164+
165+ $ storeId = $ fieldDefinition ->getStoreId ();
166+ $ store = new DataObject \Classificationstore ();
167+
168+ $ groupIds = [];
169+ $ sql = 'SELECT `id` FROM `classificationstore_groups` ' ;
170+ if ($ storeId > 0 ) {
171+ $ sql = 'SELECT `id` FROM `classificationstore_groups` WHERE `storeId` = ' . intval ($ storeId );
172+ }
173+
174+ $ queryResult = $ db ->executeQuery ($ sql );
175+
176+ while ($ row = $ queryResult ->fetchAssociative ()) {
177+ $ groupIds [intval ($ row ['id ' ])] = true ;
178+ }
179+
180+ $ event = new Event \GroupClassificationStoreEvent ($ targetObject , $ tmpObject , $ fieldDefinition , $ groupIds , $ storeId );
181+ $ eventDispatcher ->dispatch ($ event , Event \OutputDataConfigToolkitEvents::GROUP_CLASSIFICATION_STORE_EVENT );
182+
183+ $ store ->setActiveGroups ($ event ->getActiveGroups ());
184+ $ store ->setClass ($ class );
185+ $ store ->setFieldname ($ fieldDefinition ->getName ());
186+ $ store ->setObject ($ tmpObject );
187+ $ tmpObject ->set ($ fieldDefinition ->getName (), $ store );
188+ }
189+
190+ DataObject \Service::enrichLayoutDefinition ($ result ['objectColumns ' ]['children ' ][0 ], $ tmpObject );
191+ }
192+
193+ if ($ grouped === false && $ displayMode == ColumnConfigDisplayMode::ALL || ($ displayMode == ColumnConfigDisplayMode::RELEVANT && !$ enrichment )) {
146194 $ keyConfigDefinitions = [];
147195 $ keyConfigs = new Classificationstore \KeyConfig \Listing ();
148196 $ keyConfigs = $ keyConfigs ->load ();
@@ -180,4 +228,21 @@ public function getClassificationDisplayMode(): string
180228 {
181229 return $ this ->classificationDisplayMode ;
182230 }
231+
232+ /**
233+ * @param bool $grouped
234+ */
235+ public function setClassificationGroupedDisplay (bool $ grouped )
236+ {
237+ $ this ->classificationGroupedDisplay = $ grouped ;
238+ }
239+
240+ /**
241+ *
242+ * @return bool
243+ */
244+ public function getClassificationGroupedDisplay (): bool
245+ {
246+ return $ this ->classificationGroupedDisplay ;
247+ }
183248}
0 commit comments