Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d6a3753
work in progress
Feb 19, 2021
a659db9
added filterTypes to backend selection
Feb 22, 2021
630d399
added difference between initial and not initial filters
Feb 22, 2021
9ae57b5
refactored context assignemnt
Feb 26, 2021
84b2e07
refactoring
Feb 26, 2021
1a29079
fixed selecting of intial palette
Feb 26, 2021
f891273
added template, started orm filter query
Apr 1, 2021
a2605e6
working on querybuilder
Apr 7, 2021
ef3e234
added querybuilder where for TextFilterType
Apr 12, 2021
4730781
added processing of queryParts
Apr 13, 2021
fbf0997
text-type working
Apr 15, 2021
ae8d55c
added basic choice_type
Apr 16, 2021
bb96233
added more configuration options for choice type
Apr 16, 2021
c8a1360
working on datetimetype
Apr 16, 2021
900ad15
added whereQueryBuilder merhod to QueryPart class, working on dateTim…
Apr 19, 2021
79c4658
removed queryBuilder from FilterTypeContext, added dca to FilterQuery…
Apr 19, 2021
7dd779f
first buttonType implementation
Apr 19, 2021
2efd6ba
added html5 to datetimeType, working button type
Apr 20, 2021
b6dd843
fixed resetButton to be submitButton, and still reset the form
Apr 20, 2021
c477fa4
refactored queryPart and queryPartProcessor
Apr 20, 2021
2d80b5e
added visual improvements to filterTypes
Apr 21, 2021
153b433
refactoring and fixing datetimeTyp
Apr 22, 2021
5085895
fixed code style
Apr 22, 2021
33c4fcc
fixed datetime format issue, to break form on wrong data value
Apr 22, 2021
4b06c14
fixed data option for choiceType
Apr 22, 2021
e491887
fixed code style
Apr 22, 2021
58cce7e
refactored FilterTypeContext, FilterQueryPart, FilterQueryProcessor, …
Apr 23, 2021
5ca0331
added deprecations
Apr 23, 2021
ca4cc6b
added initialValue and initialValueType
Apr 23, 2021
6c5d439
added intial filter handling, added new filter option for overriding …
Apr 27, 2021
254864a
fixed corruption of DateTimeType by passing wrong value to formBuilder
Apr 27, 2021
a12015f
merged master
Apr 27, 2021
a4c5831
fixed wrong indent in service yml
Apr 27, 2021
2095107
refactored type and reordered new classes
Apr 29, 2021
6a58d73
refactored deprecated options on type dropdown
Apr 29, 2021
3458736
refactored defaultOperator for legacy types
Apr 29, 2021
248758c
fixed error not retrieving correct pageId on multiple following async…
Apr 29, 2021
a17c2d2
refactored is null issue fix
Apr 29, 2021
b027462
fixed async form submit, adjusted choiceType for form reset
Apr 30, 2021
eeb386c
added github actions
Apr 30, 2021
1d4dc64
added tests for TextType and FilterQueryPart
May 3, 2021
a70d0cc
fixed and added tests for FilterQueryPartCollection
May 4, 2021
78c5d23
added more options to choiceType
May 4, 2021
0b7754f
refactored initialValueChoices
May 4, 2021
580b28f
fixed corrupted options array for filterTypes
May 4, 2021
89e52f1
added translation and deprecated all old filtertypes
Jun 25, 2021
3d60c19
fixed initial value of choice
Jun 28, 2021
0ed1dd0
fixed method signatures
Jun 28, 2021
c70f436
excluded test for deprecated files
Jun 28, 2021
9bbb4bd
translation changes
Jul 23, 2021
355d526
fixed choice_type when initial
Nov 22, 2021
9da534e
added initialValues to dateTime type
Nov 23, 2021
9d72dff
added initial values to text type
Nov 23, 2021
af7a2ae
working on tests
Dec 1, 2021
c26d540
fixed filters if legacy and new filter are mixed on one page
Dec 6, 2021
364a69d
merged master
Dec 6, 2021
a880a81
refactored service loading in FilterTypes to ServiceSubscriber for be…
koertho Dec 7, 2021
8e5accf
added psr/container to dependencies
koertho Dec 7, 2021
6b8b8f5
fix tests
koertho Dec 7, 2021
ea3e9f6
added missing method to FilterTypeInterface and added return types
koertho Dec 7, 2021
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
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on: [ push ]

jobs:
tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ 7.1, 7.2., 7.3, 7.4 ]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
tools: phpunit
coverage: none

- name: Checkout
uses: actions/checkout@v2

- name: Install the dependencies
run: composer install --no-interaction

- name: Run the unit tests
run: php vendor/bin/phpunit -c phpunit.xml.dist --colors=always

