public function load(ObjectManager $manager) { $symbonfy_base_dir = $this->container->getParameter('kernel.root_dir'); $data_dir = $symbonfy_base_dir . '/Resources/data/'; $row = 0; $fd = fopen($data_dir . 'person.csv', "r"); if ($fd) { while (($data = fgetcsv($fd)) !== false) { $row++; if ($row == 1) { continue; } //skip header $person = new Person(); $person->setName($data[0]); $person->setAge($data[1]); $birthDate = \DateTime::createFromFormat('d/m/Y', $data[2]); $person->setBirthDate($birthDate); $person->setHeight($data[3]); $person->setEmail($data[4]); $person->setPhone($data[5]); $person->setGender($data[6]); $person->setDescends($data[7]); $person->setVehicle($data[8]); $person->setPreferredLanguage($data[9]); $person->setEnglishLevel($data[10]); $person->setPersonalWebSite($data[11]); $person->setCardNumber($data[12]); $person->setIBAN($data[13]); $manager->persist($person); } fclose($fd); } $manager->flush(); }
public function loadUserByOAuthUserResponse(UserResponseInterface $response) { //Data from response $email = $response->getEmail(); $firstname = $response->getFirstName(); $lastname = $response->getLastName(); $nickname = $firstname . $lastname; //Check if this user already exists in our app DB $qb = $this->doctrine->getManager()->createQueryBuilder(); $qb->select('u')->from('AppBundle:Person', 'u')->where('u.email = :gmail')->setParameter('gmail', $email)->setMaxResults(1); $result = $qb->getQuery()->getResult(); //add to database if doesn't exists if (!count($result)) { $person = new Person(); $person->setFirstname($firstname); $person->setLastname($lastname); $person->setUsername($nickname); $person->setEmail($email); //$user->setRoles('ROLE_USER'); //Set some wild random pass since its irrelevant, this is Google login $factory = $this->container->get('security.encoder_factory'); $encoder = $factory->getEncoder($person); $password = $encoder->encodePassword(md5(uniqid()), $person->getSalt()); $person->setPassword($password); $em = $this->doctrine->getManager(); $em->persist($person); $em->flush(); } else { $person = $result[0]; } //set id $this->session->set('id', $person->getId()); return $person; }
/** * @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)); }
/** * the dataProvider for testLastName * @return array containing all fringe cases identified @ current */ public function lastNameProvider() { $person = new Person(); $person->setPlainPassword("thisIsSupersecret,Dog!"); $person->setEmail("*****@*****.**"); return array('normal' => array("Dragonslayer", 0), 'hyphened' => array('Sint-Joost', 0), 'dot' => array("St.Joris", 0), 'roof' => array("Înspirationless", 0), 'eyes' => array("Özer", 0), 'tail' => array("Anná", 0), 'reversed tail' => array("Annà", 0), '@' => array("joost@the movies straat", 1), '/' => array("Sint/Jooststraat", 1), ';' => array("i am a programmer; straat;", 1), '<' => array("3 is < than 4 street", 1), '>' => array("4 is > than 3 street", 1), '(' => array("( is an opening brace street", 1), ')' => array(") is a closing brace street", 1), '[' => array("[ is an opening brace street", 1), ']' => array("] is a closing brace street", 1), '{' => array("{ is an opening brace street", 1), '}' => array("} is a closing brace street", 1), ':' => array(": is not allowed", 1), '?' => array("? is not allowed", 1), '|' => array("| is not allowed", 1), '\\' => array("\\ is not allowed", 1), '!' => array("! is not allowed", 1), '#' => array("# is not allowed", 1), '$' => array("\$ is not allowed", 1), '%' => array("% is not allowed", 1), '&' => array("& is not allowed", 1), '*' => array("* is not allowed", 1), '+' => array("+ is not allowed", 1), '=' => array("= is not allowed", 1), '€' => array("€ is not allowed", 1), '_' => array("_ is not allowed", 1), '`' => array("` is not allowed", 1), '~' => array("~ is not allowed", 1), ',' => array(", is not allowed", 1), 'too short' => array("a", 1), 'too long' => array("This name is far too long for a person i say governor", 1), 'empty' => array("", 1), 'numeric' => array(10, 1), 'null' => array(null, 1)); }