Esempio n. 1
0
 public function preUpload(PreUploadEvent $event)
 {
     //echo "preUpload";die();
     /*$response = $event->getResponse();
       $msg = "test";
       $response->setSuccess(false);
       $response->setError($msg);*/
     $galleryId = $event->getRequest()->get('galleryId');
     $file = $event->getFile();
     $media = new Media();
     //$media->setName($file->getBasename());
     $media->setName($file->getClientOriginalName());
     $media->setBinaryContent($file);
     $media->setEnabled(true);
     $media->setContext('default');
     $media->setProviderName('sonata.media.provider.image');
     $this->em = $this->doctrine[0]->getEntityManager();
     $gallery = $this->em->getRepository('ApplicationSonataMediaBundle:Gallery')->find($galleryId);
     $galleryHasMedia = new GalleryHasMedia();
     $galleryHasMedia->setMedia($media);
     $galleryHasMedia->setEnabled(true);
     $gallery->addGalleryHasMedias($galleryHasMedia);
     $this->em->persist($galleryHasMedia);
     $this->em->persist($media);
     $this->em->flush();
     die;
 }
Esempio n. 2
0
 /**
  * Creates a new Lots entity.
  *
  */
 public function createAction(Request $request)
 {
     $entity = new Lots();
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $user = $this->container->get('security.context')->getToken()->getUser();
         $entity->setUser($user);
         $uploadedFiles = $request->files->get('myfile');
         $numUploadedFiles = count($uploadedFiles);
         if ($numUploadedFiles > 0) {
             $tmp_gallery = new Gallery();
             $mediaManager = $this->container->get('sonata.media.manager.media');
             $uploadedFiles = $request->files->get('myfile');
             $tmp_gallery->setName($entity->getTitle());
             $tmp_gallery->setContext('default');
             $tmp_gallery->setDefaultFormat('default_small');
             $tmp_gallery->setEnabled(true);
             //            $em->persist($tmp_gallery);
             //            $em->refresh($tmp_gallery);
             for ($i = 0; $i < $numUploadedFiles; $i++) {
                 $tmp_media = new Media();
                 $tmp_galleryHasMedia = new GalleryHasMedia();
                 $tmp_media->setBinaryContent($uploadedFiles[$i]->getRealPath());
                 $tmp_media->setContext('default');
                 $tmp_media->setName($uploadedFiles[$i]->getClientOriginalName());
                 $mediaManager->save($tmp_media, 'default', 'sonata.media.provider.image');
                 $tmp_galleryHasMedia->setMedia($tmp_media);
                 $tmp_galleryHasMedia->setEnabled(true);
                 $tmp_galleryHasMedia->setGallery($tmp_gallery);
                 $em->persist($tmp_galleryHasMedia);
             }
             $em->persist($tmp_gallery);
             $em->flush();
             $em->refresh($tmp_gallery);
             $entity->setGallery($tmp_gallery);
         }
         $offer = new Offer();
         $em->persist($offer);
         $entity->setOffer($offer);
         $em->persist($entity);
         $em->flush();
         return $this->redirect($this->generateUrl('lots_show', array('id' => $entity->getId())));
     }
     return $this->render('AESlandsBundle:Lots:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }
Esempio n. 3
0
 public function mediaUploaded(MediaArrayEvent $event)
 {
     $em = $this->doctrine->getManager();
     $mediaArray = $event->getMedia();
     $gallery = $this->galleryManager->findOneBy(array("name" => "Media Library"));
     if (!$gallery) {
         $gallery = new Gallery();
         $gallery->setName("Media Library");
         $gallery->setContext('default');
         $gallery->setDefaultFormat('big');
         $gallery->setEnabled(true);
         $em->persist($gallery);
     }
     foreach ($mediaArray as $media) {
         $galleryHasMedia = new GalleryHasMedia();
         $galleryHasMedia->setMedia($media);
         $galleryHasMedia->setGallery($gallery);
         $galleryHasMedia->setEnabled(true);
         $em->persist($galleryHasMedia);
     }
     $em->flush();
 }
 /**
  * @param MediaInterface   $media
  * @param GalleryInterface $gallery
  */
 protected function addMediaToGallery(MediaInterface $media, GalleryInterface $gallery)
 {
     $galleryHasMedia = new GalleryHasMedia();
     $galleryHasMedia->setMedia($media);
     $galleryHasMedia->setPosition(count($gallery->getGalleryHasMedias()) + 1);
     $galleryHasMedia->setEnabled(true);
     $gallery->addGalleryHasMedias($galleryHasMedia);
 }