/** * @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(); }