Skip to content

Commit

Permalink
Merge pull request #122 from aweichler/5.x
Browse files Browse the repository at this point in the history
 add possibility to show groups of classification store in output channel definition
  • Loading branch information
mcop1 authored Oct 18, 2024
2 parents 868867c + bc12687 commit 8b21648
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/classificationstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Binary file added doc/img/classification_all_grouped.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 69 additions & 4 deletions src/Controller/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"})
*
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();

Expand All @@ -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');

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getConfigTreeBuilder()
])
->defaultValue('relevant')
->end()
->booleanNode('grouped')->defaultFalse()->end()
->end()
->end()
->arrayNode('tab_options')
Expand Down
4 changes: 3 additions & 1 deletion src/DependencyInjection/OutputDataConfigToolkitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 85 additions & 0 deletions src/Event/GroupClassificationStoreEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace OutputDataConfigToolkitBundle\Event;

use Pimcore\Model\DataObject;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class GroupClassificationStoreEvent.
*/
class GroupClassificationStoreEvent extends Event
{
public function __construct(
protected ?DataObject\AbstractObject $targetObject,
protected DataObject\AbstractObject $destinationObject,
protected DataObject\ClassDefinition\Data\Classificationstore $classificationstoreDefinition,
protected array $activeGroups = [],
protected int $storeId = 0,
) {
}

public function setTargetObject(?DataObject\AbstractObject $targetObject): void
{
$this->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;
}
}
7 changes: 7 additions & 0 deletions src/Event/OutputDataConfigToolkitEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 8b21648

Please sign in to comment.