|
@@ -0,0 +1,122 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\UserBundle\DataFixtures\ORM;
|
|
4
|
+
|
|
5
|
+use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
6
|
+use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
7
|
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
8
|
+use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
9
|
+use Muzich\CoreBundle\Entity\Group;
|
|
10
|
+use Muzich\CoreBundle\Entity\FollowGroup;
|
|
11
|
+use Muzich\CoreBundle\Entity\GroupsTagsFavorites;
|
|
12
|
+
|
|
13
|
+class LoadGroupData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
|
14
|
+{
|
|
15
|
+
|
|
16
|
+ private $container;
|
|
17
|
+ private $entity_manager;
|
|
18
|
+
|
|
19
|
+ public function setContainer(ContainerInterface $container = null)
|
|
20
|
+ {
|
|
21
|
+ $this->container = $container;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ public function getOrder()
|
|
25
|
+ {
|
|
26
|
+ return 6;
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ protected function getArrayOfTag($names)
|
|
30
|
+ {
|
|
31
|
+ $tags = array();
|
|
32
|
+ foreach ($names as $name)
|
|
33
|
+ {
|
|
34
|
+ $tags[] = $this->entity_manager->merge($this->getReference('tag_'.$name));
|
|
35
|
+ }
|
|
36
|
+ return $tags;
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ /**
|
|
40
|
+ *
|
|
41
|
+ */
|
|
42
|
+ protected function createGroup($reference_id, $name, $description, $open, $owner)
|
|
43
|
+ {
|
|
44
|
+ $group = new Group();
|
|
45
|
+ $group->setName($name);
|
|
46
|
+ $group->setDescription($description);
|
|
47
|
+ $group->setOpen($open);
|
|
48
|
+ $group->setOwner($owner);
|
|
49
|
+
|
|
50
|
+ $this->entity_manager->persist($group);
|
|
51
|
+ $this->addReference('group_'.$reference_id, $group);
|
|
52
|
+ return $group;
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ protected function theyFollowGroup($followers, $group)
|
|
56
|
+ {
|
|
57
|
+ foreach ($followers as $follower)
|
|
58
|
+ {
|
|
59
|
+ $followGroup = new FollowGroup();
|
|
60
|
+ $followGroup->setFollower($follower);
|
|
61
|
+ $followGroup->setGroup($group);
|
|
62
|
+ $this->entity_manager->persist($followGroup);
|
|
63
|
+ }
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ protected function groupHasTags($tags, $group)
|
|
67
|
+ {
|
|
68
|
+ foreach ($tags as $pos => $tag)
|
|
69
|
+ {
|
|
70
|
+ $GroupsTagsFavorites = new GroupsTagsFavorites();
|
|
71
|
+ $GroupsTagsFavorites->setTag($tag);
|
|
72
|
+ $GroupsTagsFavorites->setGroup($group);
|
|
73
|
+ $GroupsTagsFavorites->setPosition($pos);
|
|
74
|
+ $this->entity_manager->persist($GroupsTagsFavorites);
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ public function load($entity_manager)
|
|
79
|
+ {
|
|
80
|
+ $this->entity_manager = $entity_manager;
|
|
81
|
+
|
|
82
|
+ // Création des groupes
|
|
83
|
+
|
|
84
|
+ $group_dudeldrum = $this->createGroup('dudeldrum', 'DUDELDRUM',
|
|
85
|
+ nl2br("Un groupe de musique médievale."),
|
|
86
|
+ false, $this->entity_manager->merge($this->getReference('user_joelle')));
|
|
87
|
+
|
|
88
|
+ $group_fan_de_psytrance = $this->createGroup('fan_de_psytrance', 'Fans de psytrance',
|
|
89
|
+ "La Trance psychédélique (souvent appelée psytrance) est une forme de trance (style de musique électronique)
|
|
90
|
+ apparue au début des années 1990 à Goa, Inde, d'où le nom de \"Goa\" ou \"trance-Goa\" donné au départ à ce
|
|
91
|
+ courant musical (ou encore Hippie Trance, 604 par analogie graphique avec GOA). La trance psychédélique est
|
|
92
|
+ caractérisée par un rythme rapide, dans la gamme des 125 à 160 battements par minute (bpm), contrairement à
|
|
93
|
+ l'ambient et autres formes d'house ou de techno. Ses basses sont fortes, sans interruption, sans changement
|
|
94
|
+ et recouvertes par beaucoup d'autres rythmes, souvent produits par le célèbre synthétiseur Roland TB-303.",
|
|
95
|
+ true, $this->entity_manager->merge($this->getReference('user_bob')));
|
|
96
|
+
|
|
97
|
+ // Followers
|
|
98
|
+
|
|
99
|
+ $this->theyFollowGroup(array(
|
|
100
|
+ $this->entity_manager->merge($this->getReference('user_bux')),
|
|
101
|
+ $this->entity_manager->merge($this->getReference('user_jean'))
|
|
102
|
+ ), $group_dudeldrum);
|
|
103
|
+
|
|
104
|
+ $this->theyFollowGroup(array(
|
|
105
|
+ $this->entity_manager->merge($this->getReference('user_bux')),
|
|
106
|
+ $this->entity_manager->merge($this->getReference('user_jean')),
|
|
107
|
+ $this->entity_manager->merge($this->getReference('user_paul')),
|
|
108
|
+ $this->entity_manager->merge($this->getReference('user_bob'))
|
|
109
|
+ ), $group_fan_de_psytrance);
|
|
110
|
+
|
|
111
|
+ // Tags
|
|
112
|
+ $this->groupHasTags(array(
|
|
113
|
+ $this->entity_manager->merge($this->getReference('tag_medieval'))
|
|
114
|
+ ), $group_dudeldrum);
|
|
115
|
+
|
|
116
|
+ $this->groupHasTags(array(
|
|
117
|
+ $this->entity_manager->merge($this->getReference('tag_psytrance'))
|
|
118
|
+ ), $group_fan_de_psytrance);
|
|
119
|
+
|
|
120
|
+ $this->entity_manager->flush();
|
|
121
|
+ }
|
|
122
|
+}
|