Exemplo n.º 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();
     }
 }
Exemplo n.º 2
0
 /**
  * @Route("/{id}/image/", name="activity_image_add")
  * @Method("POST")
  */
 public function addImageAction($id, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('OesteveGrupetaBundle:Activity')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Activity entity.');
     }
     $authChecker = $this->get('security.authorization_checker');
     if (false === $authChecker->isGranted(ActivityVoter::EDIT, $entity)) {
         throw $this->createAccessDeniedException('Unauthorized access!');
     }
     $requestObj = json_decode($request->getContent());
     if (strpos($requestObj->content, ',') > 1 && strpos($requestObj->content, 'base64') > 1) {
         $fileContent = substr($requestObj->content, strpos($requestObj->content, ',') + 1);
         $image = new Image();
         $image->setContent($fileContent);
         $image->setName("Image");
         $entity->addImage($image);
         $em->persist($entity);
         $em->flush();
         return $this->JsonResponse($image);
     }
     return new Response('', 500);
 }
Exemplo n.º 3
0
 /**
  * Process club before form handleRequest
  * 
  * @param Club $club
  */
 private function processForm(Club $club)
 {
     if ($club->getSlug() == null) {
         $club->setSlug(\Oesteve\Bundle\GrupetaBundle\Utils\Slug::slugify($club->getName()));
     }
     if ($club->getLogoFile() != null) {
         $image = new Image();
         $image->setFile($club->getLogoFile());
         $image->setName($club->getLogoFile()->getClientOriginalName());
         $club->setLogo($image);
     }
     return $club;
 }
Exemplo n.º 4
0
 /**
  * 
  * Update method, only update the attributes:
  * 
  *  - Name
  *
  * @Route("/{id}/image/{image_id}", name="gallery_update_image")
  * @Method("PUT")
  * 
  * @ParamConverter("gallery", class="OesteveGrupetaBundle:Gallery", options={"mapping" ={"id" = "id"}})
  * @ParamConverter("image", class="OesteveGrupetaBundle:Image", options={"mapping" ={"image_id" = "id"}})
  * 
  */
 public function updateImageAction(Gallery $gallery, Image $image, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var SerializerBuilder The serialicer */
     $serializer = $this->get('jms_serializer');
     /** @var Image The updated image */
     $updatedImage = $serializer->deserialize($request->getContent(), 'Oesteve\\Bundle\\GrupetaBundle\\Entity\\Image', 'json');
     /**
      * Only update name
      */
     $image->setName($updatedImage->getName());
     $em->persist($image);
     $em->flush();
     return $this->getJsonResponse($image);
 }
Exemplo n.º 5
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;
 }