Internal: Rename SearchOrFilter to PartialSearchOrFilter + improve query - refs BT#22036

pull/5930/head
Angel Fernando Quiroz Campos 2 weeks ago
parent aec1f0656c
commit d352cd564a
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 4
      src/CoreBundle/Entity/Message.php
  2. 4
      src/CoreBundle/Entity/User.php
  3. 8
      src/CoreBundle/Filter/PartialSearchOrFilter.php

@ -18,7 +18,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Entity\Listener\MessageListener;
use Chamilo\CoreBundle\Filter\SearchOrFilter;
use Chamilo\CoreBundle\Filter\PartialSearchOrFilter;
use Chamilo\CoreBundle\Repository\MessageRepository;
use Chamilo\CoreBundle\State\MessageByGroupStateProvider;
use Chamilo\CoreBundle\State\MessageProcessor;
@ -78,7 +78,7 @@ use Symfony\Component\Validator\Constraints as Assert;
BooleanFilter::class,
properties: ['receivers.read']
)]
#[ApiFilter(SearchOrFilter::class, properties: ['title', 'content'])]
#[ApiFilter(PartialSearchOrFilter::class, properties: ['title', 'content'])]
#[ApiFilter(ExistsFilter::class, properties: ['receivers.deletedAt'])]
class Message
{

@ -18,7 +18,7 @@ use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Controller\Api\UserSkillsController;
use Chamilo\CoreBundle\Entity\Listener\UserListener;
use Chamilo\CoreBundle\Filter\SearchOrFilter;
use Chamilo\CoreBundle\Filter\PartialSearchOrFilter;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\Traits\UserCreatorTrait;
use Chamilo\CourseBundle\Entity\CGroupRelTutor;
@ -78,7 +78,7 @@ use UserManager;
'lastname' => 'partial',
]
)]
#[ApiFilter(SearchOrFilter::class, properties: ['username', 'firstname', 'lastname'])]
#[ApiFilter(PartialSearchOrFilter::class, properties: ['username', 'firstname', 'lastname'])]
#[ApiFilter(filterClass: BooleanFilter::class, properties: ['isActive'])]
class User implements UserInterface, EquatableInterface, ResourceInterface, ResourceIllustrationInterface, PasswordAuthenticatedUserInterface, LegacyPasswordAuthenticatedUserInterface, ExtraFieldItemInterface, Stringable
{

@ -12,7 +12,7 @@ use ApiPlatform\Metadata\Operation;
use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;
class SearchOrFilter extends AbstractFilter
class PartialSearchOrFilter extends AbstractFilter
{
protected function filterProperty(
string $property,
@ -32,17 +32,17 @@ class SearchOrFilter extends AbstractFilter
}
$alias = $queryBuilder->getRootAliases()[0];
$valueParameter = $queryNameGenerator->generateParameterName($property);
$valueParameter = ':'.$queryNameGenerator->generateParameterName($property);
$ors = [];
foreach (array_keys($this->properties) as $field) {
$ors[] = $queryBuilder->expr()->like(
"$alias.$field",
":$valueParameter"
(string) $queryBuilder->expr()->concat("'%'", $valueParameter, "'%'")
);
$queryBuilder->setParameter($valueParameter, "%$value%");
$queryBuilder->setParameter($valueParameter, $value);
}
$queryBuilder
Loading…
Cancel
Save