|
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\PartTraits; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
use App\Entity\Parts\Category; |
|
36
|
|
|
use App\Entity\Parts\Footprint; |
|
37
|
|
|
use App\Entity\Parts\Part; |
|
38
|
|
|
use App\Security\Annotations\ColumnSecurity; |
|
39
|
|
|
use App\Validator\Constraints\Selectable; |
|
40
|
|
|
|
|
41
|
|
|
trait BasicPropertyTrait |
|
42
|
|
|
{ |
|
43
|
|
|
/** |
|
44
|
|
|
* @var string The name of this part |
|
45
|
|
|
* @ORM\Column(type="string") |
|
46
|
|
|
* @ColumnSecurity(prefix="name") |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $name = ''; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string A text describing what this part does |
|
52
|
|
|
* @ORM\Column(type="text") |
|
53
|
|
|
* @ColumnSecurity(prefix="description") |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $description = ''; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string A comment/note related to this part |
|
59
|
|
|
* @ORM\Column(type="text") |
|
60
|
|
|
* @ColumnSecurity(prefix="comment") |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $comment = ''; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var bool Kept for compatibility (it is not used now, and I dont think it was used in old versions) |
|
66
|
|
|
* @ORM\Column(type="boolean") |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $visible = true; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var bool True, if the part is marked as favorite. |
|
72
|
|
|
* @ORM\Column(type="boolean") |
|
73
|
|
|
* @ColumnSecurity(type="boolean") |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $favorite = false; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var Category The category this part belongs too (e.g. Resistors). Use tags, for more complex grouping. |
|
79
|
|
|
* Every part must have a category. |
|
80
|
|
|
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts") |
|
81
|
|
|
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false) |
|
82
|
|
|
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category") |
|
83
|
|
|
* @Selectable() |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $category; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var Footprint|null The footprint of this part (e.g. DIP8) |
|
89
|
|
|
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts") |
|
90
|
|
|
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id") |
|
91
|
|
|
* @ColumnSecurity(prefix="footprint", type="App\Entity\Parts\Footprint") |
|
92
|
|
|
* @Selectable() |
|
93
|
|
|
*/ |
|
94
|
|
|
protected $footprint; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get the description string like it is saved in the database. |
|
98
|
|
|
* This can contain BBCode, it is not parsed yet. |
|
99
|
|
|
* @return string the description |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getDescription(): string |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->description; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the comment associated with this part. |
|
108
|
|
|
* @return string The raw/unparsed comment |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getComment(): string |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->comment; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get if this part is visible. |
|
117
|
|
|
* This property is not used yet. |
|
118
|
|
|
* @return bool true if this part is visible |
|
119
|
|
|
* false if this part isn't visible |
|
120
|
|
|
*/ |
|
121
|
|
|
public function isVisible(): bool |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->visible; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Check if this part is a favorite. |
|
128
|
|
|
* @return bool * true if this part is a favorite |
|
129
|
|
|
* * false if this part is not a favorite. |
|
130
|
|
|
*/ |
|
131
|
|
|
public function isFavorite(): bool |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->favorite; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Get the category of this part (e.g. Resistors). |
|
139
|
|
|
* There is always a category, for each part! |
|
140
|
|
|
* @return Category the category of this part |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getCategory(): ?Category |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->category; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Gets the Footprint of this part (e.g. DIP8) |
|
149
|
|
|
* @return Footprint|null The footprint of this part. Null if this part should no have a footprint. |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getFootprint(): ?Footprint |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->footprint; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Sets the description of this part. |
|
158
|
|
|
* @param string $new_description the new description |
|
159
|
|
|
* @return self |
|
160
|
|
|
*/ |
|
161
|
|
|
public function setDescription(?string $new_description): self |
|
162
|
|
|
{ |
|
163
|
|
|
$this->description = $new_description; |
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Sets the comment property of this part. |
|
169
|
|
|
* @param string $new_comment the new comment |
|
170
|
|
|
* @return self |
|
171
|
|
|
*/ |
|
172
|
|
|
public function setComment(string $new_comment): self |
|
173
|
|
|
{ |
|
174
|
|
|
$this->comment = $new_comment; |
|
175
|
|
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Set the category of this Part. |
|
181
|
|
|
* The category property is required for every part, so you can not pass null like the other properties (footprints) |
|
182
|
|
|
* @param Category $category The new category of this part |
|
183
|
|
|
* @return self |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setCategory(Category $category): Part |
|
186
|
|
|
{ |
|
187
|
|
|
$this->category = $category; |
|
188
|
|
|
return $this; |
|
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Set the new Footprint of this Part. |
|
193
|
|
|
* |
|
194
|
|
|
* @param Footprint|null $new_footprint The new footprint of this part. Set to null, if this part should not have |
|
195
|
|
|
* a footprint. |
|
196
|
|
|
* |
|
197
|
|
|
* @return self |
|
198
|
|
|
*/ |
|
199
|
|
|
public function setFootprint(?Footprint $new_footprint): Part |
|
200
|
|
|
{ |
|
201
|
|
|
$this->footprint = $new_footprint; |
|
202
|
|
|
return $this; |
|
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Set the favorite status for this part. |
|
207
|
|
|
* |
|
208
|
|
|
* @param $new_favorite_status bool The new favorite status, that should be applied on this part. |
|
209
|
|
|
* Set this to true, when the part should be a favorite. |
|
210
|
|
|
* |
|
211
|
|
|
* @return self |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setFavorite(bool $new_favorite_status): self |
|
214
|
|
|
{ |
|
215
|
|
|
$this->favorite = $new_favorite_status; |
|
216
|
|
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
} |