Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to show groups of classification store in output channel definition #122

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
71 changes: 67 additions & 4 deletions src/Controller/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Doctrine\DBAL\Exception\TableNotFoundException;
use OutputDataConfigToolkitBundle\Constant\ColumnConfigDisplayMode;
use OutputDataConfigToolkitBundle\Event;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Db;
Expand All @@ -25,6 +26,7 @@
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 +41,9 @@ class ClassController extends UserAwareController
/* @var string $classificationDisplayMode */
protected $classificationDisplayMode;

/* @var bool $classificationGroupedDisplay */
protected $classificationGroupedDisplay;
mcop1 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @Route("/get-class-definition-for-column-config", methods={"GET"})
*
Expand All @@ -48,7 +53,7 @@ class ClassController extends UserAwareController
*
* @throws \Exception
*/
public function getClassDefinitionForColumnConfigAction(Request $request)
public function getClassDefinitionForColumnConfigAction(Request $request, EventDispatcherInterface $eventDispatcher)
{
$classId = $request->get('id');
$class = DataObject\ClassDefinition::getById($classId);
Expand Down Expand Up @@ -103,7 +108,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request)
}
}

$this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result);
$this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result, $eventDispatcher);

return $this->jsonResponse($result);
}
Expand All @@ -114,7 +119,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): void
{
$displayMode = $this->getClassificationDisplayMode();

Expand All @@ -123,6 +128,7 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D
}

$enrichment = false;
$grouped = $this->getClassificationGroupedDisplay();
if ($displayMode == ColumnConfigDisplayMode::DATA_OBJECT || $displayMode == ColumnConfigDisplayMode::RELEVANT) {
$targetObjectId = $request->get('target_oid');

Expand All @@ -142,7 +148,47 @@ 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();
mcop1 marked this conversation as resolved.
Show resolved Hide resolved
$targetObjectId = intval($request->get('target_oid'));
$targetObject = DataObject\Concrete::getById($targetObjectId);
$tmpObject = new $classString();
$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 +226,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';
}
Loading