Substitute a record element by a lazaret element

@param Request     $request The current request
@param int         $file_id A lazaret element id

@return Response
484930
public function acceptElement(Request $request, $file_id)
    {
        $ret = ['success' => false, 'message' => '', 'result'  => []];

        //Mandatory parameter
        if (null === $recordId = $request->request->get('record_id')) {
            $ret['message'] = $this->app->trans('You must give a destination record');

            return $this->app->json($ret);
        }

        /** @var LazaretFile $lazaretFile */
        $lazaretFile = $this->getLazaretFileRepository()->find($file_id);

        if (null === $lazaretFile) {
            $ret['message'] = $this->app->trans('File is not present in quarantine anymore, please refresh');

            return $this->app->json($ret);
        }

        $found = false;

        //Check if the chosen record is eligible to the substitution
        foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) {
            if ($record->getRecordId() !== (int) $recordId) {
                continue;
            }

            $found = true;
            break;
        }

        if (!$found) {
            $ret['message'] = $this->app->trans('The destination record provided is not allowed');

            return $this->app->json($ret);
        }

        $path = $this->app['tmp.lazaret.path'] . '/';
        $lazaretFileName = $path .$lazaretFile->getFilename();
        $lazaretThumbFileName = $path .$lazaretFile->getThumbFilename();

        try {
            $media = $this->app->getMediaFromUri($lazaretFileName);

            $record = $lazaretFile->getCollection($this->app)->get_databox()->get_record($recordId);
            $this->getSubDefinitionSubstituer()->substituteDocument($record, $media);
            $this->getDataboxLogger($record->getDatabox())->log(
                $record,
                \Session_Logger::EVENT_SUBSTITUTE,
                'HD',
                ''
            );

            //Delete lazaret file
            $manager = $this->getEntityManager();
            $manager->remove($lazaretFile);
            $manager->flush();

            $ret['success'] = true;
        } catch (\Exception $e) {
            $ret['message'] = $this->app->trans('An error occured');
        }

        try {
            $this->getFilesystem()->remove([$lazaretFileName, $lazaretThumbFileName]);
        } catch (IOException $e) {

        }

        return $this->app->json($ret);
    }
891633
public function get_file(Request $request)
    {
        $filepath = $request->input('filepath');
        $data = file_get_contents(base_path($filepath));
        echo $data;
    }
809992
public function getAction(Request $request, $id)
    {
        $document = $this->getModel()->getSerialised($id, $request);

        $response = $this->getResponse()
            ->setStatusCode(Response::HTTP_OK)
            ->setContent($document);

        return $response;
    }
74350
public function update(Request $request, $id)
    {
        $fb = Flipbook::find($id);
        $input = $request->all();
        //  return dd($input);

        $fb->content .= ",";
        $i = 1;
        foreach($request->files as $uploadedFile )
            //if($request->hasFile('flip_img'))
        {
            // echo "hi";
            // $request->file()
            // $name = $uploadedFile->getClientOriginalName();

            //$image =  $request->file('flip_img');
            $filename  = time().'_'. $i . '.' . $uploadedFile->getClientOriginalExtension();
            $i++;
            $file = $uploadedFile->move(public_path('rudra/fbook/pics/'), $filename);
            //$path = public_path('rudra/flipbook/pics/' . $filename);
            $path = 'rudra/fbook/pics/' . $filename;

            // Image::make($image->getRealPath())->resize(200, 200)->save($path);
            $fb->content .= $path .",";

        }

        $fb->content = rtrim($fb->content,",");

        $fb->name = $input['book_name'];
        $fb->desc = $input['desc'];
        // $input['urlname'] = strtolower(preg_replace('/[ ,]+/', '-', trim($input['name'])));
        $fb->save();
        //dd($input);
        //exit;
        // Subcategory::create($input);
        return Redirect::route('flipbook.index');
    }
