public function load(ObjectManager $manager) { for ($i = 0; $i < 10000; $i++) { $names = array("Sergiu", "Irene", "Victor", "Oscar", "Antonio", "Jaime", "David", "Roberto", "Alba"); $names_last = array("Popa", "Lubelza", "Plaza", "Tejero", "Viyuela", "Moreno", "Garcia", "Herrero", "Barbero"); $person = new Person(); $person->setFirstName($names[array_rand($names)]); $person->setLastName($names_last[array_rand($names_last)]); $person->setBlind(rand(1, 100) % 2 == 0 ? true : false); // Set 2 random languages for each person $languages = array("English", "Spanish", "Romanian"); $levels = array("A1", "A2", "B1", "B2", "C1", "C2"); $j = 0; while ($j < 2) { $language = $manager->getRepository('AppBundle:Language')->findOneBy(array('language' => $languages[array_rand($languages)], 'level' => $levels[array_rand($levels)])); $current_languages = array(); foreach ($person->getLanguages() as $current) { $current_languages[] = $current->getId(); } if (!in_array($language->getId(), $current_languages)) { $person->addLanguage($language); $j++; } } $manager->persist($person); } $manager->flush(); }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Generating people...'); /** @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager = $this->getContainer()->get('doctrine')->getManager(); $faker = Factory::create(); $people = array(); for ($i = 0; $i < self::$NUMBER_Of_PERSONS; $i++) { $person = new Person(); $gender = rand(0, 1) == 0 ? Gender::MALE() : Gender::FEMALE(); $person->setFirstName($faker->format("firstName", array($gender->getName()))); $person->setLastName($faker->lastName); $person->setGender($gender); $person->setBirthday($faker->dateTimeBetween('-60 years', '-18 years')); $entityManager->persist($person); $people[] = $person; $output->write('.'); } $output->writeln(''); $output->writeln('Generating calendars with appointments...'); for ($i = 0; $i < self::$NUMBER_Of_CALENDARS; $i++) { $calendar = new Calendar(); $calendar->setPerson($faker->randomElement($people)); $entityManager->persist($calendar); for ($j = 0; $j < $faker->randomDigit; $j++) { $appointment = new Appointment(); $appointment->setWhen($faker->dateTimeThisYear); $appointment->setWhat($faker->text); $appointment->setCalendar($calendar); $entityManager->persist($appointment); } $output->write('.'); } $entityManager->flush(); }
/** *@Route("/test") **/ public function createAction() { $person = new Person(); $person->setFirstName('User' . rand(10, 10000)); $person->setLastName('lastname' . rand(10, 10000)); $person->setAge(rand(18, 99)); $em = $this->getDoctrine()->getManager(); $em->persist($person); $em->flush(); return new Response('Added New User: '******' ' . $person->getLastName() . ' with age:' . $person->getAge()); }
/** * @Route("/savePerson") */ public function savePersonAction(Request $request) { $firstName = $request->request->get('firstName'); $lastName = $request->request->get('lastName'); $address = $request->request->get('address'); $zip = $request->request->get('zipCode'); $city = $request->request->get('city'); $country = $request->request->get('country'); $email = $request->request->get('email'); $person = new Person(); $person->setFirstName($firstName); $person->setLastName($lastName); $person->setAddress($address); $person->setZip($zip); $person->setCity($city); $person->setCountry($country); $person->setEmail($email); $em = $this->getDoctrine()->getManager(); $em->persist($person); $em->flush(); $response = new JsonResponse(); $response->setData(array('response' => 'Created person entry with id ' . $person->getId())); return $response; }
/** * @Route("/person/create") */ public function createActionPerson() { $person = new Person(); $person->setLevelId(1); $person->setFirstName('A Foo Bar'); $person->setLastName('A Foo Bar'); $person->setRegisterDate('20.01.2015 15:35:35'); $person->setEmail('A Foo Bar'); $person->setPhonenumber('A Foo Bar'); $person->setPassword('A Foo Bar'); $em = $this->getDoctrine()->getManager(); $em->persist($person); $em->flush(); $personArray[] = $person->getId(); $personArray[] = $person->getLevelId(); $personArray[] = $person->getFirstName(); $personArray[] = $person->getLastName(); $personArray[] = $person->getRegisterDate(); $personArray[] = $person->getEmail(); $personArray[] = $person->getPhonenumber(); $personArray[] = $person->getPassword(); return new Response(json_encode($personArray)); }
/** * {@inheritDoc} */ public function setFirstName($firstName) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setFirstName', array($firstName)); return parent::setFirstName($firstName); }