Browse Source

Ajout des fixtures Group (plus followers et tags)

bastien 13 years ago
parent
commit
8a7638b29b

+ 122 - 0
src/Muzich/CoreBundle/DataFixtures/ORM/LoadGroupData.php View File

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
+}

+ 1 - 1
src/Muzich/CoreBundle/DataFixtures/ORM/LoadTagData.php View File

45
       'instrumental', 'italiano', 'jam', 'jazz',  'jazzrock',  'jazzy', 'jungle',
45
       'instrumental', 'italiano', 'jam', 'jazz',  'jazzrock',  'jazzy', 'jungle',
46
       'keyboard', 'latin',  'latino',  'live', 'lofi', 'lounge', 'meditation', 
46
       'keyboard', 'latin',  'latino',  'live', 'lofi', 'lounge', 'meditation', 
47
       'melancolique', 'mellow',  'melodique', 'metal','metalcore','minimal', 
47
       'melancolique', 'mellow',  'melodique', 'metal','metalcore','minimal', 
48
-      'minimalism', 'minimaltechno', 'mix', 'movie' 
48
+      'minimalism', 'minimaltechno', 'mix', 'movie', 'medieval', 'psytrance'
49
       
49
       
50
       ) as $tag_name)
50
       ) as $tag_name)
51
     {
51
     {

+ 28 - 1
src/Muzich/CoreBundle/Entity/Group.php View File

34
   protected $name;
34
   protected $name;
35
   
35
   
36
   /**
36
   /**
37
+   * Description
38
+   * 
39
+   * @ORM\Column(type="text")
40
+   * @var type string
41
+   */
42
+  protected $description;
43
+  
44
+  /**
37
    * Si open est a vrai, cela traduit que les followers peuvent 
45
    * Si open est a vrai, cela traduit que les followers peuvent 
38
    * diffuser leur element en tant qu'élément de ce groupe.
46
    * diffuser leur element en tant qu'élément de ce groupe.
39
    * 
47
    * 
80
   public function __construct()
88
   public function __construct()
81
   {
89
   {
82
     $this->followers = new ArrayCollection();
90
     $this->followers = new ArrayCollection();
83
-    parent::__construct();
84
   }
91
   }
85
   
92
   
86
   /**
93
   /**
114
   }
121
   }
115
 
122
 
116
   /**
123
   /**
124
+   * Set description
125
+   *
126
+   * @param string $description
127
+   */
128
+  public function setDescription($description)
129
+  {
130
+    $this->description = $description;
131
+  }
132
+
133
+  /**
134
+   * Get description
135
+   *
136
+   * @return string 
137
+   */
138
+  public function getDescription()
139
+  {
140
+    return $this->description;
141
+  }
142
+
143
+  /**
117
    * Set open
144
    * Set open
118
    *
145
    *
119
    * @param boolean $open
146
    * @param boolean $open