coverage:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
coverage: xdebug
tools: php-cs-fixer, phpunit

- name: Checkout
uses: actions/checkout@v2

- name: Install the dependencies
run: composer install --no-interaction

- name: Generate the coverage report
run: php vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml

- name: Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ This bundle offers a generic filter module to use with arbitrary contao entities
- Label/Message handling using symfony translations
- Render form always empty (without user selection)
- Merge data over multiple filter forms with same form name
- Default Values (can be overwritten by user)
- Initial Values (can`t be overwritten by user)
- Default Values
- Initial Values
- Stores filter data in session (no GET parameter URL remnant)
- Content element "Filter-Preselect" with optional redirect functionality to preselect filter on given page
- Content element "Filter-Hyperlink" with filter preselect feature
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"contao/core-bundle": "^4.4",
"symfony/framework-bundle": "~3.4.26|^4.0",
"heimrichhannot/contao-be_explanation-bundle": "^2.3",
"heimrichhannot/contao-utils-bundle": "^2.0",
"heimrichhannot/contao-utils-bundle": "^2.206",
"heimrichhannot/contao-multi-column-editor-bundle": "^2.0",
"heimrichhannot/contao-fieldpalette-bundle": ">=0.2 <2.0-dev",
"heimrichhannot/contao-entity-filter-bundle": "^1.5",
Expand All @@ -17,7 +17,8 @@
"twig/extensions": "^1.5",
"heimrichhannot/truncate-html": "^1.0",
"symfony/form": "~3.4|~4.0",
"ext-pdo": "*"
"ext-pdo": "*",
"psr/container": "^1.0 || ^2.0"
},
"require-dev": {
"contao/core-bundle": "4.4.*",
Expand Down
10 changes: 10 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@
<ini name="display_startup_errors" value="1"/>
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<testsuites>
<testsuite name="Unit Tests">
<directory>./tests</directory>
<exclude>./tests/Backend</exclude>
<exclude>./tests/Choice</exclude>
<exclude>./tests/Config</exclude>
<exclude>./tests/ContaoManager</exclude>
<exclude>./tests/DependencyInjection</exclude>
<exclude>./tests/Filter/Type</exclude>
<exclude>./tests/Model</exclude>
<exclude>./tests/Module</exclude>
<exclude>./tests/Utils</exclude>
</testsuite>
</testsuites>

Expand Down
9 changes: 5 additions & 4 deletions src/Backend/FilterPreselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Contao\System;
use HeimrichHannot\FilterBundle\Filter\Type\ChoiceType;
use HeimrichHannot\FilterBundle\Model\FilterConfigElementModel;
use HeimrichHannot\FilterBundle\Type\AbstractFilterType;

class FilterPreselect
{
Expand Down Expand Up @@ -48,12 +49,12 @@ public function adjustLabel($row, $label)
$choices = $this->prepareElementChoices((int) $row['id']);

switch ($row['initialValueType']) {
case \HeimrichHannot\FilterBundle\Filter\AbstractType::VALUE_TYPE_SCALAR:
case AbstractFilterType::VALUE_TYPE_SCALAR:
$label = $choices[$row['initialValue']] ?? $row['initialValue'];

break;

case \HeimrichHannot\FilterBundle\Filter\AbstractType::VALUE_TYPE_ARRAY:
case AbstractFilterType::VALUE_TYPE_ARRAY:
$values = array_map(
function ($item) {
return $item['value'] ?? null;
Expand All @@ -65,8 +66,8 @@ function ($item) {

break;

case \HeimrichHannot\FilterBundle\Filter\AbstractType::VALUE_TYPE_CONTEXTUAL:
$label = \HeimrichHannot\FilterBundle\Filter\AbstractType::VALUE_TYPE_CONTEXTUAL;
case AbstractFilterType::VALUE_TYPE_CONTEXTUAL:
$label = AbstractFilterType::VALUE_TYPE_CONTEXTUAL;
}

return sprintf('%s -> %s [ID: %s]', $filterConfigElement->title, $label, $filterConfigElement->id);
Expand Down
2 changes: 1 addition & 1 deletion src/Choice/DateChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function collect()
$dates[$translatedDate] = $translatedDate;
}

krsort($dates, SORT_NUMERIC);
krsort($dates, \SORT_NUMERIC);

return $dates;
}
Expand Down
102 changes: 57 additions & 45 deletions src/Choice/FieldOptionsChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Contao\Widget;
use Doctrine\DBAL\FetchMode;
use HeimrichHannot\FilterBundle\Model\FilterConfigElementModel;
use HeimrichHannot\FilterBundle\Type\FilterTypeCollection;
use HeimrichHannot\UtilsBundle\Choice\AbstractChoice;
use HeimrichHannot\UtilsBundle\Model\ModelUtil;
use Symfony\Component\Translation\Translator;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected function getCustomOptions(FilterConfigElementModel $element, array $fi

$options = StringUtil::deserialize($element->options, true);

return $options;
return $this->adjustOptionLabels($element, $filter, $options);
}

/**
Expand All @@ -129,7 +130,6 @@ protected function getCustomOptions(FilterConfigElementModel $element, array $fi
protected function getDcaOptions(FilterConfigElementModel $element, array $filter, array $dca)
{
$options = [];
$dca = $GLOBALS['TL_DCA'][$filter['dataContainer']]['fields'][$element->field];

if (isset($dca['eval']['isCategoryField']) && $dca['eval']['isCategoryField']) {
if (isset($dca['options_callback'])) {
Expand All @@ -144,10 +144,6 @@ protected function getDcaOptions(FilterConfigElementModel $element, array $filte
return $options;
}

if (!isset($dca['inputType'])) {
return $options;
}

switch ($dca['inputType']) {
case 'cfgTags':
if (!isset($dca['eval']['tagsManager'])) {
Expand All @@ -173,6 +169,13 @@ protected function getWidgetOptions(FilterConfigElementModel $element, array $fi
{
$options = [];

$filterTypeCollection = System::getContainer()->get(FilterTypeCollection::class);

// fix for new filter types to show possible choices if inputType dca attribute is not given
if ($filterTypeCollection->hasType($element->type)) {
$dca['inputType'] = $element->inputType;
}

if (!isset($GLOBALS['TL_FFL'][$dca['inputType']]) && (System::getContainer()->get('huh.utils.container')->isBackend() && !isset($GLOBALS['BE_FFL'][$dca['inputType']]))) {
return $options;
}
Expand Down Expand Up @@ -255,45 +258,7 @@ protected function getWidgetOptions(FilterConfigElementModel $element, array $fi
}
}

if (!empty($options) && true === (bool) $element->adjustOptionLabels && !empty($element->optionLabelPattern)) {
if (null !== ($filterQueryBuilder = System::getContainer()->get('huh.filter.manager')->getQueryBuilder($filter['id'], [$element->id]))) {
$filterQueryBuilder->select([$filter['dataContainer'].'.'.$element->field, $filter['dataContainer'].'.*']);
$filterQueryBuilder->orderBy($element->field);
$rows = $filterQueryBuilder->execute()->fetchAll();

$data = [];

foreach ($rows as $row) {
$currentValue = $row[$element->field];

if (isset($data[$currentValue])) {
++$data[$currentValue]['count'];

continue;
}

$data[$currentValue] = ['data' => $row, 'count' => 1];
}

foreach ($options as $key => &$option) {
if (!isset($option['label']) || !isset($rows[$option['value']])) {
continue;
}

$params = $data[$option['value']];
$params['label'] = $option['label'];

foreach ($params as $key => $value) {
unset($params[$key]);
$params['%'.$key.'%'] = $value;
}

$option['label'] = System::getContainer()->get('translator')->trans($element->optionLabelPattern, $params);
}
}
}

return $options;
return $this->adjustOptionLabels($element, $filter, $options);
}

/**
Expand Down Expand Up @@ -367,4 +332,51 @@ protected function getGroupChoicesValue(array $choices, FilterConfigElementModel

return implode(',', $choices);
}

private function adjustOptionLabels(FilterConfigElementModel $element, array $filter, array $options): array
{
if (!empty($options) && true === (bool) $element->adjustOptionLabels && !empty($element->optionLabelPattern)) {
if (null !== ($filterQueryBuilder = System::getContainer()->get('huh.filter.manager')->getQueryBuilder($filter['id'], [$element->id]))) {
$filterQueryBuilder->select([$filter['dataContainer'].'.'.$element->field, $filter['dataContainer'].'.*']);
$filterQueryBuilder->orderBy($element->field);
$rows = $filterQueryBuilder->execute()->fetchAll();

$data = [];

foreach ($rows as $row) {
$currentValue = $row[$element->field];

if (isset($data[$currentValue])) {
++$data[$currentValue]['count'];

continue;
}

$data[$currentValue] = ['data' => $row, 'count' => 1];
}

foreach ($options as &$option) {
if (!isset($option['label']) || !isset($rows[$option['value']])) {
continue;
}

$params = $data[$option['value']];
$params['label'] = $option['label'];

foreach ($params as $key => $value) {
unset($params[$key]);
$params['%'.$key.'%'] = $value;
}

if (!$params['%count%']) {
$params['%count%'] = 0;
}

$option['label'] = System::getContainer()->get('translator')->trans($element->optionLabelPattern, $params);
}
}
}

return $options;
}
}
Loading