Browse Source

Ajout de fixtures pour les elements favoris.

bastien 12 years ago
parent
commit
9eb64613f2

+ 58 - 0
src/Muzich/CoreBundle/DataFixtures/ORM/LoadUsersElementsFavoritesData.php View File

@@ -0,0 +1,58 @@
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\UsersElementsFavorites;
10
+
11
+class LoadUsersElementsFavoritesData  extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
12
+{
13
+  
14
+  private $container;
15
+  private $entity_manager;
16
+  
17
+  public function setContainer(ContainerInterface $container = null)
18
+  {
19
+    $this->container = $container;
20
+  }
21
+  
22
+  public function getOrder()
23
+  {
24
+    return 102; // the order in which fixtures will be loaded
25
+  }
26
+  
27
+  /**
28
+   *  
29
+   */
30
+  protected function createRecord($user, $element)
31
+  {
32
+    $favorite = new UsersElementsFavorites();
33
+    $favorite->setUser($user);
34
+    $favorite->setElement($element);
35
+    $this->entity_manager->persist($favorite);
36
+    //$this->addReference('user_tag_'.$user->getId().'_'.$tag->getId(), $userTag);
37
+  }
38
+  
39
+  public function load($entity_manager)
40
+  {
41
+    $this->entity_manager = $entity_manager;
42
+
43
+    // favoris de bux
44
+    $bux = $this->entity_manager->merge($this->getReference('user_bux'));
45
+    $paul = $this->entity_manager->merge($this->getReference('user_paul'));
46
+    
47
+    $youtube_heretik_1 = $this->getReference('element_youtube_heretik_1');
48
+    $youtube_djfab_1 = $this->getReference('element_youtube_djfab_1');
49
+    $jamendo_caio_1 = $this->getReference('element_jamendo_caio_1');
50
+    
51
+    $this->createRecord($bux, $youtube_heretik_1);
52
+    $this->createRecord($bux, $youtube_djfab_1);
53
+    $this->createRecord($paul, $youtube_heretik_1);
54
+    $this->createRecord($paul, $jamendo_caio_1);
55
+    
56
+    $this->entity_manager->flush();
57
+  }
58
+}