1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2022 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
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
25
|
|
|
* |
26
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
27
|
|
|
* |
28
|
|
|
* This program is free software: you can redistribute it and/or modify |
29
|
|
|
* it under the terms of the GNU Affero General Public License as published |
30
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
31
|
|
|
* (at your option) any later version. |
32
|
|
|
* |
33
|
|
|
* This program is distributed in the hope that it will be useful, |
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36
|
|
|
* GNU Affero General Public License for more details. |
37
|
|
|
* |
38
|
|
|
* You should have received a copy of the GNU Affero General Public License |
39
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
namespace App\Entity\Parameters; |
43
|
|
|
|
44
|
|
|
use Doctrine\Common\Collections\Collection; |
45
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
46
|
|
|
|
47
|
|
|
trait ParametersTrait |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* Mapping done in subclasses. |
51
|
|
|
* |
52
|
|
|
* @var Collection<int, AbstractParameter> |
53
|
|
|
* @Assert\Valid() |
54
|
|
|
*/ |
55
|
|
|
protected $parameters; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return all associated specifications. |
59
|
|
|
* |
60
|
|
|
* @psalm-return Collection<int, AbstractParameter> |
61
|
|
|
*/ |
62
|
|
|
public function getParameters(): Collection |
63
|
|
|
{ |
64
|
|
|
return $this->parameters; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Add a new parameter information. |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function addParameter(AbstractParameter $parameter): self |
73
|
|
|
{ |
74
|
|
|
$parameter->setElement($this); |
|
|
|
|
75
|
|
|
$this->parameters->add($parameter); |
76
|
|
|
|
77
|
|
|
return $this; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function removeParameter(AbstractParameter $parameter): self |
81
|
|
|
{ |
82
|
|
|
$this->parameters->removeElement($parameter); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getGroupedParameters(): array |
88
|
|
|
{ |
89
|
|
|
$tmp = []; |
90
|
|
|
|
91
|
|
|
foreach ($this->parameters as $parameter) { |
92
|
|
|
$tmp[$parameter->getGroup()][] = $parameter; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $tmp; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|