Move folder.

@param Request $request

@return ResultResponse
@Route("/move", name="mediamanager_folder_move")
342976
public function moveAction(Request $request)
    {
        $volumeId = $request->get('site_id');
        $targetId = $request->get('target_id');
        $sourceId = $request->get('source_id');

        $volume = $this->getVolume($volumeId);
        $folder = $volume->findFolder($sourceId);
        $targetFolder = $volume->findFolder($targetId);

        $volume->moveFolder($folder, $targetFolder, $this->getUser()->getId());

        return new ResultResponse(true);
    }
576904
public function addFolder(Request $request)
    {
        // check if alphanumeric and no space
        if (! ctype_alnum($request->input('new_directory'))) {
            flash()->error('Invalid folder name! Folder name must be alphanumeric only and no space');

            return redirect()->back();
        }

        $folder = $request->input('current_directory') . '/' . $request->input('new_directory');
        Storage::makeDirectory($folder);

        flash()->success('New Folder added successfully!');

        return redirect()->back()->with('folder', $folder);
    }
155948
public function bulkMoveAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $mediaRepo = $em->getRepository('KunstmaanMediaBundle:Media');
        $form = $this->createForm(BulkMoveMediaType::class);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            /** @var Folder $folder */
            $folder = $form->getData()['folder'];
            $mediaIds = explode(',', $form->getData()['media']);

            $mediaRepo->createQueryBuilder('m')
                ->update()
                ->set('m.folder', $folder->getId())
                ->where('m.id in (:mediaIds)')
                ->setParameter('mediaIds', $mediaIds)
                ->getQuery()
                ->execute();

            $this->addFlash(FlashTypes::SUCCESS, $this->get('translator')->trans('media.folder.bulk_move.success.text'));

            return new JsonResponse(
                [
                    'Success' => 'The media is moved',
                ]
            );
        }

        return $this->render(
            '@KunstmaanMedia/Folder/bulk-move-modal_form.html.twig',
            [
                'form' => $form->createView(),
            ]
        );
    }
204859
public function copyAction(Request $request)
    {
        $folderId = $request->get('folderID');
        $fileIDs = json_decode($request->get('fileIDs'));

        $volume = $this->getVolumeByFolderId($folderId);
        $folder = $volume->findFolder($folderId);

        foreach ($fileIDs as $fileID) {
            $file = $volume->findFile($fileID);
            $volume->copyFile($file, $folder, $this->getUser()->getId());
        }

        return new ResultResponse(true, 'File(s) copied.');
    }
1058293
public function uploadAction(Request $request)
    {
        $media = $this->get('opifer.media.media_manager')->createMedia();
        $em = $this->getDoctrine()->getManager();

        foreach ($request->files->all() as $files) {
            if ((!is_array($files)) && (!$files instanceof \Traversable)) {
                $files = [$files];
            }

            foreach ($files as $file) {
                $media = clone $media;
                $media->setFile($file);

                if (strpos($file->getClientMimeType(), 'image') !== false) {
                    $media->setProvider('image');
                } else {
                    $media->setProvider('file');
                }

                $em->persist($media);
            }
        }
        $em->flush();

        $media = $this->get('jms_serializer')->serialize($media, 'json');

        return new Response($media, 200, ['Content-Type' => 'application/json']);
    }
594555
public function renameAction(Request $request)
    {
        $fileId = $request->get('file_id');
        $name = $request->get('file_name');

        $volume = $this->get('phlexible_media_manager.volume_manager')->getByFileId($fileId);

        $file = $volume->findFile($fileId);
        $volume->renameFile($file, $name, $this->getUser()->getId());

        return new ResultResponse(true, 'File(s) renamed.');
    }
632456
public function loadAction(Request $request)
    {
        $repository = $this->get('phlexible_media_template.template_manager');

        $templateKey = $request->get('template_key');

        $template = $repository->find($templateKey);
        $parameters = $template->getParameters();

        if (isset($parameters['method'])) {
            $parameters['xmethod'] = $parameters['method'];
            unset($parameters['method']);
        }

        return new JsonResponse(['success' => true, 'data' => $parameters]);
    }
741350
public function index(Request $request)
    {
        $storage_root     = $this->getRootDir();
        $accepted_files   = $this->config->get('media.accepted_files');
        $max_file_size    = $this->config->get('media.max_file_size', 3);
        $this->currentDir = $request->get('folder', $storage_root);

        if ($this->folderIsNotAccessible($request)) {
            return redirect()->route('administrator.media.index');
        }

        $items = $this->buildFileAndDirectoryListing();

        $directories = $this->buildDirectory(
            $this->scanDirectory($storage_root),
            $storage_root
        );

        return view('administrator.media.index')
            ->with('template', $this->template)
            ->with('items', $items)
            ->with('current_directory', $this->currentDir)
            ->with('directories', $directories)
            ->with('accepted_files', $accepted_files)
            ->with('storage_root', $storage_root)
            ->with('max_file_size', $max_file_size);
    }
836068
public function moveUpAction(Request $request)
    {
        $context = $this->loadContext($request);

        $resource = $context->getResource();

        $this->isGranted('EDIT', $resource);

        $repo = $this->getRepository();
        $repo->moveUp($resource, 1);

        return $this->redirectToReferer($this->generateUrl(
            $this->config->getRoute('list'),
            $context->getIdentifiers()
        ));
    }
