-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add quarantine filter in customer grid
- Loading branch information
Showing
5 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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) | ||
*/ | ||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) }} |