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
|
|
|
namespace App\Services\LabelSystem\Barcodes; |
22
|
|
|
|
23
|
|
|
use App\Entity\Base\AbstractStructuralDBElement; |
24
|
|
|
use App\Entity\Parts\Category; |
25
|
|
|
use App\Entity\Parts\Footprint; |
26
|
|
|
use App\Entity\Parts\Manufacturer; |
27
|
|
|
use App\Entity\Parts\Part; |
28
|
|
|
use App\Entity\Parts\PartLot; |
29
|
|
|
use App\Entity\Parts\Storelocation; |
30
|
|
|
|
31
|
|
|
final class BarcodeExampleElementsGenerator |
32
|
|
|
{ |
33
|
|
|
public function getElement(string $type): object |
34
|
|
|
{ |
35
|
|
|
switch ($type) { |
36
|
|
|
case 'part': |
37
|
|
|
return $this->getExamplePart(); |
38
|
|
|
case 'part_lot': |
39
|
|
|
return $this->getExamplePartLot(); |
40
|
|
|
case 'storelocation': |
41
|
|
|
return $this->getStorelocation(); |
42
|
|
|
default: |
43
|
|
|
throw new \InvalidArgumentException('Unknown $type.'); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function getStorelocation(): Storelocation |
48
|
|
|
{ |
49
|
|
|
$storelocation = new Storelocation(); |
50
|
|
|
$storelocation->setName('Location 1'); |
51
|
|
|
$storelocation->setComment('Example comment'); |
52
|
|
|
$storelocation->updatedTimestamps(); |
53
|
|
|
|
54
|
|
|
$parent = new Storelocation(); |
55
|
|
|
$parent->setName('Parent'); |
56
|
|
|
|
57
|
|
|
$storelocation->setParent($parent); |
58
|
|
|
|
59
|
|
|
return $storelocation; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function getStructuralData(string $class): AbstractStructuralDBElement |
63
|
|
|
{ |
64
|
|
|
if (!is_a($class, AbstractStructuralDBElement::class, true)) { |
65
|
|
|
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** @var AbstractStructuralDBElement $parent */ |
69
|
|
|
$parent = new $class(); |
70
|
|
|
$parent->setName('Example'); |
71
|
|
|
|
72
|
|
|
/** @var AbstractStructuralDBElement $child */ |
73
|
|
|
$child = new $class(); |
74
|
|
|
$child->setName((new \ReflectionClass($class))->getShortName()); |
75
|
|
|
$child->setParent($parent); |
76
|
|
|
|
77
|
|
|
return $child; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getExamplePart(): Part |
81
|
|
|
{ |
82
|
|
|
$part = new Part(); |
83
|
|
|
$part->setName('Example Part'); |
84
|
|
|
$part->setDescription('<b>Part</b> description'); |
85
|
|
|
$part->setComment('<i>Part</i> comment'); |
86
|
|
|
|
87
|
|
|
$part->setCategory($this->getStructuralData(Category::class)); |
88
|
|
|
$part->setFootprint($this->getStructuralData(Footprint::class)); |
89
|
|
|
$part->setManufacturer($this->getStructuralData(Manufacturer::class)); |
90
|
|
|
|
91
|
|
|
$part->setMass(123.4); |
92
|
|
|
$part->setManufacturerProductNumber('CUSTOM MPN'); |
93
|
|
|
$part->setTags('Tag1, Tag2, Tag3'); |
94
|
|
|
$part->setManufacturingStatus('active'); |
95
|
|
|
$part->updatedTimestamps(); |
96
|
|
|
|
97
|
|
|
$part->setFavorite(true); |
98
|
|
|
$part->setMinAmount(100); |
99
|
|
|
$part->setNeedsReview(true); |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
return $part; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getExamplePartLot(): PartLot |
106
|
|
|
{ |
107
|
|
|
$lot = new PartLot(); |
108
|
|
|
$lot->setPart($this->getExamplePart()); |
109
|
|
|
|
110
|
|
|
$lot->setDescription('Example Lot'); |
111
|
|
|
$lot->setComment('Lot comment'); |
112
|
|
|
$lot->setExpirationDate(new \DateTime('+1 days')); |
113
|
|
|
$lot->setStorageLocation($this->getStructuralData(Storelocation::class)); |
114
|
|
|
$lot->setAmount(123); |
115
|
|
|
|
116
|
|
|
return $lot; |
117
|
|
|
} |
118
|
|
|
} |