1066079
public function deleteAction(Request $request, Media $media)
    {
        $user = $this->getBlogUser();
        $mediaLibrary = $this->container->get('sonata.media.manager.gallery')->findOneBy(array('name' => 'Media Library'));
        $em = $this->getDoctrine()->getManager();

        foreach($media->getGalleryHasMedias() as $hasMedia)
        {
            if($hasMedia->getGallery() == $mediaLibrary)
            {
                $em->remove($hasMedia);
            }
        }

        $em->flush();

        if($request->isXmlHttpRequest())
        {
            return new JsonResponse(array('success' => 'true'));
        }

        $this->get('session')->getFlashBag()->add('success', 'Photo removed successfully.');
        return $this->redirectToRoute('ed_blog_admin_media_list');
    }
307657
protected function deleteFile(Request $request)
    {
        try {
            $file = $request->input('s');
            Storage::delete($file);

            return $this->notifySuccess($file . ' successfully deleted!');
        } catch (\ErrorException $e) {
            return $this->notifyError($e->getMessage());
        }
    }
276609
public function moveDownAction(Request $request)
    {
        $container = $this->findContainerByRequest($request);

        try {
            $sibling = $this->getEditor()->getContainerManager()->moveDown($container);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $content = $container->getContent();

        $this->validate($content);
        $this->persist($content);

        $data = [
            'containers' => [
                $this->getViewBuilder()->buildContainer($container),
                $this->getViewBuilder()->buildContainer($sibling),
            ],
        ];

        return $this->buildResponse($data, self::SERIALIZE_LAYOUT);
    }
112433
public function moveUpAction(Request $request)
    {
        $context = $this->loadContext($request);

        $resource = $context->getResource();

        $this->isGranted('EDIT', $resource);

        $this->move($resource, -1);

        return $this->redirectToReferer($this->generateUrl(
            $this->config->getRoute('list'),
            $context->getIdentifiers()
        ));
    }
799998
public function moveDownAction(Request $request)
    {
        $row = $this->findRowByRequest($request);

        try {
            $sibling = $this->getEditor()->getRowManager()->moveDown($row);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $container = $row->getContainer();

        $this->validate($container);
        $this->persist($container);

        $data = [
            'rows' => [
                $this->getViewBuilder()->buildRow($row),
                $this->getViewBuilder()->buildRow($sibling),
            ],
        ];

        return $this->buildResponse($data, self::SERIALIZE_LAYOUT);
    }
845349
public function folderZipAction(Request $request)
    {
        $folderId = $request->get('folder_id');

        $volumeManager = $this->get('phlexible_media_manager.volume_manager');
        $path = $this->container->getParameter('phlexible_media_manager.temp_dir');

        $filesystem = new Filesystem();
        $filesystem->mkdir($path);

        $volume = $volumeManager->getByFolderId($folderId);
        $folder = $volume->findFolder($folderId);

        $prefix = $folder->getPath();
        $prefixLength = 0;
        if ($prefix && mb_strpos($prefix, '/') !== false) {
            $prefix = mb_substr($prefix, 0, -mb_strlen('/'.$folder->getName()));
            $prefixLength = mb_strlen($prefix) + 1;
            $prefix = '';
        } elseif ($folder->isRoot()) {
            $prefix = $folder->getName().'/';
        } else {
            $prefix = '';
        }

        $filename = 'folder_'.$folder->getName().'_'.date('YmdHis');
        $filename = preg_replace('/[^a-zA-Z0-9-_]/', '_', $filename);
        $filename = $path.$filename.'.zip';

        $rii = new \RecursiveIteratorIterator(new FolderIterator($folder), \RecursiveIteratorIterator::SELF_FIRST);

        $files = [];
        foreach ($rii as $folder) {
            $folderPath = $folder->getPath().'/';
            foreach ($volume->findFilesByFolder($folder) as $file) {
                $displayName = $prefix.$folderPath.$file->getName();
                $displayName = mb_substr($displayName, $prefixLength, null, 'UTF-8');
                $files[$displayName] = $file->getPhysicalPath();
            }
        }

        $zippy = Zippy::load();
        $zippy->create($filename, $files);

        return new ResultResponse(true, 'Zip finished', ['filename' => basename($filename)]);
    }
581245
public function createDirectory(Request $request)
    {
        $this->authorize(MediasPolicy::PERMISSION_CREATE);

        // TODO: Refactor this with the Laravel 5.5 new Exception Handler & Form Request
        $validator = validator($data = $request->all(), [
            'name'     => ['required', 'string'], // TODO: check if the folder does not exists
            'location' => ['required', 'string'],
        ]);

        if ($validator->fails()) {
            return $this->jsonResponseError([
                'messages' => $validator->messages(),
            ], 422);
        }

        $this->media->makeDirectory(
            $path = trim($data['location'], '/').'/'.Str::slug($data['name'])
        );

        return $this->jsonResponseSuccess(['data' => compact('path')]);
    }
1215980
public function store(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'create')) {
            return $this->noPermission();
        }
        return (new Media())->upload($request);
    }