protected function insertUsers(InputInterface $input, OutputInterface $output)
 {
     if ($lastUser = $this->doctrine->getRepository('AppBundle:Person')->findOneBy([], ['id' => 'DESC'])) {
         $startId = $lastUser->getId();
     } else {
         $startId = 0;
     }
     $em = $this->doctrine->getManager();
     $usercount = $startId + $input->getArgument('usercount');
     $faker = \Faker\Factory::create();
     for ($i = $startId; $i < $usercount; $i++) {
         $person = new Person();
         $person->setUsername(sprintf('exampleuser%d', $i))->setFirstname($faker->firstName)->setLastname($faker->lastName)->setPassword('password')->setEmail($faker->safeEmail);
         $output->writeln(sprintf('<info>Added user %s (%s %s)</info>', $person->getUsername(), $person->getFirstname(), $person->getLastname()));
         $em->persist($person);
         $em->flush();
     }
 }
Ejemplo n.º 2
0
 /**
  * @Route("/{id}", name="update_person")
  * @Method("PUT")
  * @ParamConverter("person", converter="fos_rest.request_body")
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function updatePerson($id, Person $person)
 {
     $em = $this->getDoctrine()->getManager();
     $dbPerson = new Person();
     $dbPerson = $this->getDoctrine()->getRepository('AppBundle:Person')->find($id);
     $dbPerson->setName($person->getName());
     $dbPerson->setAge($person->getAge());
     $dbPerson->setEmail($person->getEmail());
     $dbPerson->setLastName($person->getLastname());
     $dbPerson->setTelephone($person->getTelephone());
     $errors = $this->getErrors($person);
     if (isset($errors)) {
         return $this->view($errors, 400);
     }
     $em->persist($dbPerson);
     $em->flush();
     return $dbPerson;
 }
Ejemplo n.º 3
0
 /**
  * Turn this item object into a generic array
  *
  * @return array
  */
 public function transform(Person $person)
 {
     return ['id' => (int) $person->getId(), 'firstname' => $person->getFirstname(), 'lastname' => $person->getLastname(), 'email' => $person->getEmail(), 'organizationId' => $person->getOrganization()->getId(), 'fileCount' => $person->getNumFiles(), 'createdAt' => $person->getCreatedAt(), 'updatedAt' => $person->getUpdatedAt()];
 }