342422
public function cdeleteAction(Request $request)
    {
        $ids = array_filter(explode(',', $request->get('ids', '')));

        $documentManager = $this->getDocumentManager();
        foreach ($ids as $id) {
            $document = $documentManager->find($id);
            $documentManager->remove($document);
            $documentManager->flush();
        }

        return $this->handleView($this->view(null));
    }
715097
public function putAction($id, Request $request)
    {
        $request = $this->requestManager->updateFileRequest($request);
        /** @var FileModel $model */
        $model = $this->getModel();

        $file = new File();
        if ($metadata = $request->get('metadata', false)) {
            $file = $this->restUtils->validateRequest($metadata, $model);
        }

        $file = $this->fileManager->handleSaveRequest($file, $request, $model);

        // Set status code and content
        $response = $this->getResponse();
        $response->setStatusCode(Response::HTTP_NO_CONTENT);
        $response->headers->set(
            'Location',
            $this->getRouter()->generate('gravitondyn.file.rest.file.get', array('id' => $file->getId()))
        );

        return $response;
    }
538253
public function index(Request $request, $file)
	{
		$options = $request->all();

		return Render::image($file, $options)->cast();
	}
1364632
public function fileInsertForm($request = null)
    {
        // Get ID either from posted back value, or url parameter
        if (!$request) {
            $this->jsonError(400);
            return null;
        }
        $id = $request->param('ID');
        if (!$id) {
            $this->jsonError(400);
            return null;
        }
        return $this->getFileInsertForm($id);
    }
693501
public function subCreateAction(Request $request, $folderId)
    {
        $em = $this->getDoctrine()->getManager();

        /* @var Folder $parent */
        $parent = $em->getRepository('VictoireMediaBundle:Folder')->getFolder($folderId);
        $folder = new Folder();
        $folder->setParent($parent);
        $form = $this->createForm(FolderType::class, $folder, ['folder' => $folder]);
        if ('POST' == $request->getMethod()) {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $em->getRepository('VictoireMediaBundle:Folder')->save($folder);

                $this->congrat('Folder \''.$folder->getName().'\' has been created!');

                return new Response('<script>window.location="'.$this->generateUrl('VictoireMediaBundle_folder_show', ['folderId' => $folder->getId()]).'"</script>');
            }
        }

        $galleries = $em->getRepository('VictoireMediaBundle:Folder')->getAllFolders();

        return $this->render('VictoireMediaBundle:Folder:addsub-modal.html.twig', [
            'subform'   => $form->createView(),
            'galleries' => $galleries,
            'folder'    => $folder,
            'parent'    => $parent,
        ]);
    }
102402
public function editStorageAction(Request $request, $id)
    {
        $em = $this->get('doctrine.orm.entity_manager');
        $storage = $em->find(Storage::class, $id);

        if (empty($storage)) {
            return $this->redirectToRoute('cms_admin_config_media');
        }

        $form = $this->createForm(StorageFormType::class, $storage);
        $form->add('update', SubmitType::class, ['attr' => ['class' => 'btn btn-success']]);
        $form->add('cancel', SubmitType::class, ['attr' => ['class' => 'btn-default', 'formnovalidate' => 'formnovalidate']]);

        if ($request->isMethod('POST')) {
            $form->handleRequest($request);

            if ($form->get('cancel')->isClicked()) {
                return $this->redirectToRoute('cms_admin_config_media');
            }

            if ($form->isValid()) {
                $this->persist($form->getData(), true);
                $this->addFlash('success', 'Хранилище обновлено');

                return $this->redirectToRoute('cms_admin_config_media');
            }
        }

        return $this->render('@CMS/AdminMediaLibrary/edit_storage.html.twig', [
            'form'   => $form->createView(),
        ]);
    }
