Example #1
0
 public function registrationOauthCompleted(OAuthResponseEvent $event)
 {
     $em = $this->em;
     if (!$event->getUser()->isEnabled()) {
         return;
     }
     $user = $event->getUser();
     if ($user->getAthlete() == null) {
         $athlete = new Athlete();
         $athlete->setName($user->getUsername());
         $profilePicture = $event->getResponse()->getProfilePicture();
         if ($profilePicture != null) {
             $image = new Image();
             $fileContent = file_get_contents($profilePicture);
             $image->setName("Facebook profile image");
             $image->setContent(base64_encode($fileContent));
             $athlete->setImage($image);
         }
         $user->setAthlete($athlete);
         $em->persist($athlete);
         $em->flush();
     }
 }
Example #2
0
 /**
  * Proces club before form handleRequest
  * 
  * @param Club $club
  */
 private function processForm(Athlete $athlete)
 {
     if ($athlete->getSlug() == null) {
         $em = $this->getDoctrine()->getManager();
         $i = 1;
         $slug = Slug::slugify($athlete->getTitle());
         $exists = $em->getRepository("OesteveGrupetaBundle:Athlete")->findOneBy(array('slug' => $slug));
         while ($exists != null) {
             $slug = Slug::slugify($athlete->getTitle() . '-' . $i++);
             $exists = $em->getRepository("OesteveGrupetaBundle:Athlete")->findOneBy(array('slug' => $slug));
         }
         $athlete->setSlug($slug);
     }
     if ($athlete->getImageFile() != null) {
         $image = new Image();
         $image->setFile($athlete->getImageFile());
         $image->setName($athlete->getImageFile()->getClientOriginalName());
         $athlete->setImage($image);
     }
     if ($athlete->getCoverImageFile() != null) {
         $image = new Image();
         $image->setFile($athlete->getCoverImageFile());
         $image->setName($athlete->getCoverImageFile()->getClientOriginalName());
         $athlete->setCoverImage($image);
     }
     return $athlete;
 }