1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace App\Entity\Parts; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use App\Entity\Base\PartsContainingDBElement; |
36
|
|
|
use App\Entity\Base\StructuralDBElement; |
37
|
|
|
use Doctrine\ORM\Mapping as ORM; |
38
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
39
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* This unit represents the unit in which the amount of parts in stock are measured. |
43
|
|
|
* This could be something like N, gramms, meters, etc... |
44
|
|
|
* |
45
|
|
|
* @package App\Entity |
46
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") |
47
|
|
|
* @ORM\Table(name="`measurement_units`") |
48
|
|
|
* @UniqueEntity("unit") |
49
|
|
|
*/ |
50
|
|
|
class MeasurementUnit extends PartsContainingDBElement |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for gramms) |
55
|
|
|
* or m (for meters). |
56
|
|
|
* @ORM\Column(type="string", name="unit", nullable=true) |
57
|
|
|
* @Assert\Length(max=10) |
58
|
|
|
*/ |
59
|
|
|
protected $unit; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var bool Determines if the amount value associated with this unit should be treated as integer. |
63
|
|
|
* Set to false, to measure continuous sizes likes masses or lengthes. |
64
|
|
|
* @ORM\Column(type="boolean", name="is_integer") |
65
|
|
|
*/ |
66
|
|
|
protected $is_integer = false; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.). |
70
|
|
|
* Useful for sizes like meters. |
71
|
|
|
* @ORM\Column(type="boolean", name="use_si_prefix") |
72
|
|
|
*/ |
73
|
|
|
protected $use_si_prefix = false; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @ORM\OneToMany(targetEntity="MeasurementUnit", mappedBy="parent", cascade={"persist"}) |
77
|
|
|
*/ |
78
|
|
|
protected $children; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\ManyToOne(targetEntity="MeasurementUnit", inversedBy="children") |
82
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
83
|
|
|
*/ |
84
|
|
|
protected $parent; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the ID as an string, defined by the element class. |
88
|
|
|
* This should have a form like P000014, for a part with ID 14. |
89
|
|
|
* |
90
|
|
|
* @return string The ID as a string; |
91
|
|
|
* |
92
|
|
|
*/ |
93
|
|
|
public function getIDString(): string |
94
|
|
|
{ |
95
|
|
|
return 'MU' . $this->getID(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getUnit(): ?string |
102
|
|
|
{ |
103
|
|
|
return $this->unit; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $unit |
108
|
|
|
* @return MeasurementUnit |
109
|
|
|
*/ |
110
|
|
|
public function setUnit(?string $unit): MeasurementUnit |
111
|
|
|
{ |
112
|
|
|
$this->unit = $unit; |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function isInteger(): bool |
120
|
|
|
{ |
121
|
|
|
return $this->is_integer; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param bool $isInteger |
126
|
|
|
* @return MeasurementUnit |
127
|
|
|
*/ |
128
|
|
|
public function setIsInteger(bool $isInteger): MeasurementUnit |
129
|
|
|
{ |
130
|
|
|
$this->isInteger = $isInteger; |
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return bool |
136
|
|
|
*/ |
137
|
|
|
public function isUseSIPrefix(): bool |
138
|
|
|
{ |
139
|
|
|
return $this->use_si_prefix; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param bool $usesSIPrefixes |
144
|
|
|
* @return MeasurementUnit |
145
|
|
|
*/ |
146
|
|
|
public function setUseSIPrefix(bool $usesSIPrefixes): MeasurementUnit |
147
|
|
|
{ |
148
|
|
|
$this->useSIPrefixes = $usesSIPrefixes; |
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
} |