Skip to content

Commit 8b21648

Browse files
authored
Merge pull request #122 from aweichler/5.x
add possibility to show groups of classification store in output channel definition
2 parents 868867c + bc12687 commit 8b21648

File tree

7 files changed

+169
-5
lines changed

7 files changed

+169
-5
lines changed

doc/classificationstore.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ different display modes for classification store keys in the output definition c
99
##### DisplayMode `all` or `relevant` and type is folder or the object has no assigned group
1010
![image](img/classification_all.jpg)
1111

12+
##### DisplayMode `all` and Grouped `true`
13+
![image](img/classification_all_grouped.jpg)
14+
15+
1216
##### DisplayMode `object` or `relevant` and object has any assigned group
1317
![image](img/classification_relevant.jpg)
1418

124 KB
Loading

src/Controller/ClassController.php

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
use Doctrine\DBAL\Exception\TableNotFoundException;
1919
use OutputDataConfigToolkitBundle\Constant\ColumnConfigDisplayMode;
20+
use OutputDataConfigToolkitBundle\Event;
2021
use Pimcore\Controller\Traits\JsonHelperTrait;
2122
use Pimcore\Controller\UserAwareController;
2223
use Pimcore\Db;
2324
use Pimcore\Model\DataObject;
2425
use Pimcore\Model\DataObject\Classificationstore;
26+
use Pimcore\Model\FactoryInterface;
2527
use Symfony\Component\HttpFoundation\JsonResponse;
2628
use Symfony\Component\HttpFoundation\Request;
2729
use 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
}

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getConfigTreeBuilder()
4242
])
4343
->defaultValue('relevant')
4444
->end()
45+
->booleanNode('grouped')->defaultFalse()->end()
4546
->end()
4647
->end()
4748
->arrayNode('tab_options')

src/DependencyInjection/OutputDataConfigToolkitExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public function load(array $configs, ContainerBuilder $container)
4040
$config = $this->processConfiguration($configuration, $configs);
4141

4242
$displayMode = $config['classification_store']['display_mode'];
43+
$grouped = $config['classification_store']['grouped'];
4344
$defaultGrid = $config['tab_options']['default_classes'];
4445
$orderByName = $config['tab_options']['order_by_name'];
4546

4647
$container
4748
->getDefinition(ClassController::class)
48-
->addMethodCall('setClassificationDisplayMode', [$displayMode]);
49+
->addMethodCall('setClassificationDisplayMode', [$displayMode])
50+
->addMethodCall('setClassificationGroupedDisplay', [$grouped]);
4951

5052
$container
5153
->getDefinition(AdminController::class)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
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+
16+
namespace OutputDataConfigToolkitBundle\Event;
17+
18+
use Pimcore\Model\DataObject;
19+
use Symfony\Contracts\EventDispatcher\Event;
20+
21+
/**
22+
* Class GroupClassificationStoreEvent.
23+
*/
24+
class GroupClassificationStoreEvent extends Event
25+
{
26+
public function __construct(
27+
protected ?DataObject\AbstractObject $targetObject,
28+
protected DataObject\AbstractObject $destinationObject,
29+
protected DataObject\ClassDefinition\Data\Classificationstore $classificationstoreDefinition,
30+
protected array $activeGroups = [],
31+
protected int $storeId = 0,
32+
) {
33+
}
34+
35+
public function setTargetObject(?DataObject\AbstractObject $targetObject): void
36+
{
37+
$this->targetObject = $targetObject;
38+
}
39+
40+
public function getTargetObject(): ?DataObject\AbstractObject
41+
{
42+
return $this->targetObject;
43+
}
44+
45+
public function setDestinationObject(DataObject\AbstractObject $destinationObject): void
46+
{
47+
$this->destinationObject = $destinationObject;
48+
}
49+
50+
public function getDestinationObject(): DataObject\AbstractObject
51+
{
52+
return $this->destinationObject;
53+
}
54+
55+
public function setClassificationstoreDefinition(
56+
DataObject\ClassDefinition\Data\Classificationstore $classificationstoreDefinition
57+
): void {
58+
$this->classificationstoreDefinition = $classificationstoreDefinition;
59+
}
60+
61+
public function getClassificationstoreDefinition(): DataObject\ClassDefinition\Data\Classificationstore
62+
{
63+
return $this->classificationstoreDefinition;
64+
}
65+
66+
public function getActiveGroups(): array
67+
{
68+
return $this->activeGroups;
69+
}
70+
71+
public function setActiveGroups(array $activeGroups): void
72+
{
73+
$this->activeGroups = $activeGroups;
74+
}
75+
76+
public function setStoreId(int $storeId): void
77+
{
78+
$this->storeId = $storeId;
79+
}
80+
81+
public function getStoreId(): int
82+
{
83+
return $this->storeId;
84+
}
85+
}

src/Event/OutputDataConfigToolkitEvents.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ class OutputDataConfigToolkitEvents
3535
* @var string
3636
*/
3737
const SAVE_CONFIG_EVENT = 'outputDataConfigToolkit.saveEvent';
38+
39+
/**
40+
* @Event("OutputDataConfigToolkitBundle\Event\GroupClassificationStoreEvent")
41+
*
42+
* @var string
43+
*/
44+
const GROUP_CLASSIFICATION_STORE_EVENT = 'outputDataConfigToolkit.groupClassificationStoreEvent';
3845
}

0 commit comments

Comments
 (0)