mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 19:34:31 +02:00
Added possibility to define alternative names on data structures
This can be used to find elements, based on the data returned by info providers
This commit is contained in:
parent
edc54aaf91
commit
b74ab18a6d
11 changed files with 79 additions and 5 deletions
|
@ -419,4 +419,34 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comma separated list of alternative names.
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAlternativeNames(): ?string
|
||||
{
|
||||
if ($this->alternative_names === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Remove trailing comma
|
||||
return rtrim($this->alternative_names, ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a comma separated list of alternative names.
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlternativeNames(?string $new_value): self
|
||||
{
|
||||
//Add a trailing comma, if not already there (makes it easier to find in the database)
|
||||
if (is_string($new_value) && substr($new_value, -1) !== ',') {
|
||||
$new_value .= ',';
|
||||
}
|
||||
|
||||
$this->alternative_names = $new_value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Form\AdminPages;
|
||||
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use App\Entity\Base\AbstractNamedDBElement;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
|
@ -111,6 +114,19 @@ class BaseEntityAdminForm extends AbstractType
|
|||
);
|
||||
}
|
||||
|
||||
if ($entity instanceof AbstractStructuralDBElement && !($entity instanceof Group || $entity instanceof Project || $entity instanceof Currency)) {
|
||||
$builder->add('alternative_names', TextType::class, [
|
||||
'required' => false,
|
||||
'label' => 'entity.edit.alternative_names.label',
|
||||
'help' => 'entity.edit.alternative_names.help',
|
||||
'empty_data' => null,
|
||||
'attr' => [
|
||||
'class' => 'tagsinput',
|
||||
'data-controller' => 'elements--tagsinput',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
$this->additionalFormElements($builder, $options, $entity);
|
||||
|
||||
//Attachment section
|
||||
|
|
|
@ -209,17 +209,17 @@ class StructuralDBElementRepository extends NamedDBElementRepository
|
|||
return $result[0];
|
||||
}
|
||||
|
||||
/*//If we have no result, try to find the element by additional names
|
||||
//If we have no result, try to find the element by alternative names
|
||||
$qb = $this->createQueryBuilder('e');
|
||||
//Use lowercase conversion to be case-insensitive
|
||||
$qb->where($qb->expr()->like('LOWER(e.additional_names)', 'LOWER(:name)'));
|
||||
$qb->setParameter('name', '%'.$name.'%');
|
||||
$qb->where($qb->expr()->like('LOWER(e.alternative_names)', 'LOWER(:name)'));
|
||||
$qb->setParameter('name', '%'.$name.',%');
|
||||
|
||||
$result = $qb->getQuery()->getResult();
|
||||
|
||||
if (count($result) === 1) {
|
||||
if (count($result) >= 1) {
|
||||
return $result[0];
|
||||
}*/
|
||||
}
|
||||
|
||||
//If we find nothing, return null
|
||||
return null;
|
||||
|
@ -247,6 +247,9 @@ class StructuralDBElementRepository extends NamedDBElementRepository
|
|||
$entity = new $class;
|
||||
$entity->setName($name);
|
||||
|
||||
//Set the found name to the alternative names, so the entity can be easily renamed later
|
||||
$entity->setAlternativeNames($name);
|
||||
|
||||
$this->setNewEntityToCache($entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -265,6 +265,7 @@ final class DTOtoEntityConverter
|
|||
//If the entity was newly created, set the file filter
|
||||
if ($tmp->getId() === null) {
|
||||
$tmp->setFiletypeFilter('application/pdf');
|
||||
$tmp->setAlternativeNames(self::TYPE_DATASHEETS_NAME);
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
|
@ -282,6 +283,7 @@ final class DTOtoEntityConverter
|
|||
//If the entity was newly created, set the file filter
|
||||
if ($tmp->getId() === null) {
|
||||
$tmp->setFiletypeFilter('image/*');
|
||||
$tmp->setAlternativeNames(self::TYPE_DATASHEETS_NAME);
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue