Skip to content

Commit

Permalink
Merge pull request #21 from DivanteLtd/feature/calculated-fields
Browse files Browse the repository at this point in the history
Calculated fields and fixes
  • Loading branch information
t-zilla authored Nov 12, 2020
2 parents 38236b4 + 51c3f84 commit 7e0cf9d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ protected function getFieldOperators(): array
{
return [
['fieldName' => 'contains_related', 'fieldLabel' => 'bundle_advancedSearch_character_operator_contain'],
['fieldName' => 'not_contain_related', 'fieldLabel' => 'bundle_advancedSearch_character_operator_not_contain'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,12 @@ pimcore.bundle.advancedSearch.searchConfig.fieldConditionPanel.numeric = Class.c
},

getFilterValues: function() {

var filterEntryData = {},
operator = "must",
operatorFieldValue = this.operatorField.getValue();

if(operatorFieldValue == "eq") {
filterEntryData = this.termField.getValue()
} else {
filterEntryData[operatorFieldValue] = this.termField.getValue();
}

if(operatorFieldValue == "exists" || operatorFieldValue == "not_exists") {
operator = operatorFieldValue;
}

return {
fieldname: this.fieldSelectionInformation.fieldName,
filterEntryData: filterEntryData,
operator: operator,
filterEntryData: this.termField.getValue(),
operator: this.operatorField.getValue(),
ignoreInheritance: this.inheritanceField.getValue()
};

}

});
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,7 @@ pimcore.bundle.advancedSearch.searchConfig.resultPanel = Class.create(pimcore.ob
]
});


this.pagingtoolbar = Ext.create("Ext.PagingToolbar", {
pageSize: itemsPerPage,
store: this.store,
displayInfo: true,
displayMsg: '{0} - {1} / {2}',
emptyMsg: t("no_objects_found")
});
this.pagingtoolbar = pimcore.helpers.grid.buildDefaultPagingToolbar(this.store, {pageSize: itemsPerPage});

this.languageInfo = new Ext.Toolbar.TextItem({
text: t("grid_current_language") + ": " + pimcore.available_languages[this.gridLanguage]
Expand Down
11 changes: 4 additions & 7 deletions src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ pimcore.bundle.advancedSearch = Class.create(pimcore.plugin.admin, {
pimcoreReady: function (params, broker) {
var perspectiveCfg = pimcore.globalmanager.get("perspective");
var user = pimcore.globalmanager.get("user");

if (user.roles.length === 0 || user.roles.includes("3")) {
var searchMenu = pimcore.globalmanager.get("layout_toolbar").searchMenu;
if (searchMenu && perspectiveCfg.inToolbar("search.advancedSearch")) {
Ext.get('pimcore_menu_search').insertSibling('<li id="pimcore_menu_advanced_search" data-menu-tooltip="Advanced search" class="pimcore_bundle_nav_icon_advancedSearch pimcore_menu_item pimcore_menu_needs_children"></li>', 'after');
pimcore.bundle.advancedSearch.helper.rebuildAdvancedSearchMenu();
}
var searchMenu = pimcore.globalmanager.get("layout_toolbar").searchMenu;
if (searchMenu && perspectiveCfg.inToolbar("search.advancedSearch")) {
Ext.get('pimcore_menu_search').insertSibling('<li id="pimcore_menu_advanced_search" data-menu-tooltip="Advanced search" class="pimcore_bundle_nav_icon_advancedSearch pimcore_menu_item pimcore_menu_needs_children"></li>', 'after');
pimcore.bundle.advancedSearch.helper.rebuildAdvancedSearchMenu();
}
}
});
Expand Down
39 changes: 37 additions & 2 deletions src/AdvancedSearchBundle/Service/FilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class FilterService
'expression' => '%s LIKE ?',
'data' => '%,_data_,%',
],
'not_contain_related' => [
'expression' => 'NOT (%s LIKE ?) OR %s IS NULL',
'data' => '%,_data_,%',
],
];

/**
Expand Down Expand Up @@ -126,16 +130,47 @@ public function __construct(
public function getFieldDefinitionAdapter(ClassDefinition\Data $fieldDefinition, bool $considerInheritance)
{
$adapter = null;
$fieldType = $fieldDefinition->fieldtype;

if ($fieldDefinition instanceof ClassDefinition\Data\CalculatedValue) {
$fieldType = $this->getCalculatedValueFieldType($fieldDefinition);
}

if ($this->filterLocator->has($fieldDefinition->fieldtype)) {
$adapter = $this->filterLocator->get($fieldDefinition->fieldtype);
if ($this->filterLocator->has($fieldType)) {
$adapter = $this->filterLocator->get($fieldType);
$adapter->setConsiderInheritance($considerInheritance);
$adapter->setFieldDefinition($fieldDefinition);
}

return $adapter;
}

private function getCalculatedValueFieldType(ClassDefinition\Data\CalculatedValue $fieldDefinition): ?string
{
$calculatorClass = $fieldDefinition->getCalculatorClass();
if (!$calculatorClass) {
return null;
}

$reflection = new \ReflectionClass($calculatorClass);
if (!$reflection->hasMethod('compute')) {
return null;
}

$method = $reflection->getMethod('compute');
if (!$method->hasReturnType()) {
return 'input';
}

$map = [
'bool' => 'checkbox',
'int' => 'numeric',
'float' => 'numeric',
'string' => 'input',
];
return $map[strtolower($method->getReturnType())] ?? 'input';
}

/**
* returns selectable fields with their type information for search frontend
*
Expand Down

0 comments on commit 7e0cf9d

Please sign in to comment.