mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Added autocomplete for part parameters
This commit is contained in:
parent
44b288b807
commit
9a7e47863b
18 changed files with 209 additions and 134 deletions
33
src/Repository/ParameterRepository.php
Normal file
33
src/Repository/ParameterRepository.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
class ParameterRepository extends DBElementRepository
|
||||
{
|
||||
/**
|
||||
* Find parameters using a parameter name
|
||||
* @param string $name The name to search for
|
||||
* @param bool $exact True, if only exact names should match. False, if the name just needs to be contained in the parameter name
|
||||
* @param int $max_results
|
||||
* @return array
|
||||
*/
|
||||
public function autocompleteParamName(string $name, bool $exact = false, int $max_results = 50): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('parameter');
|
||||
|
||||
$qb->distinct()
|
||||
->select('parameter.name')
|
||||
->addSelect('parameter.symbol')
|
||||
->addSelect('parameter.unit')
|
||||
->where('parameter.name LIKE :name');
|
||||
if ($exact) {
|
||||
$qb->setParameter('name', $name);
|
||||
} else {
|
||||
$qb->setParameter('name', '%'.$name.'%');
|
||||
}
|
||||
|
||||
$qb->setMaxResults($max_results);
|
||||
|
||||
return $qb->getQuery()->getArrayResult();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue