Part-DB.Part-DB-server/src/Services/LogSystem/HistoryHelper.php

87 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2022-11-29 21:21:26 +01:00
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* 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.
*
* 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
* GNU Affero General Public License for more details.
*
* 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/>.
*/
2020-03-15 13:56:31 +01:00
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
2022-11-29 22:28:53 +01:00
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* 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.
*
* 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
* GNU Affero General Public License for more details.
*
* 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/>.
*/
namespace App\Services\LogSystem;
2020-03-04 21:09:01 +01:00
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
2022-08-14 19:32:53 +02:00
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Part;
class HistoryHelper
{
public function __construct()
{
}
/**
2020-03-29 23:13:25 +02:00
* Returns an array containing all elements that are associated with the argument.
* The returned array contains the given element.
2020-03-15 13:56:31 +01:00
*
2022-08-14 19:32:53 +02:00
* @psalm-return array<AbstractParameter|array-key, mixed>
*/
public function getAssociatedElements(AbstractDBElement $element): array
{
$array = [$element];
2020-03-04 21:09:01 +01:00
if ($element instanceof AttachmentContainingDBElement) {
$array = array_merge($array, $element->getAttachments()->toArray());
}
if ($element instanceof Part) {
$array = array_merge(
$array,
$element->getPartLots()->toArray(),
$element->getOrderdetails()->toArray()
);
foreach ($element->getOrderdetails() as $orderdetail) {
$array = array_merge($array, $orderdetail->getPricedetails()->toArray());
}
}
if ($element instanceof Part || $element instanceof AbstractStructuralDBElement) {
$array = array_merge($array, $element->getParameters()->toArray());
}
return $array;
}
2020-03-15 13:56:31 +01:00
}