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
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* part-db version 0.1 |
25
|
|
|
* Copyright (C) 2005 Christoph Lechner |
26
|
|
|
* http://www.cl-projects.de/. |
27
|
|
|
* |
28
|
|
|
* part-db version 0.2+ |
29
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
30
|
|
|
* http://code.google.com/p/part-db/ |
31
|
|
|
* |
32
|
|
|
* Part-DB Version 0.4+ |
33
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
34
|
|
|
* https://github.com/jbtronics |
35
|
|
|
* |
36
|
|
|
* This program is free software; you can redistribute it and/or |
37
|
|
|
* modify it under the terms of the GNU General Public License |
38
|
|
|
* as published by the Free Software Foundation; either version 2 |
39
|
|
|
* of the License, or (at your option) any later version. |
40
|
|
|
* |
41
|
|
|
* This program is distributed in the hope that it will be useful, |
42
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
43
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44
|
|
|
* GNU General Public License for more details. |
45
|
|
|
* |
46
|
|
|
* You should have received a copy of the GNU General Public License |
47
|
|
|
* along with this program; if not, write to the Free Software |
48
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
namespace App\Entity\Devices; |
52
|
|
|
|
53
|
|
|
use App\Entity\Attachments\DeviceAttachment; |
54
|
|
|
use App\Entity\Base\AbstractPartsContainingDBElement; |
55
|
|
|
use App\Entity\Parameters\DeviceParameter; |
56
|
|
|
use Doctrine\Common\Collections\Collection; |
57
|
|
|
use Doctrine\ORM\Mapping as ORM; |
58
|
|
|
use InvalidArgumentException; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Class AttachmentType. |
62
|
|
|
* |
63
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") |
64
|
|
|
* @ORM\Table(name="`devices`") |
65
|
|
|
*/ |
66
|
|
|
class Device extends AbstractPartsContainingDBElement |
67
|
|
|
{ |
68
|
|
|
/** |
69
|
|
|
* @ORM\OneToMany(targetEntity="Device", mappedBy="parent") |
70
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
71
|
|
|
*/ |
72
|
|
|
protected $children; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @ORM\ManyToOne(targetEntity="Device", inversedBy="children") |
76
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
77
|
|
|
*/ |
78
|
|
|
protected $parent; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\OneToMany(targetEntity="DevicePart", mappedBy="device") |
82
|
|
|
*/ |
83
|
|
|
protected $parts; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var int |
87
|
|
|
* @ORM\Column(type="integer") |
88
|
|
|
*/ |
89
|
|
|
protected $order_quantity = 0; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var bool |
93
|
|
|
* @ORM\Column(type="boolean") |
94
|
|
|
*/ |
95
|
|
|
protected $order_only_missing_parts = false; |
96
|
|
|
/** |
97
|
|
|
* @var Collection<int, DeviceAttachment> |
98
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
99
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
100
|
|
|
*/ |
101
|
|
|
protected $attachments; |
102
|
|
|
|
103
|
|
|
/** @var Collection<int, DeviceParameter> |
104
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\DeviceParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
105
|
|
|
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) |
106
|
|
|
*/ |
107
|
|
|
protected $parameters; |
108
|
|
|
|
109
|
|
|
/******************************************************************************** |
110
|
|
|
* |
111
|
|
|
* Getters |
112
|
|
|
* |
113
|
|
|
*********************************************************************************/ |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the order quantity of this device. |
117
|
|
|
* |
118
|
|
|
* @return int the order quantity |
119
|
|
|
*/ |
120
|
|
|
public function getOrderQuantity(): int |
121
|
|
|
{ |
122
|
|
|
return $this->order_quantity; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the "order_only_missing_parts" attribute. |
127
|
|
|
* |
128
|
|
|
* @return bool the "order_only_missing_parts" attribute |
129
|
|
|
*/ |
130
|
|
|
public function getOrderOnlyMissingParts(): bool |
131
|
|
|
{ |
132
|
|
|
return $this->order_only_missing_parts; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/******************************************************************************** |
136
|
|
|
* |
137
|
|
|
* Setters |
138
|
|
|
* |
139
|
|
|
*********************************************************************************/ |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set the order quantity. |
143
|
|
|
* |
144
|
|
|
* @param int $new_order_quantity the new order quantity |
145
|
|
|
* |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
|
|
public function setOrderQuantity(int $new_order_quantity): self |
149
|
|
|
{ |
150
|
|
|
if ($new_order_quantity < 0) { |
151
|
|
|
throw new InvalidArgumentException('The new order quantity must not be negative!'); |
152
|
|
|
} |
153
|
|
|
$this->order_quantity = $new_order_quantity; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set the "order_only_missing_parts" attribute. |
160
|
|
|
* |
161
|
|
|
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute |
162
|
|
|
* |
163
|
|
|
* @return Device |
164
|
|
|
*/ |
165
|
|
|
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self |
166
|
|
|
{ |
167
|
|
|
$this->order_only_missing_parts = $new_order_only_missing_parts; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|