/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $user = new User(); $user->addMoviesCategory($this->getReference('cat2')); $user->addMoviesCategory($this->getReference('cat3')); $user->setPreferredMovie($this->getReference('movie1')); $user->setPhoto($this->getReference('photo1')); $user->setUsername('Tyrion'); $user->setFirstName('Tyrion'); $user->setLastName('Lannister'); $user->setPlainPassword('password'); $user->setEmail('*****@*****.**'); $user->setEnabled(true); $user->addRole('ROLE_USER'); $manager->persist($user); $this->setReference('user1', $user); $user = new User(); $user->addMoviesCategory($this->getReference('cat1')); $user->addMoviesCategory($this->getReference('cat5')); $user->setPreferredMovie($this->getReference('movie2')); $user->setPhoto($this->getReference('photo2')); $user->setUsername('Jaime'); $user->setFirstName('Jaime'); $user->setLastName('Lannister'); $user->setPlainPassword('password'); $user->setEmail('*****@*****.**'); $user->setEnabled(true); $user->addRole('ROLE_USER'); $manager->persist($user); $this->setReference('user2', $user); $user = new User(); $user->addMoviesCategory($this->getReference('cat1')); $user->addMoviesCategory($this->getReference('cat2')); $user->addMoviesCategory($this->getReference('cat3')); $user->setPreferredMovie($this->getReference('movie3')); $user->setPhoto($this->getReference('photo3')); $user->setUsername('Arya'); $user->setFirstName('Arya'); $user->setLastName('Stark'); $user->setPlainPassword('password'); $user->setEmail('*****@*****.**'); $user->setEnabled(true); $user->addRole('ROLE_USER'); $manager->persist($user); $this->setReference('user3', $user); $user = new User(); $user->addMoviesCategory($this->getReference('cat5')); $user->setPreferredMovie($this->getReference('movie4')); $user->setPhoto($this->getReference('photo4')); $user->setUsername('Jon'); $user->setFirstName('Jon'); $user->setLastName('Snow'); $user->setPlainPassword('password'); $user->setEmail('*****@*****.**'); $user->setEnabled(true); $user->addRole('ROLE_USER'); $manager->persist($user); $this->setReference('user4', $user); $manager->flush(); }
/** * @param \AppBundle\Entity\User $user */ public function updateUser(User $user) { if (($avatar = $user->getAvatar()) !== null) { $avatar->setName($user->getUsername()); } $this->em->persist($avatar); $this->em->persist($user); $this->em->flush(); }
/** * Generates a Customer with his addresses. * * @param ObjectManager $manager * @param int $i Random number to avoid username collision * * @return Customer */ protected function generateCustomer(ObjectManager $manager, $i) { $faker = $this->getFaker(); $firstName = $faker->firstName(); $lastName = $faker->lastName(); $email = $faker->email(); $username = $faker->userName(); if (0 === $i % 50 && $this->hasReference('customer-johndoe')) { return $this->getReference('customer-johndoe'); } // Customer $customer = new Customer(); $customer->setTitle(array_rand(array(BaseCustomer::TITLE_MLLE, BaseCustomer::TITLE_MME, BaseCustomer::TITLE_MR))); $customer->setFirstname($firstName); $customer->setLastname($lastName); $customer->setEmail($email); $customer->setBirthDate($faker->datetime()); $customer->getBirthPlace($faker->city()); $customer->setPhoneNumber($faker->phoneNumber()); $customer->setMobileNumber($faker->phoneNumber()); $customer->setFaxNumber($faker->phoneNumber()); $customer->setLocale('fr'); $customer->setIsFake(true); // Customer billing address $customerBillingAddress = new Address(); $customerBillingAddress->setType(BaseAddress::TYPE_BILLING); $customerBillingAddress->setCustomer($customer); $customerBillingAddress->setCurrent(true); $customerBillingAddress->setName('My billing address'); $customerBillingAddress->setFirstname($customer->getFirstname()); $customerBillingAddress->setLastname($customer->getLastname()); $customerBillingAddress->setAddress1($faker->address()); $customerBillingAddress->setPostcode($faker->postcode()); $customerBillingAddress->setCity($faker->city()); $customerBillingAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode()); $customerBillingAddress->setPhone($faker->phoneNumber()); // Customer contact address $customerContactAddress = new Address(); $customerContactAddress->setType(BaseAddress::TYPE_CONTACT); $customerContactAddress->setCustomer($customer); $customerContactAddress->setCurrent(true); $customerContactAddress->setName('My contact address'); $customerContactAddress->setFirstname($customer->getFirstname()); $customerContactAddress->setLastname($customer->getLastname()); $customerContactAddress->setAddress1($faker->address()); $customerContactAddress->setPostcode($faker->postcode()); $customerContactAddress->setCity($faker->city()); $customerContactAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode()); $customerContactAddress->setPhone($customer->getPhoneNumber()); // Customer delivery address $customerDeliveryAddress = new Address(); $customerDeliveryAddress->setType(BaseAddress::TYPE_DELIVERY); $customerDeliveryAddress->setCustomer($customer); $customerDeliveryAddress->setCurrent(true); $customerDeliveryAddress->setName('My delivery address'); $customerDeliveryAddress->setFirstname($customer->getFirstname()); $customerDeliveryAddress->setLastname($customer->getLastname()); $customerDeliveryAddress->setAddress1($faker->address()); $customerDeliveryAddress->setPostcode($faker->postcode()); $customerDeliveryAddress->setCity($faker->city()); $customerDeliveryAddress->setCountryCode(0 === $i % 50 ? 'FR' : $faker->countryCode()); $customerDeliveryAddress->setPhone($faker->phoneNumber()); $customer->addAddress($customerBillingAddress); $customer->addAddress($customerContactAddress); $customer->addAddress($customerDeliveryAddress); // User if (0 === $i % 10) { $user = $this->getReference('user-johndoe'); $this->setReference('customer-johndoe', $customer); } else { /** @var \Sonata\UserBundle\Model\User $user */ $user = new User(); $user->setUsername($i . '-' . $username); $user->setUsernameCanonical($i . '-' . $username); $user->setEmail($i . '_' . $email); $user->setEmailCanonical($email); $user->setPlainPassword('customer'); } $customer->setUser($user); $manager->persist($customerBillingAddress); $manager->persist($customerContactAddress); $manager->persist($customerDeliveryAddress); $manager->persist($user); $manager->persist($customer); return $customer; }