/**
  * @Given existen las universidades:
  */
 public function thereAreUniversities(TableNode $tableNode)
 {
     foreach ($tableNode->getHash() as $universityHash) {
         $university = new University();
         $university->setName($universityHash['nombre']);
         $university->setCity($universityHash['ciudad']);
         $university->setProvince($universityHash['provincia']);
         $university->setCif($universityHash['cif']);
         $university->setPostcode($this->faker->boolean());
         $university->setAddress($this->faker->word);
         $university->setType($this->faker->word);
         $university->setSlug($this->faker->word);
         $this->getEntityManager()->persist($university);
     }
     $this->getEntityManager()->flush();
 }
Esempio n. 2
0
 /**
  * Exports tax data from one university.
  *
  * @param University $university
  * @return TaxData
  */
 public static function copyFromUniversity(University $university)
 {
     $taxdata = new TaxData();
     $taxdata->setName($university->getName());
     $taxdata->setAddress($university->getAddress());
     $taxdata->setCity($university->getCity());
     $taxdata->setProvince($university->getProvince());
     $taxdata->setPostcode($university->getPostcode());
     $taxdata->setCif($university->getCif());
     return $taxdata;
 }
Esempio n. 3
0
 public function editAction(Request $request)
 {
     $user = $this->getUser();
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException('This user does not have access to this section.');
     }
     /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
     $dispatcher = $this->get('event_dispatcher');
     $event = new GetResponseUserEvent($user, $request);
     $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
     $formFactory = $this->get('fos_user.profile.form.factory');
     $form = $formFactory->createForm();
     $form->setData($user);
     $form->handleRequest($request);
     //        if ( $request->getMethod('POST') ){
     //            dump($form);
     //            exit;
     //        }
     if ($request->getMethod() == 'POST') {
         $em = $this->getDoctrine()->getManager();
         //city
         $cityTitle = $user->getCity();
         $city = $this->getDoctrine()->getRepository('AppBundle:City')->findOneByTitle($cityTitle);
         if ($city === null) {
             $city = new City();
             $city->setTitle($cityTitle);
             $city->setCountry($user->getCountry());
             $em->persist($city);
             $em->flush($city);
             $em->refresh($city);
         }
         $user->setCity($city);
         //university
         $universityTitle = $user->getUniversity();
         $university = $this->getDoctrine()->getRepository('AppBundle:University')->findOneByTitle($cityTitle);
         if ($university === null) {
             $university = new University();
             $university->setTitle($universityTitle);
             $university->setCountry($user->getCountry());
             $em->persist($university);
             $em->flush($university);
             $em->refresh($university);
         }
         $user->setUniversity($university);
         $user->setCertificate([]);
         /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
         $userManager = $this->get('fos_user.user_manager');
         $event = new FormEvent($form, $request);
         $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
         $userManager->updateUser($user);
         if (null === ($response = $event->getResponse())) {
             $url = $this->generateUrl('fos_user_profile_show');
             $response = new RedirectResponse($url);
         }
         $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
         return $response;
     }
     return $this->render('FOSUserBundle:Profile:edit.html.twig', array('form' => $form->createView()));
 }
 /**
  * Save new Universities.
  *
  * @Route("/api/university/save_new_university", name="save_new_university")
  * @Method({"POST"})
  */
 public function saveNewUniversityAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $serializer = $this->container->get('jms_serializer');
     $stateRepo = $em->getRepository("AppBundle:State");
     $request_data = json_decode($request->getContent(), true);
     $message_array = array();
     foreach ($request_data as $university) {
         $university['universityStatus'] = "Activated";
         $universityEntity = new University();
         foreach ($university['campuses'] as $campus) {
             $campusName = null;
             $state = null;
             $campusEntity = new Campus();
             if (array_key_exists('campusName', $campus)) {
                 $campusEntity->setCampusName($campus['campusName']);
             }
             if (array_key_exists('state', $campus)) {
                 $campusEntity->setState($stateRepo->findOneById($campus['state']));
             }
             $universityEntity->addCampus($campusEntity);
         }
         $universityForm = $this->createForm(new UniversityType(), $universityEntity);
         $universityForm->submit($university);
         if ($universityForm->isValid()) {
             $em->persist($universityEntity);
             $em->flush();
             array_push($message_array, array('success' => 'University Successfully Created'));
         } else {
             $em->clear();
             $universityFormErrorJson = $serializer->serialize($universityForm, 'json');
             array_push($message_array, json_decode($universityFormErrorJson, true));
         }
     }
     $json = $serializer->serialize($message_array, 'json');
     $response = new Response($json, 200);
     return $response;
 }
Esempio n. 5
0
 /**
  * Create an user if he doesn't exists.
  * @param $username
  * @param $password
  * @param null $role
  * @param bool $create_entities
  * @param string $enabled
  * @param null $address
  * @param array $groups
  * @param bool $flush
  * @return UserInterface
  */
 public function thereIsUser($username, $password, $role = null, $create_entities = false, $enabled = 'yes', $address = null, $groups = array(), $flush = true)
 {
     $addressData = explode(',', $address);
     $addressData = array_map('trim', $addressData);
     if ($create_entities == true) {
         $student_delegation = new StudentDelegation();
         $student_delegation->setName($this->faker->word);
         $student_delegation->setCity($this->faker->word);
         $student_delegation->setProvince($this->faker->word);
         $student_delegation->setPostcode($this->faker->boolean());
         $student_delegation->setAddress($this->faker->word);
         $student_delegation->setSlug($this->faker->word);
         $college = new College();
         $college->addStudentsDelegation($student_delegation);
         $college->setName($this->faker->word);
         $college->setCity($this->faker->word);
         $college->setProvince($this->faker->word);
         $college->setPostcode($this->faker->boolean());
         $college->setAddress($this->faker->word);
         $college->setSlug($this->faker->word);
         $this->getEntityManager()->persist($college);
         $university = new University();
         $university->addCollege($college);
         $university->setName($this->faker->word);
         $university->setCity($this->faker->word);
         $university->setProvince($this->faker->word);
         $university->setCif($this->faker->word);
         $university->setPostcode($this->faker->boolean());
         $university->setAddress($this->faker->word);
         $university->setType($this->faker->word);
         $university->setSlug($this->faker->word);
         $student_delegation->setCollege($college);
         $college->setUniversity($university);
         $this->getEntityManager()->persist($student_delegation);
         $this->getEntityManager()->persist($university);
         $this->getEntityManager()->flush();
     }
     /** @var User $user */
     $user = new User();
     $user->setUsername($username);
     $user->setFirstname($this->faker->firstName);
     $user->setLastname($this->faker->lastName);
     $user->setFirstname(null === $address ? $this->faker->firstName : $addressData[0]);
     $user->setLastname(null === $address ? $this->faker->lastName : $addressData[1]);
     $user->setEmail($username . '@ritsiGA.com');
     $user->setEnabled('yes' === $enabled);
     $user->setPlainPassword($password);
     if ($create_entities == true) {
         $user->setStudentDelegation($student_delegation);
     }
     if (null !== $role) {
         $user->addRole($role);
     }
     $this->getEntityManager()->persist($user);
     foreach ($groups as $groupName) {
         if ($group = $this->findOneByName('group', $groupName)) {
             $user->addGroup($group);
         }
     }
     if ($flush) {
         $this->getEntityManager()->flush();
     }
     return $user;
 }