Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 4675c45

Browse files
author
Teddy Roncin
committed
🐛 (Dependency version) Updated some code to be able to be run with the current version
Some code (in the filters) was outdated and not updated during the rebase
1 parent dce2d41 commit 4675c45

File tree

4 files changed

+100
-97
lines changed

4 files changed

+100
-97
lines changed

composer.lock

Lines changed: 46 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ApiPlatform/IsStudentFilter.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
namespace App\ApiPlatform;
44

5-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
6-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
5+
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
6+
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
7+
use ApiPlatform\Metadata\Operation;
78
use Doctrine\ORM\QueryBuilder;
89

9-
class IsStudentFilter extends AbstractContextAwareFilter
10+
class IsStudentFilter extends AbstractFilter
1011
{
11-
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
12-
{
13-
if ($property !== 'is_student') {
14-
return;
15-
}
16-
$alias = $queryBuilder->getRootAliases()[0];
17-
$queryBuilder->andWhere("{$alias}.studentId ".($value == 'true' ? 'IS NOT' : 'IS').' NULL');
18-
}
19-
2012
public function getDescription(string $resourceClass): array
2113
{
2214
return [
@@ -27,4 +19,13 @@ public function getDescription(string $resourceClass): array
2719
],
2820
];
2921
}
30-
}
22+
23+
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
24+
{
25+
if ('is_student' !== $property) {
26+
return;
27+
}
28+
$alias = $queryBuilder->getRootAliases()[0];
29+
$queryBuilder->andWhere("{$alias}.studentId ".('true' === $value ? 'IS NOT' : 'IS').' NULL');
30+
}
31+
}

src/ApiPlatform/SearchInNamesFilter.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@
22

33
namespace App\ApiPlatform;
44

5-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
6-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
5+
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
6+
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
7+
use ApiPlatform\Metadata\Operation;
78
use Doctrine\ORM\QueryBuilder;
89

9-
class SearchInNamesFilter extends AbstractContextAwareFilter
10+
class SearchInNamesFilter extends AbstractFilter
1011
{
11-
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
12-
{
13-
if ($property !== 'name') {
14-
return;
15-
}
16-
$alias = $queryBuilder->getRootAliases()[0];
17-
$infoAlias = $queryNameGenerator->generateJoinAlias('info');
18-
$queryBuilder
19-
->innerJoin("{$alias}.infos", $infoAlias)
20-
->andWhere("({$alias}.firstName LIKE '%{$value}%' OR {$alias}.lastName LIKE '%{$value}%' OR {$infoAlias}.nickname LIKE '%{$value}%')");
21-
}
22-
2312
public function getDescription(string $resourceClass): array
2413
{
2514
return [
@@ -30,4 +19,17 @@ public function getDescription(string $resourceClass): array
3019
],
3120
];
3221
}
33-
}
22+
23+
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
24+
{
25+
if ('name' !== $property) {
26+
return;
27+
}
28+
$alias = $queryBuilder->getRootAliases()[0];
29+
$infoAlias = $queryNameGenerator->generateJoinAlias('info');
30+
$queryBuilder
31+
->innerJoin("{$alias}.infos", $infoAlias)
32+
->andWhere("({$alias}.firstName LIKE '%{$value}%' OR {$alias}.lastName LIKE '%{$value}%' OR {$infoAlias}.nickname LIKE '%{$value}%')")
33+
;
34+
}
35+
}

0 commit comments

Comments
 (0)