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
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
25
|
|
|
* |
26
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
27
|
|
|
* |
28
|
|
|
* This program is free software; you can redistribute it and/or |
29
|
|
|
* modify it under the terms of the GNU General Public License |
30
|
|
|
* as published by the Free Software Foundation; either version 2 |
31
|
|
|
* of the License, or (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 General Public License for more details. |
37
|
|
|
* |
38
|
|
|
* You should have received a copy of the GNU General Public License |
39
|
|
|
* along with this program; if not, write to the Free Software |
40
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
namespace App\Entity\Parts; |
44
|
|
|
|
45
|
|
|
use App\Entity\Attachments\MeasurementUnitAttachment; |
46
|
|
|
use App\Entity\Base\AbstractPartsContainingDBElement; |
47
|
|
|
use App\Entity\Parameters\MeasurementUnitParameter; |
48
|
|
|
use Doctrine\Common\Collections\Collection; |
49
|
|
|
use Doctrine\ORM\Mapping as ORM; |
50
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
51
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* This unit represents the unit in which the amount of parts in stock are measured. |
55
|
|
|
* This could be something like N, grams, meters, etc... |
56
|
|
|
* |
57
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") |
58
|
|
|
* @ORM\Table(name="`measurement_units`") |
59
|
|
|
* @UniqueEntity("unit") |
60
|
|
|
*/ |
61
|
|
|
class MeasurementUnit extends AbstractPartsContainingDBElement |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for grams) |
65
|
|
|
* or m (for meters). |
66
|
|
|
* @ORM\Column(type="string", name="unit", nullable=true) |
67
|
|
|
* @Assert\Length(max=10) |
68
|
|
|
*/ |
69
|
|
|
protected $unit; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var bool Determines if the amount value associated with this unit should be treated as integer. |
73
|
|
|
* Set to false, to measure continuous sizes likes masses or lengths. |
74
|
|
|
* @ORM\Column(type="boolean", name="is_integer") |
75
|
|
|
*/ |
76
|
|
|
protected $is_integer = false; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.). |
80
|
|
|
* Useful for sizes like meters. |
81
|
|
|
* @ORM\Column(type="boolean", name="use_si_prefix") |
82
|
|
|
*/ |
83
|
|
|
protected $use_si_prefix = false; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @ORM\OneToMany(targetEntity="MeasurementUnit", mappedBy="parent", cascade={"persist"}) |
87
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
88
|
|
|
*/ |
89
|
|
|
protected $children; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @ORM\ManyToOne(targetEntity="MeasurementUnit", inversedBy="children") |
93
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
94
|
|
|
*/ |
95
|
|
|
protected $parent; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @ORM\OneToMany(targetEntity="Part", mappedBy="partUnit", fetch="EXTRA_LAZY") |
99
|
|
|
*/ |
100
|
|
|
protected $parts; |
101
|
|
|
/** |
102
|
|
|
* @var Collection<int, MeasurementUnitAttachment> |
103
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
104
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
105
|
|
|
* @Assert\Valid() |
106
|
|
|
*/ |
107
|
|
|
protected $attachments; |
108
|
|
|
|
109
|
|
|
/** @var Collection<int, MeasurementUnitParameter> |
110
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\MeasurementUnitParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
111
|
|
|
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) |
112
|
|
|
* @Assert\Valid() |
113
|
|
|
*/ |
114
|
|
|
protected $parameters; |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getUnit(): ?string |
121
|
|
|
{ |
122
|
|
|
return $this->unit; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $unit |
127
|
|
|
* |
128
|
|
|
* @return MeasurementUnit |
129
|
|
|
*/ |
130
|
|
|
public function setUnit(?string $unit): self |
131
|
|
|
{ |
132
|
|
|
$this->unit = $unit; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function isInteger(): bool |
138
|
|
|
{ |
139
|
|
|
return $this->is_integer; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return MeasurementUnit |
144
|
|
|
*/ |
145
|
|
|
public function setIsInteger(bool $isInteger): self |
146
|
|
|
{ |
147
|
|
|
$this->is_integer = $isInteger; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function isUseSIPrefix(): bool |
153
|
|
|
{ |
154
|
|
|
return $this->use_si_prefix; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return MeasurementUnit |
159
|
|
|
*/ |
160
|
|
|
public function setUseSIPrefix(bool $usesSIPrefixes): self |
161
|
|
|
{ |
162
|
|
|
$this->use_si_prefix = $usesSIPrefixes; |
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|