LoadUserData::getOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Symfony Standard project.
5
 *
6
 * Copyright (c) 2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Application\Sonata\UserBundle\DataFixtures\ORM;
13
14
use Doctrine\Common\DataFixtures\AbstractFixture;
15
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
16
use Doctrine\Common\Persistence\ObjectManager;
17
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
20
/**
21
 * Loads users to the database.
22
 *
23
 * @author Jon Torrado <[email protected]>
24
 */
25
class LoadUserData extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface
26
{
27
    private static $names = [
28
        'Tricia Carbonneau',
29
        'Cindy Mendoza',
30
        'Alessandra Wollard',
31
        'Vernell Fleeman',
32
        'Chad Ferebee',
33
        'Olinda Resendez',
34
        'Iva Moniz',
35
        'Alec Cuthbertson',
36
        'Candie Foret',
37
        'Burma Stgermain',
38
        'Rosaline Spiegel',
39
        'Elois Hipsher',
40
        'Fleta Hatter',
41
        'Jordan Muirhead',
42
        'Shala Thrift',
43
        'Dannette Newell',
44
        'Brett Voigt',
45
        'Lesley Varney',
46
        'Rich Larocca',
47
        'Ofelia Deckert',
48
        'Tamera Bagdon',
49
        'Kecia Buttner',
50
        'Bronwyn Mattia',
51
        'Brooks Mcpartland',
52
        'Candelaria Buechner',
53
        'Yolando Dery',
54
        'Daniele Guan',
55
        'Ehtel Durrant',
56
        'Rocco Medlen',
57
        'Sally Cornejo',
58
        'Dorinda Riser',
59
        'Tana Berthiaume',
60
        'Clelia Senger',
61
        'Norbert Petteway',
62
        'Agatha Gaus',
63
        'Lauran Depaolo',
64
        'Treasa Waid',
65
        'Truman Sybert',
66
        'Annmarie Helt',
67
        'Librada Mistretta',
68
        'Kristan Mount',
69
        'Gertha Hines',
70
        'Ashley Mangual',
71
        'Florrie Hallford',
72
        'Pricilla Weekes',
73
        'Celestine Boelter',
74
        'Chas Manross',
75
        'Elvie Glavin',
76
        'Rolanda Mcspadden',
77
        'Kimberlee Wood',
78
    ];
79
80
    private $container;
81
82
    public function setContainer(ContainerInterface $container = null)
83
    {
84
        $this->container = $container;
85
    }
86
87
    /**
88
     * @return \FOS\UserBundle\Model\UserManagerInterface
89
     */
90
    public function getUserManager()
91
    {
92
        return $this->container->get('fos_user.user_manager');
93
    }
94
95
    public function load(ObjectManager $manager)
96
    {
97
        $manager = $this->getUserManager();
98
99
        // Create admin user
100
        $user = $manager->createUser();
101
        $user->setUsername('admin');
102
        $user->setEmail('admin@localhost');
103
        $user->setPlainPassword('admin');
104
        $user->setEnabled(true);
105
        $user->setSuperAdmin(true);
106
        $user->setLocked(false);
107
108
        $manager->updateUser($user);
109
110
        // Create some random users
111
        foreach (self::$names as $name) {
112
            $user = $manager->createUser();
113
            list($firstName, $lastName) = explode(' ', $name);
114
            $user->setUsername(strtolower($firstName));
115
            $user->setEmail($firstName . '@localhost');
116
            $user->setPlainPassword($firstName);
117
            $user->setFirstName($firstName);
118
            $user->setLastName($lastName);
119
            $user->setEnabled(true);
120
            $user->setLocked(false);
121
122
            $manager->updateUser($user);
123
        }
124
    }
125
126
    public function getOrder()
127
    {
128
        return 1;
129
    }
130
}
131