/**
  * @Route("/profile/new", name="new-profile")
  * @Security("has_role('ROLE_USER')")
  * @param Request $request
  * @return Response
  */
 public function newProfileAction(Request $request)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     $profile = new Profile();
     $profile->setUser($user->getId());
     $form = $this->createForm($this->get('form_profile_type'), $profile);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($profile);
         $em->flush();
         $this->addFlash('success', 'Profile has been added.');
         return $this->redirectToRoute('profiles');
     }
     return $this->render('default/new-profile.html.twig', array('form' => $form->createView()));
 }
 /**
  * @Route("/new", name="profile_new")
  * @Route("/edit/{id}", name="profile_edit", requirements={"id" = "\d+"})
  * @Template()
  */
 public function editAction(Request $request, $id = null)
 {
     $em = $this->get('doctrine')->getManager();
     $profile = null;
     if (is_null($id)) {
         $profile = new Profile();
         $profileExtended = new ProfileExtended();
         $profile->setProfileExtended($profileExtended);
     } else {
         $profile = $em->getRepository('AppBundle:Profile')->findProfileByIdJoined($id);
     }
     $form = $this->createForm(new ProfileType(), $profile, array())->add('save', 'submit', array('label' => 'app.buttons.save'));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($profile);
         $em->flush();
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('app.flash.profile.saved'));
         return new RedirectResponse($this->generateUrl('profile_show', array('id' => $profile->getId())));
     } elseif ($this->formHasErrors($form)) {
         $this->get('session')->getFlashBag()->add('danger', $this->get('translator')->trans('app.form.errors'));
     }
     return array('profile' => $profile, 'form' => $form->createView());
 }
 /**
  * Upload Profile Photo and update Profile
  *
  * @param Profile $profile
  * @param File $file
  * @param string $contentType
  */
 protected function uploadProfilePhoto(Profile $profile, File $file, $contentType)
 {
     // Upload the photo to S3
     $fileUrl = $this->get('service_photo_upload')->uploadPhoto($file, $contentType);
     // Update the Profile Photo
     $profile->setPhoto($fileUrl);
     $profile->setPhotoUploading(false);
     // Flush to DB
     $this->getDoctrine()->getManager()->flush($profile);
 }
 /**
  * Set profile
  *
  * @param Profile $profile
  * @return ProfileExtended
  */
 public function setProfile(Profile $profile)
 {
     $this->profile = $profile;
     $this->profileId = $profile->getId();
     return $this;
 }