コード例 #1
0
ファイル: UploaderListener.php プロジェクト: Kilo3/easyprod
 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;
 }
コード例 #2
0
ファイル: LotsController.php プロジェクト: madspy0/lands
 /**
  * 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()));
 }
コード例 #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();
 }
コード例 #4
0
 /**
  * Test that Id is null at the beginning.
  */
 public function testGetId()
 {
     $this->assertNull($this->galleryHasMedia->getId());
 }
コード例 #5
0
 public function addAlbumPhotoAction(Request $request)
 {
     $userId = $this->getUser()->getId();
     $albumId = $request->get('albumId');
     $userHasAlbum = $this->getDoctrine()->getRepository('NetworkStoreBundle:UserGallery')->findAlbumForUser($userId, $albumId);
     if (empty($userHasAlbum)) {
         return $this->render('NetworkWebBundle:User:msg.html.twig', ['msg' => 'msg.add_photo_to_inaccessible_album']);
     }
     $album = $userHasAlbum->getGallery();
     if (empty($album)) {
         return $this->render('NetworkWebBundle:User:msg.html.twig', ['msg' => 'msg.add_photo_to_nonexistent_album']);
     }
     $form = $this->createForm(new PhotoType());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $data['media']->setDescription($data['description']);
         $em = $this->getDoctrine()->getManager();
         $em->persist($data['media']);
         $ghm = new GalleryHasMedia();
         $ghm->setGallery($album)->setMedia($data['media']);
         $em->persist($ghm);
         $em->flush();
         $album->addGalleryHasMedia($ghm);
         $url = $this->generateUrl('user_show_album', ['id' => $userId, 'albumId' => $albumId]);
         $response = new RedirectResponse($url);
         return $response;
     }
     return $this->render('NetworkUserBundle:Albums:add_album_photo.html.twig', ['form' => $form->createView(), 'album_id' => $albumId]);
 }
コード例 #6
0
ファイル: History.php プロジェクト: 0TshELn1ck/CheTheatre
 /**
  * Remove galleryHasMedia
  *
  * @param \Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia
  */
 public function removeGalleryHasMedia(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia)
 {
     $this->galleryHasMedia->removeElement($galleryHasMedia);
 }
コード例 #7
0
 /**
  * @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);
 }