Change record type

@param  Request $request
@return Response
190753
public function changeType(Request $request)
    {
        $typeLst = $request->request->get('types', []);
        $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CANMODIFRECORD]);
        $mimeLst = $request->request->get('mimes', []);
        $forceType = $request->request->get('force_types', '');
        $updated = [];

        foreach ($records as $record) {
            try {
                $recordType = !empty($forceType) ? $forceType : (isset($typeLst[$record->getId()]) ? $typeLst[$record->getId()] : null);
                $mimeType = isset($mimeLst[$record->getId()]) ? $mimeLst[$record->getId()] : null;

                if ($recordType) {
                    $record->setType($recordType);
                    $updated[$record->getId()]['record_type'] = $recordType;
                }

                if ($mimeType) {
                    $record->setMimeType($mimeType);
                    $updated[$record->getId()]['mime_type'] = $mimeType;
                }
            } catch (\Exception $e) {

            }
        }

        return $this->app->json(['success' => true, 'updated' => $updated], 201);
    }
1000825
public function setAction(Request $request)
    {
        $ids = $request->get('ids');
        $ids = explode(',', $ids);

        $metaSetManager = $this->get('phlexible_meta_set.meta_set_manager');
        $metaSets = [];
        foreach ($ids as $id) {
            $metaSets[] = $metaSetManager->find($id);
        }

        $config = $this->createMetasetConfig($metaSets);

        return new JsonResponse($config);
    }
4055
public function processRequest(Request $request)
    {
        $contentType = $request->header('content-type') ?: '';

        if (mb_stripos($contentType, 'multipart/form-data') !== false) {
            $this->validateParsedBody($request);
            $request = $this->parseUploadedFiles($request);
        }

        return $request;
    }
252679
protected function repeaterHasSubTypes(Request $request)
    {
        if (!$resourceId = $this->getResourceId($request)) {
            return false;
        }

        if (!$model = $this->model()->whereId($resourceId)->first()) {
            return false;
        }

        return method_exists($model->type, 'types');
    }
857102
public function saveAction(Request $request)
    {
        $id = $request->get('id');
        $ids = $request->get('ids');

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

        $elementtypeService->updateViability($elementtype, $ids);

        return new ResultResponse(true);
    }
901862
public function store(Request $request)
    {
        try {
            $blockType = $this->blockTypes->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => trans('soda::terminology.block_type')]));
        }

        return redirect()->route('soda.block-types.edit', $blockType->getKey())->with('success', trans('soda::messages.created', ['object' => trans('soda::terminology.block_type')]));
    }
952498
public function updateImage(Request $request)
    {
        $fileName = $request->query->get('file');
        $type = $request->query->get('type');
        $value = $request->query->get('value');
      
        /** @var Image $entity */
        $qb = $this->getDoctrine()->getManager()->getRepository('CoreBundle:Image')
                ->createQueryBuilder('i');
        $image = $qb->where($qb->expr()->like('i.path', ':path'))
            ->setParameter('path','%'.$fileName.'%')
            ->getQuery()
            ->getOneOrNullResult();

//        $image = $this->getDoctrine()->getManager()->getRepository('CoreBundle:Image')->findOneBy(array('path' => $fileName));
       
        if (!$image) {
            throw new NotFoundHttpException('Unable to find Image entity.');
        }
        

        if($type == 'title') $image->setTitle($value);
        if($type == 'alt') $image->setAlt($value);
        
        $this->getDoctrine()->getManager()->flush();
            

        return new JsonResponse(array('success' => true));
    }
475264
public function changeConfirmedAction(Request $request)
    {
        $this->getContainer()->get('compo_region.manager.region')->setConfirmed(true);

        return new JsonResponse([
            'is_confirmed' => true,
        ]);
    }
447962
public function changeAction(Request $request, $locale)
    {
        if (($token = $this->tokenStorage->getToken()) && 'anon.' !== $token->getUser()) {
            $this->localeManager->setUserLocale($locale);
        }

        $request->setLocale($locale);
        $request->getSession()->set('_locale', $locale);

        return new RedirectResponse(
            $request->headers->get('referer')
        );
    }
1241512
public function typesAction(Request $request)
    {
        $component = $request->request->get('component');

        $taskTypes = $this->get('phlexible_task.types');

        $types = [];
        foreach ($taskTypes->all() as $type) {
            /* @var $type TypeInterface */
            if ($component && $type->getComponent() !== $component) {
                continue;
            }

            $types[] = [
                'id' => $type->getName(),
                'name' => $type->getName(),
            ];
        }

        return new JsonResponse(['types' => $types]);
    }
65931
public function deleteAction(Request $request)
    {
        $id = $request->get('id');

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

        $elementtypeService->deleteElementtype($elementtype);

        return new ResultResponse(true, "Element type $id soft deleted.");
    }
1350313
public function update(Request $request)
    {
        // Carregar ID
        $id = $this->getId($request);

        // Carregar objeto JSON
        $obj = $this->getJsonContent($request);
        if (is_null($obj)) {
            $this->error('JSON invalid', 500);
        }

        // Salvar
        $this->setValues($obj, $id);

        return response()->json((object)['success' => true]);
    }
816826
public function createAction(Request $request)
    {
        $templateRepository = $this->get('phlexible_media_template.template_manager');

        $type = $request->get('type');
        $key = $request->get('key');

        switch ($type) {
            case 'image':
                $template = new ImageTemplate();
                $template->setCache(false);
                break;
            case 'video':
                $template = new VideoTemplate();
                $template->setCache(true);
                break;
            case 'audio':
                $template = new AudioTemplate();
                $template->setCache(true);
                break;
            default:
                throw new InvalidArgumentException("Unknown template type $type");
        }

        $template->setKey($key);

        $templateRepository->updateTemplate($template);

        return new ResultResponse(true, 'New "'.$type.'" template "'.$key.'" created.');
    }
