1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\DataFixtures; |
6
|
|
|
|
7
|
|
|
use App\Entity\Property; |
8
|
|
|
use App\Utils\Slugger; |
9
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
10
|
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
11
|
|
|
use Doctrine\Persistence\ObjectManager; |
12
|
|
|
|
13
|
|
|
final class PropertyFixtures extends Fixture implements DependentFixtureInterface |
14
|
|
|
{ |
15
|
|
|
public function load(ObjectManager $manager): void |
16
|
|
|
{ |
17
|
|
|
foreach ($this->getPropertyData() as [$author, $dealType, $category, $bedrooms, $guests, $city, $district, |
18
|
|
|
$neighborhood, $title, $address, $latitude, $longitude, $price, $priceType, ]) { |
19
|
|
|
$property = new Property(); |
20
|
|
|
$property->setAuthor($author); |
|
|
|
|
21
|
|
|
$property->setDealType($dealType); |
|
|
|
|
22
|
|
|
$property->setCategory($category); |
|
|
|
|
23
|
|
|
$property->setBedroomsNumber($bedrooms); |
|
|
|
|
24
|
|
|
$property->setMaxGuests($guests); |
|
|
|
|
25
|
|
|
$property->setCity($city); |
|
|
|
|
26
|
|
|
$property->setNeighborhood($neighborhood); |
|
|
|
|
27
|
|
|
$property->setDistrict($district); |
|
|
|
|
28
|
|
|
$property->setTitle($title); |
|
|
|
|
29
|
|
|
$property->setMetaDescription($title); |
30
|
|
|
$property->setSlug(Slugger::slugify($title)); |
31
|
|
|
$property->setContent($this->getPropertyContent()); |
32
|
|
|
$property->setAddress($address); |
|
|
|
|
33
|
|
|
$property->setLatitude($latitude); |
|
|
|
|
34
|
|
|
$property->setLongitude($longitude); |
|
|
|
|
35
|
|
|
$property->setShowMap(true); |
36
|
|
|
$property->setPrice($price); |
|
|
|
|
37
|
|
|
$property->setPriceType($priceType); |
|
|
|
|
38
|
|
|
$property->setState('published'); |
39
|
|
|
$property->setCreatedAt(new \DateTime('now')); |
40
|
|
|
$property->setUpdatedAt(new \DateTime('now')); |
41
|
|
|
$property->addFeature($this->getReference('Климатизация')); |
42
|
|
|
$property->addFeature($this->getReference('Балкон')); |
43
|
|
|
$property->addFeature($this->getReference('Противопожарна аларма')); |
44
|
|
|
$property->addFeature($this->getReference('Интериорни врати')); |
45
|
|
|
$property->addFeature($this->getReference('Защитен паркинг')); |
46
|
|
|
$property->setPriorityNumber(0); |
47
|
|
|
$manager->persist($property); |
48
|
|
|
$this->addReference(Slugger::slugify($title), $property); |
49
|
|
|
} |
50
|
|
|
$manager->flush(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getPropertyData(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
/* |
57
|
|
|
$propertyData = [$author, $dealType, $category, $bedrooms, $guests, $city, |
58
|
|
|
$district $neighborhood, $title, $address, |
59
|
|
|
$latitude, $longitude, $price, $priceType]; |
60
|
|
|
*/ |
61
|
|
|
[ |
62
|
|
|
$this->getReference('admin'), |
63
|
|
|
$this->getReference('Продава'), |
64
|
|
|
$this->getReference('Вила'), |
65
|
|
|
5, |
66
|
|
|
null, |
67
|
|
|
$this->getReference('Варна'), |
68
|
|
|
$this->getReference('Община Варна'), |
69
|
|
|
$this->getReference('м-т Боровец - Юг'), |
70
|
|
|
'Красива вила за продажба в м-т Боровец - Юг', |
71
|
|
|
'Боровец - Юг', |
72
|
|
|
'43.1467016', '27.8934756', 1000, 'кв. м.', |
73
|
|
|
], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function getPropertyContent(): string |
78
|
|
|
{ |
79
|
|
|
return '<p>Много красива вила, находяща се на 13 км. от центъра на Варна в местността Боровец - Юг</p>'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getDependencies() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
CategoryFixtures::class, |
86
|
|
|
CityFixtures::class, |
87
|
|
|
DealTypeFixtures::class, |
88
|
|
|
DistrictFixtures::class, |
89
|
|
|
FeatureFixtures::class, |
90
|
|
|
NeighborhoodFixtures::class, |
91
|
|
|
UserFixtures::class, |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.