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