mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Allow to create nested entitiy structures directly from the part edit page.
However there is still a bug, that the newly created entites are not shown as selected (even though they are). Fixes issue #203
This commit is contained in:
parent
1654010ea3
commit
e0c380d81a
3 changed files with 133 additions and 32 deletions
|
@ -89,4 +89,38 @@ class StructuralDBElementRepository extends NamedDBElementRepository
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a structure of AbsstractStructuralDBElements from a path separated by $separator, which splits the various levels.
|
||||
* This function will try to use existing elements, if they are already in the database. If not, they will be created.
|
||||
* An array of the created elements will be returned, with the last element being the deepest element.
|
||||
* @param string $path
|
||||
* @param string $separator
|
||||
* @return AbstractStructuralDBElement[]
|
||||
*/
|
||||
public function getNewEntityFromPath(string $path, string $separator = '->'): array
|
||||
{
|
||||
$parent = null;
|
||||
$result = [];
|
||||
foreach (explode($separator, $path) as $name) {
|
||||
$name = trim($name);
|
||||
if ('' === $name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//See if we already have an element with this name and parent
|
||||
$entity = $this->findOneBy(['name' => $name, 'parent' => $parent]);
|
||||
if (null === $entity) {
|
||||
/** @var AbstractStructuralDBElement $entity */
|
||||
$entity = new ($this->getClassName());
|
||||
$entity->setName($name);
|
||||
$entity->setParent($parent);
|
||||
}
|
||||
|
||||
$result[] = $entity;
|
||||
$parent = $entity;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue