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\Manufacturer; |
36
|
|
|
use App\Entity\Parts\Part; |
37
|
|
|
use App\Security\Annotations\ColumnSecurity; |
38
|
|
|
use App\Validator\Constraints\Selectable; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* In this trait all manufacturer related properties of a part are collected (like MPN, manufacturer URL). |
42
|
|
|
* @package App\Entity\Parts\PartTraits |
43
|
|
|
*/ |
44
|
|
|
trait ManufacturerTrait |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var Manufacturer|null The manufacturer of this part |
48
|
|
|
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts") |
49
|
|
|
* @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id") |
50
|
|
|
* @ColumnSecurity(prefix="manufacturer", type="App\Entity\Parts\Manufacturer") |
51
|
|
|
* @Selectable() |
52
|
|
|
*/ |
53
|
|
|
protected $manufacturer; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string The url to the part on the manufacturer's homepage. |
57
|
|
|
* @ORM\Column(type="string") |
58
|
|
|
* @Assert\Url() |
59
|
|
|
* @ColumnSecurity(prefix="mpn", type="string", placeholder="") |
60
|
|
|
*/ |
61
|
|
|
protected $manufacturer_product_url = ''; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string The product number used by the manufacturer. If this is set to "", the name field is used. |
65
|
|
|
* @ORM\Column(type="string") |
66
|
|
|
* @ColumnSecurity(prefix="mpn", type="string", placeholder="") |
67
|
|
|
*/ |
68
|
|
|
protected $manufacturer_product_number = ''; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string The production status of this part. Can be one of the specified ones. |
72
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
73
|
|
|
* @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""}) |
74
|
|
|
* @ColumnSecurity(type="string", prefix="status", placeholder="") |
75
|
|
|
*/ |
76
|
|
|
protected $manufacturing_status = ""; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get the link to the website of the article on the manufacturers website |
80
|
|
|
* When no this part has no explicit url set, then it is tried to generate one from the Manufacturer of this part |
81
|
|
|
* automatically. |
82
|
|
|
* @return string the link to the article |
83
|
|
|
*/ |
84
|
|
|
public function getManufacturerProductUrl(): string |
85
|
|
|
{ |
86
|
|
|
if ('' !== $this->manufacturer_product_url) { |
87
|
|
|
return $this->manufacturer_product_url; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (null !== $this->getManufacturer()) { |
91
|
|
|
return $this->getManufacturer()->getAutoProductUrl($this->name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return ''; // no url is available |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Similar to getManufacturerProductUrl, but here only the database value is returned. |
99
|
|
|
* @return string The manufacturer url saved in DB for this part. |
100
|
|
|
*/ |
101
|
|
|
public function getCustomProductURL(): string |
102
|
|
|
{ |
103
|
|
|
return $this->manufacturer_product_url; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns the manufacturing/production status for this part. |
108
|
|
|
* The status can be one of the following: |
109
|
|
|
* (Similar to https://designspark.zendesk.com/hc/en-us/articles/213584805-What-are-the-Lifecycle-Status-definitions-) |
110
|
|
|
* * "": Status unknown |
111
|
|
|
* * "announced": Part has been announced, but is not in production yet |
112
|
|
|
* * "active": Part is in production and will be for the forseeable future |
113
|
|
|
* * "nrfnd": Not recommended for new designs. |
114
|
|
|
* * "eol": Part will become discontinued soon |
115
|
|
|
* * "discontinued": Part is obsolete/discontinued by the manufacturer |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getManufacturingStatus(): ?string |
119
|
|
|
{ |
120
|
|
|
return $this->manufacturing_status; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Sets the manufacturing status for this part |
125
|
|
|
* See getManufacturingStatus() for valid values. |
126
|
|
|
* @param string $manufacturing_status |
127
|
|
|
* @return Part |
128
|
|
|
*/ |
129
|
|
|
public function setManufacturingStatus(string $manufacturing_status): self |
130
|
|
|
{ |
131
|
|
|
$this->manufacturing_status = $manufacturing_status; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get the manufacturer of this part (if there is one). |
137
|
|
|
* |
138
|
|
|
* @return Manufacturer the manufacturer of this part (if there is one) |
139
|
|
|
*/ |
140
|
|
|
public function getManufacturer(): ?Manufacturer |
141
|
|
|
{ |
142
|
|
|
return $this->manufacturer; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Returns the assigned manufacturer product number (MPN) for this part. |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getManufacturerProductNumber(): string |
151
|
|
|
{ |
152
|
|
|
return $this->manufacturer_product_number; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Sets the manufacturer product number (MPN) for this part. |
157
|
|
|
* @param string $manufacturer_product_number |
158
|
|
|
* @return Part |
159
|
|
|
*/ |
160
|
|
|
public function setManufacturerProductNumber(string $manufacturer_product_number): self |
161
|
|
|
{ |
162
|
|
|
$this->manufacturer_product_number = $manufacturer_product_number; |
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Sets the URL to the manufacturer site about this Part. |
168
|
|
|
* Set to "" if this part should use the automatically URL based on its manufacturer. |
169
|
|
|
* @param string $new_url The new url |
170
|
|
|
* @return self |
171
|
|
|
*/ |
172
|
|
|
public function setManufacturerProductURL(string $new_url): self |
173
|
|
|
{ |
174
|
|
|
$this->manufacturer_product_url = $new_url; |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Sets the new manufacturer of this part. |
181
|
|
|
* |
182
|
|
|
* @param Manufacturer|null $new_manufacturer The new Manufacturer of this part. Set to null, if this part should |
183
|
|
|
* not have a manufacturer. |
184
|
|
|
* |
185
|
|
|
* @return self |
186
|
|
|
*/ |
187
|
|
|
public function setManufacturer(?Manufacturer $new_manufacturer): self |
188
|
|
|
{ |
189
|
|
|
$this->manufacturer = $new_manufacturer; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
} |