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 |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (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 General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace App\DataFixtures; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
use App\Entity\Attachments\AttachmentType; |
26
|
|
|
use App\Entity\Attachments\PartAttachment; |
27
|
|
|
use App\Entity\Parts\Category; |
28
|
|
|
use App\Entity\Parts\Footprint; |
29
|
|
|
use App\Entity\Parts\Manufacturer; |
30
|
|
|
use App\Entity\Parts\Part; |
31
|
|
|
use App\Entity\Parts\PartLot; |
32
|
|
|
use App\Entity\Parts\Storelocation; |
33
|
|
|
use App\Entity\Parts\Supplier; |
34
|
|
|
use App\Entity\PriceInformations\Orderdetail; |
35
|
|
|
use App\Entity\PriceInformations\Pricedetail; |
36
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
37
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
38
|
|
|
use Doctrine\Persistence\ObjectManager; |
39
|
|
|
|
40
|
|
|
class PartFixtures extends Fixture |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
protected $em; |
44
|
|
|
|
45
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
46
|
|
|
{ |
47
|
|
|
$this->em = $entityManager; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritDoc |
52
|
|
|
*/ |
53
|
|
|
public function load(ObjectManager $manager) |
54
|
|
|
{ |
55
|
|
|
$table_name = $this->em->getClassMetadata(Part::class)->getTableName(); |
|
|
|
|
56
|
|
|
$this->em->getConnection()->exec("ALTER TABLE `${table_name}` AUTO_INCREMENT = 1;"); |
57
|
|
|
|
58
|
|
|
/** Simple part */ |
59
|
|
|
$part = new Part(); |
60
|
|
|
$part->setName('Part 1'); |
61
|
|
|
$part->setCategory($manager->find(Category::class, 1)); |
|
|
|
|
62
|
|
|
$manager->persist($part); |
63
|
|
|
|
64
|
|
|
/** More complex part */ |
65
|
|
|
$part = new Part(); |
66
|
|
|
$part->setName('Part 2'); |
67
|
|
|
$part->setCategory($manager->find(Category::class, 1)); |
68
|
|
|
$part->setFootprint($manager->find(Footprint::class, 1)); |
69
|
|
|
$part->setManufacturer($manager->find(Manufacturer::class, 1)); |
70
|
|
|
$part->setTags('test, Test, Part2'); |
71
|
|
|
$part->setMass(100.2); |
72
|
|
|
$part->setNeedsReview(true); |
73
|
|
|
$part->setManufacturingStatus('active'); |
74
|
|
|
$manager->persist($part); |
75
|
|
|
|
76
|
|
|
/** Part with orderdetails, storelocations and Attachments */ |
77
|
|
|
$part = new Part(); |
78
|
|
|
$part->setFavorite(true); |
79
|
|
|
$part->setName('Part 2'); |
80
|
|
|
$part->setCategory($manager->find(Category::class, 1)); |
81
|
|
|
$partLot1 = new PartLot(); |
82
|
|
|
$partLot1->setAmount(1.0); |
83
|
|
|
$partLot1->setStorageLocation($manager->find(Storelocation::class, 1)); |
84
|
|
|
$part->addPartLot($partLot1); |
85
|
|
|
|
86
|
|
|
$partLot2 = new PartLot(); |
87
|
|
|
$partLot2->setExpirationDate(new \DateTime()); |
88
|
|
|
$partLot2->setComment('Test'); |
89
|
|
|
$partLot2->setNeedsRefill(true); |
90
|
|
|
$partLot2->setStorageLocation($manager->find(Storelocation::class, 3)); |
91
|
|
|
$part->addPartLot($partLot2); |
92
|
|
|
|
93
|
|
|
$orderdetail = new Orderdetail(); |
94
|
|
|
$orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
|
|
|
|
95
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); |
96
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); |
97
|
|
|
$part->addOrderdetail($orderdetail); |
98
|
|
|
|
99
|
|
|
$orderdetail = new Orderdetail(); |
100
|
|
|
$orderdetail->setSupplierpartnr('BC 547'); |
101
|
|
|
$orderdetail->setObsolete(true); |
102
|
|
|
$orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
103
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); |
104
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); |
105
|
|
|
$part->addOrderdetail($orderdetail); |
106
|
|
|
|
107
|
|
|
$attachment = new PartAttachment(); |
108
|
|
|
$attachment->setName('TestAttachment'); |
109
|
|
|
$attachment->setURL('www.foo.bar'); |
110
|
|
|
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
|
|
|
|
111
|
|
|
$part->addAttachment($attachment); |
112
|
|
|
|
113
|
|
|
$attachment = new PartAttachment(); |
114
|
|
|
$attachment->setName('Test2'); |
115
|
|
|
$attachment->setPath('invalid'); |
116
|
|
|
$attachment->setShowInTable(true); |
117
|
|
|
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
118
|
|
|
$part->addAttachment($attachment); |
119
|
|
|
|
120
|
|
|
$manager->persist($part); |
121
|
|
|
$manager->flush(); |
122
|
|
|
} |
123
|
|
|
} |