Selaa lähdekoodia

Ajout fixtures: Relations (follow) entre Users.

bastien 13 vuotta sitten
vanhempi
commit
4acc073252
1 muutettua tiedostoa jossa 26 lisäystä ja 6 poistoa
  1. 26 6
      src/Muzich/UserBundle/DataFixtures/ORM/LoadUserData.php

+ 26 - 6
src/Muzich/UserBundle/DataFixtures/ORM/LoadUserData.php Näytä tiedosto

7
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
 use Symfony\Component\DependencyInjection\ContainerInterface;
8
 use Symfony\Component\DependencyInjection\ContainerInterface;
9
 use Muzich\CoreBundle\Entity\User;
9
 use Muzich\CoreBundle\Entity\User;
10
+use Muzich\CoreBundle\Entity\FollowUser;
10
 
11
 
11
 class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
12
 class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
12
 {
13
 {
32
    * @param string $email
33
    * @param string $email
33
    * @param string $password_raw
34
    * @param string $password_raw
34
    * @param array $roles
35
    * @param array $roles
36
+   * 
37
+   * @return User
35
    */
38
    */
36
   protected function createUser($username, $email, $password_raw, $superadmin = false, $enabled = true)
39
   protected function createUser($username, $email, $password_raw, $superadmin = false, $enabled = true)
37
   {
40
   {
49
     $this->user_manager->updateUser($user, false);
52
     $this->user_manager->updateUser($user, false);
50
     $this->entity_manager->persist($user);
53
     $this->entity_manager->persist($user);
51
     $this->addReference('user_'.$username, $user);
54
     $this->addReference('user_'.$username, $user);
55
+    
56
+    return $user;
57
+  }
58
+  
59
+  protected function heFollowHim($follower, $followed)
60
+  {
61
+    $heFollowHim = new FollowUser();
62
+    $heFollowHim->setFollower($follower);
63
+    $heFollowHim->setFollowed($followed);
64
+    $follower->addFollowUser($heFollowHim);
65
+    $this->entity_manager->persist($heFollowHim);
52
   }
66
   }
53
   
67
   
54
   public function load($entity_manager)
68
   public function load($entity_manager)
56
     $this->entity_manager = $entity_manager;
70
     $this->entity_manager = $entity_manager;
57
     $this->user_manager = $this->container->get('fos_user.user_manager');
71
     $this->user_manager = $this->container->get('fos_user.user_manager');
58
     
72
     
59
-    $this->createUser('admin', 'admin@root', 'toor');
60
-    $this->createUser('bux', 'bux@root', 'toor');
61
-    $this->createUser('jean', 'jean@root', 'toor');
62
-    $this->createUser('paul', 'paul@root', 'toor');
63
-    $this->createUser('bob', 'bob@root', 'toor');
64
-    $this->createUser('joelle', 'joelle@root', 'toor');
73
+    // Création des Users
74
+    $admin  = $this->createUser('admin', 'admin@root', 'toor');
75
+    $bux    = $this->createUser('bux', 'bux@root', 'toor');
76
+    $jean   = $this->createUser('jean', 'jean@root', 'toor');
77
+    $paul   = $this->createUser('paul', 'paul@root', 'toor');
78
+    $bob    = $this->createUser('bob', 'bob@root', 'toor');
79
+    $joelle = $this->createUser('joelle', 'joelle@root', 'toor');
65
 
80
 
81
+    // Relations
82
+    $this->heFollowHim($bux, $jean);
83
+    $this->heFollowHim($bux, $paul);
84
+    $this->heFollowHim($joelle, $bux);
85
+    
66
     $this->entity_manager->flush();
86
     $this->entity_manager->flush();
67
   }
87
   }
68
 }
88
 }