mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-22 03:11:30 +00:00
Handle linter errors, add missing changes in TagFinder
This commit is contained in:
parent
3a3ad1e147
commit
adf95f6f84
3 changed files with 20 additions and 15 deletions
|
|
@ -140,8 +140,8 @@ class SelectAPIController extends AbstractController
|
|||
#[Route(path: '/tag', name: 'select_tag')]
|
||||
public function getResponseForTags(EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$tf = new TagFinder($entityManager, ['min_keyword_length' => 2, 'query_limit' => 250]);
|
||||
$list = $tf->listTags('__'); // return every tag with at least two characters!
|
||||
$tf = new TagFinder($entityManager);
|
||||
$list = $tf->listTags('__', ['min_keyword_length' => 2, 'query_limit' => 250]); // return every tag with at least two characters!
|
||||
|
||||
$entries = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
|
|||
}
|
||||
|
||||
return new RedirectResponse(
|
||||
$this->urlGenerator->generate($target_id !== 0 && $target_id !== null ? 'label_dialog_profile' : 'label_dialog', [
|
||||
$this->urlGenerator->generate($target_id !== null && intval($target_id) !== 0 ? 'label_dialog_profile' : 'label_dialog', [
|
||||
'profile' => $target_id,
|
||||
'target_id' => $targets,
|
||||
'generate' => '1',
|
||||
|
|
@ -107,7 +107,7 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
|
|||
$matches = [];
|
||||
if (preg_match('/^export_(json|yaml|xml|csv)$/', $action, $matches)) {
|
||||
$ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts));
|
||||
$level = match ($target_id) {
|
||||
$level = match (intval($target_id)) {
|
||||
2 => 'extended',
|
||||
3 => 'full',
|
||||
default => 'simple',
|
||||
|
|
|
|||
|
|
@ -50,7 +50,21 @@ class TagFinder
|
|||
{
|
||||
$results = [];
|
||||
$keyword_regex = '/^'.preg_quote($keyword, '/').'/';
|
||||
$possible_tags = $this->listTags($keyword, $options);
|
||||
|
||||
//Iterate over each possible tags (which are comma separated) and extract tags which match our keyword
|
||||
foreach ($possible_tags as $tags) {
|
||||
$tags = explode(',', (string) $tags['tags']);
|
||||
$results = array_merge($results, preg_grep($keyword_regex, $tags));
|
||||
}
|
||||
|
||||
$results = array_unique($results);
|
||||
//Limit the returned tag count to specified value.
|
||||
return array_slice($results, 0, $options['return_limit']);
|
||||
}
|
||||
|
||||
public function listTags(string $keyword, array $options = []): array
|
||||
{
|
||||
$resolver = new OptionsResolver();
|
||||
$this->configureOptions($resolver);
|
||||
|
||||
|
|
@ -71,19 +85,10 @@ class TagFinder
|
|||
//->orderBy('RAND()')
|
||||
->setParameter(1, '%'.$keyword.'%');
|
||||
|
||||
$possible_tags = $qb->getQuery()->getArrayResult();
|
||||
|
||||
//Iterate over each possible tags (which are comma separated) and extract tags which match our keyword
|
||||
foreach ($possible_tags as $tags) {
|
||||
$tags = explode(',', (string) $tags['tags']);
|
||||
$results = array_merge($results, preg_grep($keyword_regex, $tags));
|
||||
}
|
||||
|
||||
$results = array_unique($results);
|
||||
//Limit the returned tag count to specified value.
|
||||
return array_slice($results, 0, $options['return_limit']);
|
||||
return $qb->getQuery()->getArrayResult();
|
||||
}
|
||||
|
||||
|
||||
protected function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue