2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
2019-08-12 15:47:57 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
2020-02-22 18:14:36 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2020-02-22 18:14:36 +01:00
|
|
|
* GNU Affero General Public License for more details.
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
2020-02-22 18:14:36 +01:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
namespace App\Entity\Base;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2023-06-11 14:55:06 +02:00
|
|
|
use App\Repository\StructuralDBElementRepository;
|
|
|
|
use App\EntityListeners\TreeCacheInvalidationListener;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Attachments\AttachmentContainingDBElement;
|
2020-03-11 21:48:47 +01:00
|
|
|
use App\Entity\Parameters\ParametersTrait;
|
2019-11-09 00:47:20 +01:00
|
|
|
use App\Validator\Constraints\NoneOfItsChildren;
|
2020-01-05 22:49:00 +01:00
|
|
|
use function count;
|
2019-04-11 22:41:21 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2020-01-02 18:45:41 +01:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2020-01-05 22:49:00 +01:00
|
|
|
use function get_class;
|
|
|
|
use InvalidArgumentException;
|
2019-04-06 18:45:26 +02:00
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
2019-04-07 19:30:42 +02:00
|
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* All elements with the fields "id", "name" and "parent_id" (at least).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
|
|
|
* This class is for managing all database objects with a structural design.
|
|
|
|
* All these sub-objects must have the table columns 'id', 'name' and 'parent_id' (at least)!
|
|
|
|
* The root node has always the ID '0'.
|
|
|
|
* It's allowed to have instances of root elements, but if you try to change
|
|
|
|
* an attribute of a root element, you will get an exception!
|
|
|
|
*
|
2019-04-06 18:45:26 +02:00
|
|
|
*
|
2023-06-11 15:02:59 +02:00
|
|
|
* @see \App\Tests\Entity\Base\AbstractStructuralDBElementTest
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[UniqueEntity(fields: ['name', 'parent'], ignoreNull: false, message: 'structural.entity.unique_name')]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\MappedSuperclass(repositoryClass: StructuralDBElementRepository::class)]
|
|
|
|
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
|
2020-02-01 19:48:07 +01:00
|
|
|
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2020-03-11 21:48:47 +01:00
|
|
|
use ParametersTrait;
|
2020-03-08 22:46:29 +01:00
|
|
|
|
2023-06-11 14:55:06 +02:00
|
|
|
final public const ID_ROOT_ELEMENT = 0;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-01 16:17:20 +01:00
|
|
|
* This is a not standard character, so build a const, so a dev can easily use it.
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2023-06-11 14:55:06 +02:00
|
|
|
final public const PATH_DELIMITER_ARROW = ' → ';
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The comment info for this element
|
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['full', 'import'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::TEXT)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected string $comment = '';
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
/**
|
|
|
|
* @var bool If this property is set, this element can not be selected for part properties.
|
2019-11-09 00:47:20 +01:00
|
|
|
* Useful if this element should be used only for grouping, sorting.
|
2019-08-12 15:47:57 +02:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['full', 'import'])]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\Column(type: Types::BOOLEAN)]
|
2022-09-18 22:59:31 +02:00
|
|
|
protected bool $not_selectable = false;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
2022-09-18 22:59:31 +02:00
|
|
|
protected int $level = 0;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2020-01-05 22:49:00 +01:00
|
|
|
/**
|
2023-04-15 23:14:53 +02:00
|
|
|
* We can not define the mapping here, or we will get an exception. Unfortunately we have to do the mapping in the
|
2020-01-05 22:49:00 +01:00
|
|
|
* subclasses.
|
|
|
|
*
|
2020-02-01 19:48:07 +01:00
|
|
|
* @var AbstractStructuralDBElement[]|Collection
|
2020-01-05 22:49:00 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['include_children'])]
|
2023-04-15 22:25:03 +02:00
|
|
|
protected Collection $children;
|
2020-02-01 19:42:28 +01:00
|
|
|
|
2020-01-05 22:49:00 +01:00
|
|
|
/**
|
2020-02-01 19:48:07 +01:00
|
|
|
* @var AbstractStructuralDBElement
|
2020-01-05 22:49:00 +01:00
|
|
|
* @NoneOfItsChildren()
|
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['include_parents', 'import'])]
|
2023-04-15 22:05:29 +02:00
|
|
|
protected ?AbstractStructuralDBElement $parent = null;
|
2020-01-05 22:49:00 +01:00
|
|
|
|
2023-04-15 23:14:53 +02:00
|
|
|
/** @var string[] all names of all parent elements as an array of strings,
|
2019-04-07 19:30:42 +02:00
|
|
|
* the last array element is the name of the element itself
|
|
|
|
*/
|
2022-09-18 22:59:31 +02:00
|
|
|
private array $full_path_strings = [];
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-04-11 22:41:21 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
2019-08-20 18:39:57 +02:00
|
|
|
parent::__construct();
|
2019-04-11 22:41:21 +02:00
|
|
|
$this->children = new ArrayCollection();
|
2020-03-11 21:48:47 +01:00
|
|
|
$this->parameters = new ArrayCollection();
|
2019-04-11 22:41:21 +02:00
|
|
|
}
|
|
|
|
|
2020-05-13 21:07:50 +02:00
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
if ($this->id) {
|
|
|
|
//Deep clone parameters
|
|
|
|
$parameters = $this->parameters;
|
|
|
|
$this->parameters = new ArrayCollection();
|
|
|
|
foreach ($parameters as $parameter) {
|
|
|
|
$this->addParameter(clone $parameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent::__clone();
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* StructuralDBElement constructor.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Check if this element is a child of another element (recursive).
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2020-02-01 19:48:07 +01:00
|
|
|
* @param AbstractStructuralDBElement $another_element the object to compare
|
2020-03-15 13:56:31 +01:00
|
|
|
* IMPORTANT: both objects to compare must be from the same class (for example two "Device" objects)!
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2020-08-21 21:36:22 +02:00
|
|
|
* @return bool true, if this element is child of $another_element
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2020-01-05 22:49:00 +01:00
|
|
|
* @throws InvalidArgumentException if there was an error
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function isChildOf(self $another_element): bool
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2020-01-05 15:46:58 +01:00
|
|
|
$class_name = static::class;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
2019-09-18 12:48:27 +02:00
|
|
|
//Check if both elements compared, are from the same type
|
|
|
|
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
|
2023-06-11 14:15:46 +02:00
|
|
|
if (!$another_element instanceof $class_name && !is_a($this, $another_element::class)) {
|
2020-01-05 22:49:00 +01:00
|
|
|
throw new InvalidArgumentException('isChildOf() only works for objects of the same type!');
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2023-06-11 14:15:46 +02:00
|
|
|
if (!$this->getParent() instanceof \App\Entity\Base\AbstractStructuralDBElement) { // this is the root node
|
2019-02-23 22:41:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-20 22:53:06 +01:00
|
|
|
|
2023-01-28 23:24:45 +01:00
|
|
|
//If the parent element is equal to the element we want to compare, return true
|
2023-02-05 03:01:25 +01:00
|
|
|
if ($this->getParent()->getID() === null) {
|
2023-01-28 23:24:45 +01:00
|
|
|
//If the IDs are not yet defined, we have to compare the objects itself
|
|
|
|
if ($this->getParent() === $another_element) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-04-15 22:05:29 +02:00
|
|
|
} elseif ($this->getParent()->getID() === $another_element->getID()) {
|
|
|
|
return true;
|
2023-01-28 23:24:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Otherwise, check recursively
|
|
|
|
return $this->parent->isChildOf($another_element);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2019-09-08 16:20:53 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Checks if this element is an root element (has no parent).
|
|
|
|
*
|
2023-04-15 23:14:53 +02:00
|
|
|
* @return bool true if this element is a root element
|
2019-09-08 16:20:53 +02:00
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function isRoot(): bool
|
2019-09-08 16:20:53 +02:00
|
|
|
{
|
2023-06-11 14:15:46 +02:00
|
|
|
return !$this->parent instanceof \App\Entity\Base\AbstractStructuralDBElement;
|
2019-09-08 16:20:53 +02:00
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Getters
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2019-03-18 19:05:41 +01:00
|
|
|
/**
|
|
|
|
* Get the parent of this element.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2020-02-01 19:48:07 +01:00
|
|
|
* @return AbstractStructuralDBElement|null The parent element. Null if this element, does not have a parent.
|
2019-03-18 19:05:41 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getParent(): ?self
|
2019-03-18 19:05:41 +01:00
|
|
|
{
|
|
|
|
return $this->parent;
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* Get the comment of the element.
|
2019-03-28 19:24:34 +01:00
|
|
|
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return string the comment
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-28 19:24:34 +01:00
|
|
|
public function getComment(): ?string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-28 19:24:34 +01:00
|
|
|
return $this->comment;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the level.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-04-07 19:30:42 +02:00
|
|
|
* The level of the root node is -1.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return int the level of this element (zero means a most top element
|
2019-11-10 14:00:56 +01:00
|
|
|
* [a sub element of the root node])
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getLevel(): int
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-11-09 00:47:20 +01:00
|
|
|
/*
|
2019-04-07 19:30:42 +02:00
|
|
|
* Only check for nodes that have a parent. In the other cases zero is correct.
|
|
|
|
*/
|
2023-06-11 14:15:46 +02:00
|
|
|
if (0 === $this->level && $this->parent instanceof \App\Entity\Base\AbstractStructuralDBElement) {
|
2019-02-23 22:41:13 +01:00
|
|
|
$element = $this->parent;
|
2023-06-11 14:15:46 +02:00
|
|
|
while ($element instanceof \App\Entity\Base\AbstractStructuralDBElement) {
|
2020-02-01 19:48:07 +01:00
|
|
|
/** @var AbstractStructuralDBElement $element */
|
2019-02-23 22:41:13 +01:00
|
|
|
$element = $element->parent;
|
2019-03-20 23:16:07 +01:00
|
|
|
++$this->level;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
return $this->level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get the full path.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-11-10 14:00:56 +01:00
|
|
|
* @param string $delimiter the delimiter of the returned string
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-11-10 14:00:56 +01:00
|
|
|
* @return string the full path (incl. the name of this element), delimited by $delimiter
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-11-10 14:00:56 +01:00
|
|
|
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2023-06-11 14:15:46 +02:00
|
|
|
if ($this->full_path_strings === []) {
|
2019-11-09 00:47:20 +01:00
|
|
|
$this->full_path_strings = [];
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->full_path_strings[] = $this->getName();
|
2019-02-24 18:05:06 +01:00
|
|
|
$element = $this;
|
|
|
|
|
2019-03-28 19:24:34 +01:00
|
|
|
$overflow = 20; //We only allow 20 levels depth
|
|
|
|
|
2023-06-11 14:15:46 +02:00
|
|
|
while ($element->parent instanceof \App\Entity\Base\AbstractStructuralDBElement && $overflow >= 0) {
|
2019-02-24 18:05:06 +01:00
|
|
|
$element = $element->parent;
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->full_path_strings[] = $element->getName();
|
2019-03-28 19:24:34 +01:00
|
|
|
//Decrement to prevent mem overflow.
|
2019-11-09 00:47:20 +01:00
|
|
|
--$overflow;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
2019-02-24 18:05:06 +01:00
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->full_path_strings = array_reverse($this->full_path_strings);
|
|
|
|
}
|
|
|
|
|
2019-11-10 14:00:56 +01:00
|
|
|
return implode($delimiter, $this->full_path_strings);
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2019-09-08 16:20:53 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Gets the path to this element (including the element itself).
|
|
|
|
*
|
2019-11-10 14:00:56 +01:00
|
|
|
* @return self[] An array with all (recursively) parent elements (including this one),
|
2019-11-09 00:47:20 +01:00
|
|
|
* ordered from the lowest levels (root node) first to the highest level (the element itself)
|
2019-09-08 16:20:53 +02:00
|
|
|
*/
|
|
|
|
public function getPathArray(): array
|
|
|
|
{
|
|
|
|
$tmp = [];
|
|
|
|
$tmp[] = $this;
|
|
|
|
|
|
|
|
//We only allow 20 levels depth
|
2020-08-21 21:36:22 +02:00
|
|
|
while (!end($tmp)->isRoot() && count($tmp) < 20) {
|
2019-09-08 16:20:53 +02:00
|
|
|
$tmp[] = end($tmp)->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_reverse($tmp);
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
2019-11-10 14:00:56 +01:00
|
|
|
* Get all sub elements of this element.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2020-02-01 19:42:28 +01:00
|
|
|
* @return Collection<static>|iterable all subelements as an array of objects (sorted by their full path)
|
2020-03-29 23:36:53 +02:00
|
|
|
* @psalm-return Collection<int, static>
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-04-11 22:41:21 +02:00
|
|
|
public function getSubelements(): iterable
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2023-03-02 22:55:22 +01:00
|
|
|
//If the parent is equal to this object, we would get an endless loop, so just return an empty array
|
|
|
|
//This is just a workaround, as validator should prevent this behaviour, before it gets written to the database
|
|
|
|
if ($this->parent === $this) {
|
|
|
|
return new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
2022-09-21 13:20:57 +02:00
|
|
|
return $this->children ?? new ArrayCollection();
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
2020-01-02 18:45:41 +01:00
|
|
|
/**
|
2022-09-21 13:20:57 +02:00
|
|
|
* @see getSubelements()
|
2020-02-01 19:42:28 +01:00
|
|
|
* @return Collection<static>|iterable
|
2020-03-29 23:36:53 +02:00
|
|
|
* @psalm-return Collection<int, static>
|
2020-01-02 18:45:41 +01:00
|
|
|
*/
|
2019-04-11 22:41:21 +02:00
|
|
|
public function getChildren(): iterable
|
2019-04-07 19:30:42 +02:00
|
|
|
{
|
2022-09-21 13:20:57 +02:00
|
|
|
return $this->getSubelements();
|
2019-04-07 19:30:42 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 21:47:25 +02:00
|
|
|
public function isNotSelectable(): bool
|
|
|
|
{
|
|
|
|
return $this->not_selectable;
|
|
|
|
}
|
|
|
|
|
2019-02-23 22:41:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Setters
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* Sets the new parent object.
|
|
|
|
*
|
2022-08-14 19:39:07 +02:00
|
|
|
* @param AbstractStructuralDBElement|null $new_parent The new parent object
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2020-02-01 19:48:07 +01:00
|
|
|
* @return AbstractStructuralDBElement
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setParent(?self $new_parent): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2019-03-28 19:24:34 +01:00
|
|
|
/*
|
|
|
|
if ($new_parent->isChildOf($this)) {
|
|
|
|
throw new \InvalidArgumentException('You can not use one of the element childs as parent!');
|
|
|
|
} */
|
|
|
|
|
|
|
|
$this->parent = $new_parent;
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2023-01-30 22:29:20 +01:00
|
|
|
//Add this element as child to the new parent
|
2023-06-11 14:15:46 +02:00
|
|
|
if ($new_parent instanceof \App\Entity\Base\AbstractStructuralDBElement) {
|
2023-01-30 22:29:20 +01:00
|
|
|
$new_parent->getChildren()->add($this);
|
|
|
|
}
|
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Set the comment.
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2023-03-24 22:51:41 +01:00
|
|
|
* @param string $new_comment the new comment
|
2019-11-09 00:47:20 +01:00
|
|
|
*
|
2020-02-01 19:48:07 +01:00
|
|
|
* @return AbstractStructuralDBElement
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2023-03-24 22:51:41 +01:00
|
|
|
public function setComment(string $new_comment): self
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
$this->comment = $new_comment;
|
2019-03-20 23:16:07 +01:00
|
|
|
|
2019-02-24 12:54:11 +01:00
|
|
|
return $this;
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
2019-04-11 22:41:21 +02:00
|
|
|
|
2020-02-01 19:42:28 +01:00
|
|
|
/**
|
2023-01-30 22:29:20 +01:00
|
|
|
* Adds the given element as child to this element.
|
|
|
|
* @param static $child
|
2020-02-01 19:42:28 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2023-01-30 22:29:20 +01:00
|
|
|
public function addChild(self $child): self
|
2019-04-11 22:41:21 +02:00
|
|
|
{
|
2023-01-30 22:29:20 +01:00
|
|
|
$this->children->add($child);
|
|
|
|
//Children get this element as parent
|
|
|
|
$child->setParent($this);
|
|
|
|
return $this;
|
|
|
|
}
|
2019-04-11 22:41:21 +02:00
|
|
|
|
2023-01-30 22:29:20 +01:00
|
|
|
/**
|
|
|
|
* Removes the given element as child from this element.
|
|
|
|
* @param static $child
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function removeChild(self $child): self
|
|
|
|
{
|
|
|
|
$this->children->removeElement($child);
|
|
|
|
//Children has no parent anymore
|
|
|
|
$child->setParent(null);
|
2019-04-11 22:41:21 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-08-12 21:47:25 +02:00
|
|
|
/**
|
2020-02-01 19:48:07 +01:00
|
|
|
* @return AbstractStructuralDBElement
|
2019-08-12 21:47:25 +02:00
|
|
|
*/
|
2019-11-09 00:47:20 +01:00
|
|
|
public function setNotSelectable(bool $not_selectable): self
|
2019-08-12 21:47:25 +02:00
|
|
|
{
|
|
|
|
$this->not_selectable = $not_selectable;
|
2019-11-09 00:47:20 +01:00
|
|
|
|
2019-08-12 21:47:25 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2019-11-09 00:47:20 +01:00
|
|
|
public function clearChildren(): self
|
2019-04-11 22:41:21 +02:00
|
|
|
{
|
|
|
|
$this->children = new ArrayCollection();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|