public function recoverAction(Person $user) { $reset = new PasswordRecover($user); $em = $this->getDoctrine()->getManager(); $em->persist($reset); $em->flush(); $message = \Swift_Message::newInstance()->setSubject('roeselarevrijwilligt.be wachtwoord reset')->setFrom('*****@*****.**')->setTo($user->getEmail())->setBody($this->renderView('email/reset_email.html.twig', array('recover' => $reset)), 'text/html'); $this->get('mailer')->send($message); }
/** *@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()); }
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(); }
private function createCharacter($info) { $character = new Person(); $character->setName($info['character']); $actor = $this->em->getRepository('AppBundle:Actor')->findByIdTrakt($info['person']['ids']['trakt']); if (!$actor) { $actor = new Actor(); $actor->setName($info['person']['name'])->setIdTrakt($info['person']['ids']['trakt'])->setSlug($info['person']['ids']['slug'])->setBirthday(new \DateTime($info['person']['birthday']))->setBirthplace($info['person']['birthplace'])->setBiography($info['person']['biography']); if ($info['person']['death']) { $actor->setDeath(new \DateTime($info['person']['death'])); } $this->insertImage($actor, $info['person']['images']); $this->em->persist($actor); } else { $actor = $actor[0]; } $character->setActor($actor); $this->em->persist($character); return $character; }
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; }
/** * @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(); }
/** * Creates a new Person entity. * * @Route("/step/1", name="person_create") * */ public function createPersonAction(Request $request) { if (!$request->isXmlHttpRequest()) { return new JsonResponse(['message' => 'You can access this only using Ajax!'], 400); } $entity = new Person(); $entity->setIpAddress(ip2long($request->getClientIp())); $form = $this->createPersonForm($entity); $form->handleRequest($request); if ($request->isMethod('POST')) { if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); return new JsonResponse(['message' => 'Success!', 'id' => $entity->getId(), 'step' => 2], 200); } } else { return $response = new JsonResponse(['form' => $this->renderView(':form:personInfo.html.twig', ['entity' => $entity, 'form' => $form->createView()])], 200); } $response = new JsonResponse(['message' => 'Error', 'form' => $this->renderView(':form:formBody.html.twig', ['entity' => $entity, 'form' => $form->createView()])], 400); return $response; }
public function load(ObjectManager $manager) { $orange = new Person(); $orange->setName('Irina HR')->setEmail('*****@*****.**')->setTelephone('0744.123.456'); $manager->persist($orange); $orangeBucurestiVictoria = new Person(); $orangeBucurestiVictoria->setName('Bogdan Negru')->setEmail('*****@*****.**')->setTelephone('0744.654.321'); $manager->persist($orangeBucurestiVictoria); $orangeBrasovTehnic = new Person(); $orangeBrasovTehnic->setName('Claudia Beschea')->setEmail('*****@*****.**')->setTelephone('0744.744.447'); $manager->persist($orangeBrasovTehnic); $orangeBrasovMuresenilor = new Person(); $orangeBrasovMuresenilor->setName('Horia Dan')->setEmail('*****@*****.**')->setTelephone('0747.747.474'); $manager->persist($orangeBrasovMuresenilor); $orangeBrasovSaturn = new Person(); $orangeBrasovSaturn->setName('Cristina Vladuca')->setEmail('*****@*****.**')->setTelephone('0743.219.876'); $manager->persist($orangeBrasovSaturn); $orangeBrasovCoresi = new Person(); $orangeBrasovCoresi->setName('Anca Hirica')->setEmail('*****@*****.**')->setTelephone('0741.234.567'); $manager->persist($orangeBrasovCoresi); $contactCargus = new Person(); $contactCargus->setName('Cristina Tunari')->setEmail('*****@*****.**')->setTelephone('0771.177.771'); $manager->persist($contactCargus); $contactDepartamentCargus = new Person(); $contactDepartamentCargus->setName('Ionel Ionelule')->setEmail('*****@*****.**')->setTelephone('0771.717.717'); $manager->persist($contactDepartamentCargus); $manager->flush(); $this->addReference('contact-orange', $orange); $this->addReference('contact-orange-bucuresti-victoria', $orangeBucurestiVictoria); $this->addReference('contact-orange-brasov-tehnic', $orangeBrasovTehnic); $this->addReference('contact-orange-brasov-muresenilor', $orangeBrasovMuresenilor); $this->addReference('contact-orange-brasov-coresi', $orangeBrasovCoresi); $this->addReference('contact-orange-brasov-saturn', $orangeBrasovSaturn); $this->addReference('contact-cargus', $contactCargus); $this->addReference('contact-departament-cargus', $contactDepartamentCargus); }
/** * @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("/{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; }
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(); } }
/** * Does this course have the named user as a person yet? * * @param \AppBundle\Entity\Person $user * * @return Boolean */ public function hasUser(\AppBundle\Entity\Person $user) { foreach ($this->users as $u) { if ($u->getId() === $user->getId()) { return true; } } return false; }
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(); }
/** * Create a list of all notifications * @param Person $user a user * @param Organisation $organisation an organisation * @param Vacancy $vacancy a vacancy * @return Response */ public function listNotificationsAction($user, $organisation = null, $vacancy = null) { $digestNotifications = []; $qb = $this->getDoctrine()->getManager()->createQueryBuilder(); $qb->select(array('dE'))->from('AppBundle:DigestEntry', 'dE')->where($qb->expr()->andX($qb->expr()->eq('dE.handled', 0), $qb->expr()->eq('dE.user', $user->getId()), $qb->expr()->neq('dE.event', 1))); if ($organisation) { $qb->where('dE.Organisation = :organisation')->setParameter('organisation', $organisation->getId()); } if ($vacancy) { $qb->where('dE.vacancy = :vacancy')->setParameter('vacancy', $vacancy->getId()); } $qb->add('orderBy', 'dE.id DESC'); $digests = $qb->getQuery()->getResult(); foreach ($digests as $digest) { $textAndActionLink = $this->getTextAndActionLinkForEvent($digest); array_push($digestNotifications, $textAndActionLink); } return $this->render("person/persoon_notificaties.html.twig", ["notifications" => $digestNotifications]); }
/** * Include User * * @param Person $person * @return \League\Fractal\Resource\Item */ public function includeUser(Person $person) { return $this->item($person->getUser(), new UserTransformer()); }
/** * {@inheritDoc} */ public function getAge() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAge', array()); return parent::getAge(); }
/** * @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 testTelephone * @return array containing all fringe cases identified @ current */ public function contactOptionsProvider() { $person = new Person(); $person->setPlainPassword("thisIsSupersecret,Dog!"); $personMail = clone $person; $personMail->setEmail("*****@*****.**"); $personTel = clone $person; $personTel->setTelephone('0493635780'); $personOrganisation = clone $person; $personOrganisation->setOrganisation(new Organisation()); return array('only email' => array($personMail, 0), 'only tel' => array($personTel, 0), 'only organisation' => array($personOrganisation, 0), 'email and tel' => array($personMail->setTelephone("0493635780"), 0), 'email and organisation' => array($personOrganisation->setEmail("*****@*****.**"), 0), 'tel and organisation' => array($personTel->setOrganisation(new Organisation()), 0), 'all three' => array($personMail->setOrganisation(new Organisation()), 0), 'none' => array($person, 1)); }