1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace App\Services\LogSystem; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
use App\Entity\Attachments\AttachmentContainingDBElement; |
25
|
|
|
use App\Entity\Base\AbstractDBElement; |
26
|
|
|
use App\Entity\Parts\Part; |
27
|
|
|
|
28
|
|
|
class HistoryHelper |
29
|
|
|
{ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns an array containing all elements that are associated with the argument. |
37
|
|
|
* The returned array contains the given element. |
38
|
|
|
* @param AbstractDBElement $element |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function getAssociatedElements(AbstractDBElement $element): array |
42
|
|
|
{ |
43
|
|
|
$array = [$element]; |
44
|
|
|
if ($element instanceof AttachmentContainingDBElement) { |
45
|
|
|
$array = array_merge($array, $element->getAttachments()->toArray()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($element instanceof Part) { |
49
|
|
|
$array = array_merge( |
50
|
|
|
$array, |
51
|
|
|
$element->getPartLots()->toArray(), |
52
|
|
|
$element->getOrderdetails()->toArray() |
53
|
|
|
); |
54
|
|
|
foreach ($element->getOrderdetails() as $orderdetail) { |
55
|
|
|
$array = array_merge($array, $orderdetail->getPricedetails()->toArray()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $array; |
60
|
|
|
} |
61
|
|
|
} |