212230
public function switchAction(Request $request)
    {
        $domainConfiguration = $this->get('kunstmaan_admin.domain_configuration');
        $host = $request->query->get('host');
        $hosts = $domainConfiguration->getFullHostConfig();
        if (!array_key_exists($host, $hosts)) {
            throw $this->createNotFoundException('Invalid host specified');
        }

        $currentHost = $domainConfiguration->getHost();

        $session = $request->getSession();
        if ($request->get('from_url_chooser')) {
            $session->set(DomainConfiguration::SWITCH_HOST, $host);
        } else {
            $session->set(DomainConfiguration::OVERRIDE_HOST, $host);
        }

        /*
         * If current host type is different then the host going to, redirect to it's homepage.
         * If coming from url chooser, don't redirect to homepage if other host.
         */
        if ((($hosts[$host]['type'] !== $hosts[$currentHost]['type']) || (!$request->query->has('route'))) && (!$request->get('from_url_chooser'))) {
            $route = 'KunstmaanAdminBundle_homepage';
            $defaultLocale = $this->get('kunstmaan_admin.domain_configuration')->getDefaultLocale();
        } else {
            $route = $request->query->get('route');
            $routeParams = $request->query->get('route_params');
            $defaultLocale = $hosts[$host]['default_locale'];
        }

        $routeParams['_locale'] = $defaultLocale;

        $response = new RedirectResponse(
            $this->get('router')->generate($route, $routeParams)
        );

        return $response;
    }
35890
public function switchAction(Request $request)
    {
        $theme = $request->get('theme');

        if (!in_array($theme, $this->themes)) {
            throw new NotFoundHttpException(sprintf('The theme "%s" does not exist', $theme));
        }

        $this->activeTheme->setName($theme);

        $url = $request->headers->get('Referer', '/');
        $response = new RedirectResponse($url);

        if (!empty($this->cookieOptions)) {
            $cookie = new Cookie(
                $this->cookieOptions['name'],
                $theme,
                time() + $this->cookieOptions['lifetime'],
                $this->cookieOptions['path'],
                $this->cookieOptions['domain'],
                (bool) $this->cookieOptions['secure'],
                (bool) $this->cookieOptions['http_only']
            );

            $response->headers->setCookie($cookie);
        }

        return $response;
    }
20960
public function store(Request $request)
    {
        // insert key and value in settings table
        $settings = Settings::all()->keyBy('settingsKey')->toArray();

        foreach ($request->form as $key => $value){
            if(!isset($settings[$key])) {
                $settings[$key] = ["settingsKey" => $key, "value" => $value];
            }
            $settings[$key]['value'] = ($value ? $value : null);
        }

        if(Settings::truncate()) {
            Settings::insert($settings);
        }

        // if request is being made from general settings
        if($request->settingsType == 'general') {
            if(isset($settings['defaultLanguage']) 
                && ((int) $settings['defaultLanguage']['value'] !== Language::getDefault()->languageID)
            ) {
                    // remove the current default language ( set it to non-default ) if this new one is the default
                    Language::where('isDefault', 1)->update(['isDefault' => 0]);
                    // set the new default language
                    $defaultLanguage = $request->form['defaultLanguage'];
                    Language::find($defaultLanguage)->update(['isDefault' => 1]);
            }

        }

        return $this->response('Settings are saved', 200);
    }
935235
public function editAction(Request $request): Response
    {
        /* @todo it shouldn't rely on keys from request */
        $requestKeys = $request->request->keys();
        $formName = reset($requestKeys) ?: null;

        $form = $this->formFactory->contentEdit(null, $formName);
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentEditData $data) {
                $contentInfo = $data->getContentInfo();
                $versionInfo = $data->getVersionInfo();
                $language = $data->getLanguage();
                $versionNo = $versionInfo->versionNo;
                $location = $data->getLocation();

                $content = $this->contentService->loadContent($contentInfo->id);
                if ((new ContentIsUser($this->userService))->isSatisfiedBy($content)) {
                    return $this->redirectToRoute('ez_user_update', [
                        'contentId' => $contentInfo->id,
                        'versionNo' => $versionNo,
                        'language' => $language->languageCode,
                    ]);
                }

                if (!$versionInfo->isDraft()) {
                    $contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
                    $this->updateDraftInitialLanguage($contentDraft, $language);
                    $versionNo = $contentDraft->getVersionInfo()->versionNo;

                    $this->notificationHandler->success(
                        $this->translator->trans(
                            /** @Desc("New Version Draft for '%name%' created.") */
                            'content.create_draft.success',
                            ['%name%' => $contentInfo->name],
                            'content'
                        )
                    );
                }

                return $this->redirectToRoute('ez_content_draft_edit', [
                    'contentId' => $contentInfo->id,
                    'versionNo' => $versionNo,
                    'language' => $language->languageCode,
                    'locationId' => null !== $location
                        ? $location->id
                        : $contentInfo->mainLocationId,
                ]);
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        /** @var ContentEditData $data */
        $data = $form->getData();
        $contentInfo = $data->getContentInfo();

        if (null !== $contentInfo) {
            return $this->redirectToRoute('_ezpublishLocation', [
                'locationId' => $contentInfo->mainLocationId,
            ]);
        }

        return $this->redirectToRoute('ezplatform.dashboard');
    }