public function createMediaAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $folderId = $request->attributes->get('id');
        $folder = $this->findFolderById($folderId);

        $upload = new MediaUpload();

        $form = $this->createForm('ekyna_media_upload', $upload, array(
            'action' => $this->generateUrl(
                'ekyna_media_browser_admin_create_media',
                array('id' => $folderId)
            ),
            'method' => 'POST',
            'attr'   => array(
                'class' => 'form-horizontal form-with-tabs',
            ),
            'folder' => $folder,
        ));

        $modal = $this->createModal();
        $modal->setTitle('ekyna_media.upload.title');
        $modal->setVars(array(
            'form_template' => 'EkynaMediaBundle:Manager:upload.html.twig',
        ));

        $success = false;
        $form->handleRequest($request);
        if ($form->isValid()) {
            $success = true;
            // TODO use ResourceManager
            foreach ($upload->getMedias() as $media) {
                $event = $this->get('ekyna_media.media.operator')->create($media);
                if ($event->hasErrors()) {
                    $success = false;
                    break;
                }
            }
        }
        if ($success) {
            $modal->setContent(array('success' => true));
        } else {
            $modal->setContent($form->createView());
        }

        return $this->get('ekyna_core.modal')->render($modal);
    }
public function createMediaAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $folderId = $request->attributes->get('id');
        $folder = $this->findFolderById($folderId);

        $upload = new MediaUpload();

        $form = $this->createForm('ekyna_media_upload', $upload, array(
            'action' => $this->generateUrl(
                'ekyna_media_browser_admin_create_media',
                array('id' => $folderId)
            ),
            'method' => 'POST',
            'attr'   => array(
                'class' => 'form-horizontal form-with-tabs',
            ),
            'folder' => $folder,
        ));

        $modal = $this->createModal();
        $modal->setTitle('ekyna_media.upload.title');
        $modal->setVars(array(
            'form_template' => 'EkynaMediaBundle:Manager:upload.html.twig',
        ));

        $success = false;
        $form->handleRequest($request);
        if ($form->isValid()) {
            $success = true;
            // TODO use ResourceManager
            foreach ($upload->getMedias() as $media) {
                $event = $this->get('ekyna_media.media.operator')->create($media);
                if ($event->hasErrors()) {
                    $success = false;
                    break;
                }
            }
        }
        if ($success) {
            $modal->setContent(array('success' => true));
        } else {
            $modal->setContent($form->createView());
        }

        return $this->get('ekyna_core.modal')->render($modal);
    }
public function createMediaAction ( Request $ request ) { if ( ! $ request -> isXmlHttpRequest ( ) ) { throw new NotFoundHttpException ( ) ; } $ folderId = $ request -> attributes -> get ( 'id' ) ; $ folder = $ this -> findFolderById ( $ folderId ) ; $ upload = new MediaUpload ( ) ; $ form = $ this -> createForm ( 'ekyna_media_upload' , $ upload , array ( 'action' => $ this -> generateUrl ( 'ekyna_media_browser_admin_create_media' , array ( 'id' => $ folderId ) ) , 'method' => 'POST' , 'attr' => array ( 'class' => 'form-horizontal form-with-tabs' , ) , 'folder' => $ folder , ) ) ; $ modal = $ this -> createModal ( ) ; $ modal -> setTitle ( 'ekyna_media.upload.title' ) ; $ modal -> setVars ( array ( 'form_template' => 'EkynaMediaBundle:Manager:upload.html.twig' , ) ) ; $ success = false ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ success = true ; // TODO use ResourceManager foreach ( $ upload -> getMedias ( ) as $ media ) { $ event = $ this -> get ( 'ekyna_media.media.operator' ) -> create ( $ media ) ; if ( $ event -> hasErrors ( ) ) { $ success = false ; break ; } } } if ( $ success ) { $ modal -> setContent ( array ( 'success' => true ) ) ; } else { $ modal -> setContent ( $ form -> createView ( ) ) ; } return $ this -> get ( 'ekyna_core.modal' ) -> render ( $ modal ) ; }
Creates the media into the folder.

@param Request $request

@return Response
Creates the media into the folder .