-
Notifications
You must be signed in to change notification settings - Fork 0
/
FiguresFixtures.php
127 lines (106 loc) · 4.96 KB
/
FiguresFixtures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace App\DataFixtures;
use App\Entity\Category;
use Faker\Factory;
use App\Entity\User;
use App\Entity\Video;
use App\Entity\Comment;
use App\Entity\Figures;
use App\Entity\Picture;
use App\Repository\UserRepository;
use App\Repository\VideoRepository;
use App\Repository\CommentRepository;
use App\Repository\FiguresRepository;
use App\Repository\PictureRepository;
use App\Repository\CategoryRepository;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class FiguresFixtures extends Fixture
{
public function __construct(CategoryRepository $categoryRepository, PictureRepository $pictureRepository, VideoRepository $videoRepository, CommentRepository $commentRepository, FiguresRepository $figuresRepository, UserRepository $userRepository, UserPasswordEncoderInterface $encoder)
{
$this->categoryRepository = $categoryRepository;
$this->pictureRepository = $pictureRepository;
$this->videoRepository = $videoRepository;
$this->commentRepository = $commentRepository;
$this->figuresRepository = $figuresRepository;
$this->userRepository = $userRepository;
$this->encoder = $encoder;
}
public function load(ObjectManager $manager)
{
$faker = Factory::create('fr_FR');
$categories = ['Grabs', 'Rotations', 'Flips', 'Slides'];
$categoriesObj = [];
$figures = ['Melancholie', 'Mute', 'Style week', '540 rotation', 'Indy', 'Stalefish', 'Japan Air', 'Nose grab', '180 rotation', 'Sad', 'Tail grab', '900 rotation', 'Seat Belt', '360 rotation', 'Japan', '720 rotation', 'Backside Air', 'Truck driver', 'Big foot', 'Slide', 'Rocket Air', 'Flip', 'Method Air'];
$videos = [
'<iframe width="560" height="315" src="https://www.youtube.com/embed/AzJPhQdTRQQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
'<iframe width="560" height="315" src="https://www.youtube.com/embed/IlL-PGqZqVY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
'<iframe width="560" height="315" src="https://www.youtube.com/embed/qsd8uaex-Is" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
'<iframe width="560" height="315" src="https://www.youtube.com/embed/5mtNg2mf-Hg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
'<iframe width="560" height="315" src="https://www.youtube.com/embed/1TJ08caetkw" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
'<iframe width="560" height="315" src="https://www.youtube.com/embed/UGdif-dwu-8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
];
// reset autoincrement à 1
$this->categoryRepository->resetIndex();
$this->pictureRepository->resetIndex();
$this->videoRepository->resetIndex();
$this->commentRepository->resetIndex();
$this->figuresRepository->resetIndex();
$this->userRepository->resetIndex();
$user = new User();
$user->setUsername('root');
$user->setEmail('root@root.fr');
$user->setPassword($this->encoder->encodePassword($user, 'root'));
$user->setActif(1);
$manager->persist($user);
foreach ($categories as $key => $item) {
$category = new Category();
$category->setName($item);
$manager->persist($category);
array_push($categoriesObj, $category);
}
foreach ($figures as $key => $item) {
$figure = new Figures();
$date = new \DateTime();
$figure->setName($item);
$figure->setCreatedAt($date);
$figure->setUpdatedAt($date);
$figure->setDescription($faker->sentences(15, true));
$figure->addCategory($categoriesObj[random_int(0, 3)]);
$figure->setMainImage('image-' . random_int(1, 6) . '.jpg');
$manager->persist($figure);
for ($i = 1; $i <= 3; $i++) {
$picture = new Picture();
$picture->setFigures($figure);
$picture->setFilename('image-' . random_int(1, 6) . '.jpg');
$picture->setUpdatedAt($date);
$manager->persist($picture);
$video = new Video();
$video->setFigure($figure);
$video->setUrl($videos[random_int(0, 5)]);
$manager->persist($video);
}
for ($i = 1; $i <= 30; $i++) {
$comment = new Comment();
$comment->setContent($faker->sentences(random_int(1, 4), true));
$comment->setCreatedAt($date);
$comment->setFigure($figure);
$comment->setUser($user);
$manager->persist($comment);
}
// for ()
}
// for ($i = 0; $i < 100; $i++) {
// $figure = new Figures();
// $date = new \DateTime();
// $figure->setName($faker->words(4, true));
// $figure->setCreatedAt($date);
// $figure->setUpdatedAt($date);
// $figure->setDescription($faker->sentences(10, true));
// $manager->persist($figure);
// }
$manager->flush();
}
}