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

[Index] introduce iterator interpreter #802

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\IndexBundle\Form\Type\Interpreter;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

final class IteratorInterpreterType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('interpreter', InterpreterType::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ core_shop_index:
index_interpreter_nested_relational: '/bundles/coreshopindex/pimcore/js/index/interpreters/nestedrelational.js'
index_interpreter_objectproperty: '/bundles/coreshopindex/pimcore/js/index/interpreters/objectproperty.js'
index_interpreter_expression: '/bundles/coreshopindex/pimcore/js/index/interpreters/expression.js'
index_interpreter_iterator: '/bundles/coreshopindex/pimcore/js/index/interpreters/iterator.js'
index_interpreter_objecttype: '/bundles/coreshopindex/pimcore/js/index/objecttype/abstract.js'
index_worker_abstract: '/bundles/coreshopindex/pimcore/js/index/worker/abstract.js'
index_worker_mysql: '/bundles/coreshopindex/pimcore/js/index/worker/mysql.js'
Expand All @@ -41,4 +42,4 @@ core_shop_index:
index: '/bundles/coreshopindex/pimcore/css/index.css'
editmode_js:
core_extension_document_tag_filter: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopFilter.js'
core_extension_document_tag_index: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopIndex.js'
core_extension_document_tag_index: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopIndex.js'
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ services:
tags:
- { name: coreshop.index.interpreter, type: nestedRelational, form-type: CoreShop\Bundle\IndexBundle\Form\Type\Interpreter\NestedInterpreterType}

coreshop.index.interpreter.iterator:
class: CoreShop\Component\Index\Interpreter\IteratorInterpreter
arguments:
- '@coreshop.registry.index.interpreter'
tags:
- { name: coreshop.index.interpreter, type: iterator, form-type: CoreShop\Bundle\IndexBundle\Form\Type\Interpreter\IteratorInterpreterType}

# Index Column Types
coreshop.index.column_type.classification_store:
class: CoreShop\Bundle\IndexBundle\Form\Type\Column\IndexColumnTypeClassificationStoreType
Expand Down Expand Up @@ -277,4 +284,4 @@ services:
class: CoreShop\Component\Index\Service\IndexUpdaterService
arguments:
- '@coreshop.repository.index'
- '@coreshop.registry.index.worker'
- '@coreshop.registry.index.worker'
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/**
* Import Definitions.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
*/

pimcore.registerNS('coreshop.index.interpreters.iterator');

coreshop.index.interpreters.iterator = Class.create(coreshop.index.interpreters.abstract, {
getStore: function() {
return pimcore.globalmanager.get('coreshop_index_interpreters');
},

getClassItem: function() {
return coreshop.index.interpreters;
},

getForm: function (record, config) {
this.interpreterPanel = new Ext.form.FormPanel({
defaults: { anchor: '90%' },
layout: 'form',
title: t('coreshop_index_interpreter_settings'),
border: true,
hidden: true
});

this.getStore().clearFilter();

this.interpreterTypeCombo = new Ext.form.ComboBox({
fieldLabel : t('coreshop_index_field_interpreter'),
name : 'interpreter',
length : 255,
value : config && config.interpreter ? config.interpreter.type : null,
store : this.getStore(),
valueField : 'name',
displayField : 'name',
queryMode : 'local',
listeners : {
change : function (combo, newValue) {
this.interpreterPanel.removeAll();

this.getInterpreterPanelLayout(newValue, record, config, {});
}.bind(this)
}
});

this.interpreterContainer = new Ext.Panel({
autoScroll: true,
forceLayout: true,
items: [
this.interpreterTypeCombo,
this.interpreterPanel
],
border: false
});

if (config && config.interpreter && config.interpreter.type) {
this.getInterpreterPanelLayout(config.interpreter.type, record, config, config.interpreter.interpreterConfig);
}

return this.interpreterContainer;
},

destroy: function () {
if (this.interpreterContainer) {
this.interpreterContainer.destroy();
}
},

getInterpreterPanelLayout : function (type, record, parentConfig, config) {
if (type) {
type = type.toLowerCase();
var classItem = this.getClassItem();

if (classItem[type]) {
this.interpreter = new classItem[type];

this.interpreterPanel.add(this.interpreter.getForm(record, Ext.isObject(config) ? config : {}, parentConfig));
this.interpreterPanel.show();
} else {
this.interpreterPanel.hide();

this.interpreter = null;
}
} else {
this.interpreterPanel.hide();
}
},

isValid: function() {
if (!this.interpreter) {
return false;
}

return this.interpreter.isValid();
},

getInterpreterData: function () {
// get defined conditions
if (this.interpreter) {
var interpreterConfig = {};
var interpreterForm = this.interpreterPanel.getForm();

if (Ext.isFunction(this.interpreter.getInterpreterData)) {
interpreterConfig = this.interpreter.getInterpreterData();
}
else {
Ext.Object.each(interpreterForm.getFieldValues(), function (key, value) {
interpreterConfig[key] = value;
}.bind(this));
}

return {
interpreter: {
interpreterConfig: interpreterConfig,
type: this.interpreterTypeCombo.getValue()
}
};
}

return {};
}
});
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/**
* Import Definitions.
*
* LICENSE
/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*
*/


pimcore.registerNS('coreshop.index.interpreters.nested');

coreshop.index.interpreters.nested = Class.create(coreshop.index.interpreters.abstract, {
getForm: function (record, interpreterConfig) {
// init
var _this = this;
var addMenu = [];
var records = pimcore.globalmanager.get('coreshop_index_interpreters').getRange().map(function(interpreter) {return interpreter.get('type')});
var store = pimcore.globalmanager.get('coreshop_index_interpreters').getRange();

store.clearFilter();

var records = store.map(function(interpreter) {return interpreter.get('type')});

Ext.each(records, function (interpreter) {
if (interpreter === 'abstract')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Import Definitions.
*
* LICENSE
/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*
*/


pimcore.registerNS('coreshop.index.interpreters.nestedcontainer');

coreshop.index.interpreters.nestedcontainer = Class.create({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Import Definitions.
*
* LICENSE
/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*
*/


pimcore.registerNS('coreshop.index.interpreters.nestedlocalized');

coreshop.index.interpreters.nestedlocalized = Class.create(coreshop.index.interpreters.nested, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/**
* Import Definitions.
*
* LICENSE
/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*
*/

pimcore.registerNS('coreshop.index.interpreters.nestedrelational');

coreshop.index.interpreters.nestedrelational = Class.create(coreshop.index.interpreters.nested, {

});
54 changes: 54 additions & 0 deletions src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\Index\Interpreter;

use CoreShop\Component\Index\Model\IndexableInterface;
use CoreShop\Component\Index\Model\IndexColumnInterface;
use CoreShop\Component\Registry\ServiceRegistryInterface;
use Webmozart\Assert\Assert;

final class IteratorInterpreter implements InterpreterInterface
{
/**
* @var ServiceRegistryInterface
*/
private $interpreterRegistry;

/**
* @param ServiceRegistryInterface $interpreterRegistry
*/
public function __construct(ServiceRegistryInterface $interpreterRegistry)
{
$this->interpreterRegistry = $interpreterRegistry;
}

/**
* {@inheritdoc}
*/
public function interpret($value, IndexableInterface $indexable, IndexColumnInterface $config, $interpreterConfig = [])
{
Assert::isArray($value, 'IteratorInterpreter can only be used with array values');

$interpreter = $interpreterConfig['interpreter'];
/**
* @var InterpreterInterface $interpreterObject
*/
$interpreterObject = $this->interpreterRegistry->get($interpreter['type']);

foreach ($value as &$val) {
$val = $interpreterObject->interpret($val, $indexable, $config, $interpreter['interpreterConfig']);
}

return $value;
}
}