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 quarantine filter in customer grid #37

Merged
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
48 changes: 48 additions & 0 deletions src/Form/Type/Filter/QuarantineFilterType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of Monsieur Biz' Anti Spam plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusAntiSpamPlugin\Form\Type\Filter;

use MonsieurBiz\SyliusAntiSpamPlugin\Entity\QuarantineItemInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class QuarantineFilterType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
'choices' => [
'monsieurbiz_anti_spam.ui.suspected' => QuarantineItemInterface::LEVEL_SUSPECTED,
'monsieurbiz_anti_spam.ui.proven' => QuarantineItemInterface::LEVEL_PROVEN,
'monsieurbiz_anti_spam.ui.likely' => QuarantineItemInterface::LEVEL_LIKELY,
],
'data_class' => null,
'required' => false,
'placeholder' => 'sylius.ui.all',
])
;
}

public function getParent(): string
{
return ChoiceType::class;
}

public function getBlockPrefix(): string
{
return 'monsieurbiz_anti_spam_grid_filter_quarantine';
}
}
39 changes: 39 additions & 0 deletions src/Grid/Filter/QuarantineFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Monsieur Biz' Anti Spam plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusAntiSpamPlugin\Grid\Filter;

use Sylius\Component\Grid\Data\DataSourceInterface;
use Sylius\Component\Grid\Filtering\FilterInterface;

final class QuarantineFilter implements FilterInterface
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameters)
*
* @param mixed $data
*/
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void
{
if (empty($data)) {
return;
}

$expressions = [
$dataSource->getExpressionBuilder()->isNotNull('quarantineItem'),
$dataSource->getExpressionBuilder()->equals('quarantineItem.level', $data),
$dataSource->getExpressionBuilder()->isNull('quarantineItem.liftedAt'),
];
$dataSource->restrict($dataSource->getExpressionBuilder()->andX(...$expressions));
}
}
13 changes: 10 additions & 3 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ services:
autowire: true
autoconfigure: true
public: false
bind :
bind :
$karserRecaptcha3Enabled: '%karser_recaptcha3.enabled%'

MonsieurBiz\SyliusAntiSpamPlugin\:
resource: '../../*'
exclude: '../../{Entity,Migrations}'

monsieurbiz.anti_spam.validators.registry: '@MonsieurBiz\SyliusAntiSpamPlugin\Registry\ValidatorsRegistry'

monsieurbiz.anti_spam.quarantineable.registry:
class: Sylius\Component\Registry\ServiceRegistry
arguments:
Expand All @@ -33,7 +33,7 @@ services:
tags:
- name: 'doctrine.event_listener'
event: 'prePersist'

MonsieurBiz\SyliusAntiSpamPlugin\EventListener\QuarantineInitializeUpdateListener:
tags:
- { name: kernel.event_listener, event: monsieurbiz_anti_spam.quarantine_item.initialize_update }
Expand All @@ -54,3 +54,10 @@ services:
MonsieurBiz\SyliusAntiSpamPlugin\Validator\ReCaptcha3Validator:
arguments:
$routesToCheck: '%monsieurbiz.anti_spam.recaptcha_validator.routes_to_check%'

MonsieurBiz\SyliusAntiSpamPlugin\Grid\Filter\QuarantineFilter:
tags:
- name: sylius.grid_filter
type: quarantine
form_type: MonsieurBiz\SyliusAntiSpamPlugin\Form\Type\Filter\QuarantineFilterType

9 changes: 9 additions & 0 deletions src/Resources/config/sylius/grid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ sylius_grid:
templates:
action:
updateQuarantine: "@MonsieurBizSyliusAntiSpamPlugin/Admin/Grid/Action/update_quarantine.html.twig"
filter:
quarantine: '@MonsieurBizSyliusAntiSpamPlugin/Admin/Grid/Filter/quarantine.html.twig'
grids:
sylius_admin_customer:
fields:
Expand All @@ -11,3 +13,10 @@ sylius_grid:
path: quarantineItem
options:
template: '@MonsieurBizSyliusAntiSpamPlugin/Admin/Grid/Field/quarantine_item.html.twig'
filters:
quarantine:
type: quarantine
label: monsieurbiz_anti_spam.ui.quarantine
enabled: true
options:
field: quarantineItem
3 changes: 3 additions & 0 deletions src/Resources/views/Admin/Grid/Filter/quarantine.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% form_theme form '@SyliusUi/Form/theme.html.twig' %}

{{ form_row(form, {'label': filter.label}) }}
Loading