private function createFakeProvider() { $provider = new Provider(); $baseFaker = \Faker\Factory::create(); $provider->setName($baseFaker->company); $provider->setCountry($baseFaker->country); $provider->setType($this->getRandomType()); $provider->setDescription($baseFaker->text(500)); $provider->setUrl($baseFaker->url); $provider->setLastModification($baseFaker->dateTime); $nb = rand(1, 5); for ($x = 0; $x <= $nb; $x++) { $contactFaker = \Faker\Factory::create(); $c = new Contact(); $c->setProvider($provider); $c->setFirstName($contactFaker->firstName); $c->setLastName($contactFaker->lastName); $c->setGender(Personne::GENDER_MALE); $c->setEmail($contactFaker->email); $c->setTelephone($contactFaker->phoneNumber); $c->setDescription($contactFaker->text(300)); $c->setComment($contactFaker->text(100)); $this->output('create fake contact'); $this->em->persist($c); } $this->em->persist($provider); $this->output('create fake provider'); return $provider; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $providerData = [['Partzilla', 'http://partzilla.com', 'USD', 9, null], ['Ronayers', 'http://ronayers.com', 'USD', 12, 19], ['Megazip', 'http://megazip.ru', 'RUB', 24, null]]; foreach ($providerData as $providerDataItem) { list($providerName, $providerUrl, $providerCurrency, $providerDeliveryLeft, $providerDeliveryRight, ) = $providerDataItem; $provider = new Provider(); $provider->setName($providerName); $provider->setUrl($providerUrl); $provider->setCurrency($providerCurrency); $provider->setDeliveryLeft($providerDeliveryLeft); $provider->setDeliveryRight($providerDeliveryRight); $manager->persist($provider); $this->addReference('provider-' . strtolower($providerName), $provider); } $manager->flush(); }
private function createProvider($name, $type, $url, $country, $description, $log) { try { $p = new Provider(); //if(($name == '') || ($name == null)) //throw new \Exception(); $p->setName($name); /* $this->output('$name: '.$name); $this->output('$type: '.$type); $this->output('$url: '.$url); $this->output('$country: '.$country); */ $p->setType($this->to_provider_type($type)); $p->setUrl($url); $p->setCountry($this->country_to_code($country)); $p->setDescription($description); $p->setComment($log); $this->em->persist($p); $this->em->flush(); return $p; } catch (\Exception $e) { echo $e->getMessage(); $this->output('cannot creat provider', 'error'); return null; } }