382783
public function elementsAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $language = $request->get('language');
        $query = $request->get('query');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $iconResolver = $this->get('phlexible_element.icon_resolver');
        $conn = $this->get('database_connection');

        $tree = $treeManager->getBySiteRootId($siterootId);

        $qb = $conn->createQueryBuilder();
        $qb
            ->select('t.id AS tid', 'e.latest_version AS version', 'evmf.backend AS title')
            ->from('tree', 't')
            ->join('t', 'element', 'e', 't.type_id = e.eid')
            ->join('e', 'element_version', 'ev', 'ev.eid = e.eid AND ev.version = e.latest_version')
            ->join('ev', 'element_version_mapped_field', 'evmf', 'evmf.element_version_id = ev.id')
            ->where($qb->expr()->eq('evmf.language', $qb->expr()->literal($language)))
            ->andWhere($qb->expr()->eq('t.siteroot_id', $qb->expr()->literal($siterootId)))
            ->andWhere($qb->expr()->like('evmf.backend', $qb->expr()->literal("%$query%")));

        $result = $conn->fetchAll($qb->getSQL());

        foreach ($result as $key => $row) {
            $treeNode = $tree->get($row['tid']);
            $result[$key]['icon'] = $iconResolver->resolveTreeNode($treeNode, $language);
        }

        return new JsonResponse(['results' => $result]);
    }
485487
public function duplicateAction(Request $request)
    {
        $id = $request->get('id');

        $elementtypeService = $this->get('phlexible_elementtype.elementtype_service');
        $sourceElementtype = $elementtypeService->findElementtype($id);

        $elementtype = $elementtypeService->duplicateElementtype($sourceElementtype, $this->getUser()->getUsername());

        return new ResultResponse(true, 'Element type duplicated.');
    }
736886
protected function setFile($file_id)
    {
        $this->data_file = array();

        if (is_numeric($file_id)) {

            $conditions = array(
                'language' => 'und',
                'file_id' => $file_id
            );

            $this->data_file = $this->file->get($conditions);

            if (empty($this->data_file)) {
                $this->outputHttpStatus(404);
            }

            $this->prepareFile($this->data_file);
        }
    }
420406
public function getAction(Request $request, $id = null)
    {
        $locale = $this->getLocale($request);

        $snippet = $this->findDocument($id, $locale);
        $view = View::create($snippet);

        return $this->viewHandler->handle($view);
    }
466579
public function getAction(Request $request, $id)
    {
        if (null !== $request->get('fields')) {
            return $this->getContent($request, $id);
        }

        return $this->getSingleNode($request, $id);
    }
738224
public function editBlockAction(Request $request, $id)
    {
        /** @var BlockManager $manager */
        $manager = $this->get('opifer.content.block_manager');
        $block = $manager->find($id, true);

        /** @var AbstractBlockService $service */
        $service = $manager->getService($block);
        $updatePreview = false; // signals parent window preview from iframe to update preview

        $service->preFormSubmit($block);

        $form = $this->createForm(BlockAdapterFormType::class, $block, [
            'block_service' => $service,
        ]);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $service->postFormSubmit($form, $block);

            $manager->save($block, true);
            $updatePreview = true;
        }

        $viewResponse = $this->render($service->getEditView(), [
            'block_service' => $service,
            'block' => $block,
            'form' => $form->createView(),
            'update_preview' => $updatePreview
        ]);

        return new JsonResponse([
            'title' => $service->getName($block),
            'view' => $viewResponse->getContent(),
            'updatePreview' => $updatePreview
        ]);
    }
1089263
public function listAction(Request $request): Response
    {
        $page = $request->query->get('page', 1);

        $pagerfanta = new Pagerfanta(
            new BookmarkAdapter($this->bookmarkService, $this->datasetFactory)
        );

        $pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
        $pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));

        $editForm = $this->formFactory->contentEdit(
            new ContentEditData()
        );

        $removeBookmarkForm = $this->formFactory->removeBookmark(
            new BookmarkRemoveData($this->getChoices($pagerfanta->getCurrentPageResults()))
        );

        return $this->render(
            '@ezdesign/admin/bookmark/list.html.twig',
            $viewParameters = [
                'pager' => $pagerfanta,
                'form_edit' => $editForm->createView(),
                'form_remove' => $removeBookmarkForm->createView(),
            ]
        );
    }