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-13 10:36:34 +02:00
|
|
|
use App\Entity\Attachments\Attachment;
|
|
|
|
|
use App\Entity\Parameters\AbstractParameter;
|
2026-01-02 23:44:20 +00:00
|
|
|
use App\Entity\Contracts\StructuralElementInterface;
|
|
|
|
|
use App\Entity\Contracts\HasParametersInterface;
|
2023-06-11 14:55:06 +02:00
|
|
|
use App\Repository\StructuralDBElementRepository;
|
|
|
|
|
use App\EntityListeners\TreeCacheInvalidationListener;
|
2024-04-28 19:38:39 +02:00
|
|
|
use App\Validator\Constraints\UniqueObjectCollection;
|
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-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;
|
2019-04-06 18:45:26 +02:00
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
2026-01-02 23:44:20 +00:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
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
|
2023-06-13 10:36:34 +02:00
|
|
|
*
|
2024-12-28 22:31:04 +01:00
|
|
|
* @template AT of Attachment
|
|
|
|
|
* @template PT of AbstractParameter
|
2023-06-13 10:36:34 +02:00
|
|
|
* @template-use ParametersTrait<PT>
|
|
|
|
|
* @extends AttachmentContainingDBElement<AT>
|
|
|
|
|
* @uses ParametersTrait<PT>
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2024-03-03 19:57:31 +01:00
|
|
|
#[UniqueEntity(fields: ['name', 'parent'], message: 'structural.entity.unique_name', ignoreNull: false)]
|
2023-06-11 14:55:06 +02:00
|
|
|
#[ORM\MappedSuperclass(repositoryClass: StructuralDBElementRepository::class)]
|
|
|
|
|
#[ORM\EntityListeners([TreeCacheInvalidationListener::class])]
|
2026-01-02 23:44:20 +00:00
|
|
|
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement implements StructuralElementInterface, HasParametersInterface
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
2020-03-11 21:48:47 +01:00
|
|
|
use ParametersTrait;
|
2026-01-02 23:44:20 +00:00
|
|
|
use StructuralElementTrait;
|
2020-01-05 22:49:00 +01:00
|
|
|
|
2023-06-13 10:36:34 +02:00
|
|
|
/**
|
|
|
|
|
* Mapping done in subclasses.
|
|
|
|
|
*
|
|
|
|
|
* @var Collection<int, AbstractParameter>
|
|
|
|
|
* @phpstan-var Collection<int, PT>
|
|
|
|
|
*/
|
2024-03-03 19:57:31 +01:00
|
|
|
#[Assert\Valid]
|
2024-04-28 19:38:39 +02:00
|
|
|
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
|
2023-06-13 10:36:34 +02:00
|
|
|
protected Collection $parameters;
|
|
|
|
|
|
2019-04-11 22:41:21 +02:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2019-08-20 18:39:57 +02:00
|
|
|
parent::__construct();
|
2026-01-02 23:44:20 +00:00
|
|
|
$this->initializeStructuralElement();
|
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-03-20 23:16:07 +01:00
|
|
|
}
|