Create a new Builder instance.

@param \Illuminate\Http\Request  $request
@param \Illuminate\Translation\Translator  $translator
@param \Illuminate\Contracts\View\Factory  $view
@param \Orchestra\Contracts\Html\Grid  $grid
544934
abstract public function __construct(Request $request, Translator $translator, View $view, GridContract $grid);

    /**
     * Extend decoration.
     *
     * @param  callable  $callback
     *
     * @return $this
     */
    public function extend(callable $callback = null)
    {
        // Run the table designer.
        if (! \is_null($callback)) {
            \call_user_func($callback, $this->grid, $this->request, $this->translator);
        }

        return $this;
    }
1129107
public function editAction(Request $request, $key, $domain)
    {
        $translation = $this->get('asm_translation_loader.translation_manager')
            ->findTranslationBy(
                array(
                    'transKey' => $key,
                    'transLocale' => $request->getLocale(),
                    'messageDomain' => $domain,
                )
            );
                
        $entity = new Translation();
        $entity->setKey($translation->getTransKey());
        $entity->setDomain($domain);
        foreach ($this->getParameter('a2lix_translation_form.locales') as $k => $loc) {
            
            $translation = $this->get('asm_translation_loader.translation_manager')
                ->findTranslationBy(
                    array(
                        'transKey' => $key,
                        'transLocale' => $loc,
                        'messageDomain' => $domain,
                    )
                );
            if($translation){
                $trans = new TranslationTranslation();
                $trans->setLocale($loc);
                $trans->setValue($translation->getTranslation());
                $entity->addTranslation($trans);
            }
            
        }
        
        $deleteForm = $this->createDeleteForm($key, $domain);
        $editForm = $this->createForm('CoreBundle\Form\TranslationType', $entity);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            
            //Create entry in DB
            $this->updateTranslation($entity);
            
            $this->get('session')->getFlashBag()->add('success', 'translation.edited');
            
            return $this->redirectToRoute('core_translation_index');
        }

        return $this->render('CoreBundle:Translation:edit.html.twig', array(
            'entity' => $entity,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }
1061115
public function changeLanguageAction(Request $request, $oldLocale, $locale)
    {
        $params = [];

        $translationRoute = $this->getTranslationRoute($request->headers->get('referer'), $oldLocale, $locale);

        $request->setLocale($locale);

        if (!is_array($translationRoute)) {
            $routeName = $translationRoute;
        } else {
            $routeName = $translationRoute['_route'];
            unset($translationRoute['_route']);
            foreach ($translationRoute as $key => $var) {
                $params[$key] = $var;
            }
        }

        $params['_locale'] = $locale;

        $parts = parse_url($request->headers->get('referer'));

        if (array_key_exists('query', $parts) && $parts['query']) {
            parse_str($parts['query'], $query);

            $params = array_merge($query, $params);
        }

        $newURL = $this->get('router')->generate($routeName, $params);

        $response = new RedirectResponse($newURL);

        if ($this->getPageHelper()->isAllowLocaleCookie()) {
            $response->headers->setCookie(new Cookie('_locale', $locale));
        }

        return $response;
    }
358673
public function redirecionar(
        Request $request,
        AtendimentoService $atendimentoService,
        TranslatorInterface $translator
    ) {
        $envelope = new Envelope();
        $data     = json_decode($request->getContent());

        $usuario     = $this->getUser();
        $unidade     = $usuario->getLotacao()->getUnidade();
        $servico     = (int) $data->servico;
        $novoUsuario = null;
        $atual       = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade);

        if (!$atual) {
            throw new Exception(
                $translator->trans('error.attendance.not_in_process', [], self::DOMAIN)
            );
        }
        
        if (isset($data->usuario)) {
            $novoUsuario = $this
                ->getDoctrine()
                ->getManager()
                ->getRepository(Usuario::class)
                ->find($data->usuario);
        }

        $redirecionado = $atendimentoService->redirecionar($atual, $unidade, $servico, $novoUsuario);
        if (!$redirecionado->getId()) {
            throw new Exception(
                $translator->trans(
                    'error.attendance.redirect',
                    [
                        '%atendimento%' => $atual->getId(),
                        '%servico%'     => $servico,
                    ],
                    self::DOMAIN
                )
            );
        }

        return $this->json($envelope);
    }
848344
public function createView(Request $request)
    {
        $viewInput = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        if ($viewInput->query instanceof LocationQuery) {
            $method = 'findLocations';
        } else {
            $method = 'findContent';
        }

        return new Values\RestExecutedView(
            array(
                'identifier' => $viewInput->identifier,
                'searchResults' => $this->searchService->$method(
                    $viewInput->query,
                    ['languages' => Language::ALL]
                ),
            )
        );
    }
1691
public function naoCompareceu(
        Request $request,
        AtendimentoService $atendimentoService,
        TranslatorInterface $translator
    ) {
        $usuario = $this->getUser();
        $unidade = $usuario->getLotacao()->getUnidade();
        $atual   = $atendimentoService->atendimentoAndamento($usuario->getId(), $unidade);

        if (!$atual) {
            throw new Exception(
                $translator->trans('error.attendance.empty', [], self::DOMAIN)
            );
        }
        
        $atendimentoService->naoCompareceu($atual, $usuario);

        $data     = $atual->jsonSerialize();
        $envelope = new Envelope();
        $envelope->setData($data);

        return $this->json($envelope);
    }
289803
public function apply(Request $request, ParamConverter $configuration)
    {
        if (null === $parameter = $configuration->getName()) {
            throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_NAME);
        }

        $options = $configuration->getOptions();

        if ($options['authenticatedUser'] === true) {
            if (($user = $this->tokenStorage->getToken()->getUser()) instanceof User) {
                $request->attributes->set($parameter, $user);

                return true;
            } else {
                if (array_key_exists('messageEnabled', $options) && $options['messageEnabled'] === true) {
                    $messageType = 'warning';
                    if (array_key_exists('messageType', $options)) {
                        $messageType = $options['messageType'];
                    }

                    $messageTranslationKey = 'this_page_requires_authentication';
                    $messageTranslationDomain = 'platform';
                    if (array_key_exists('messageTranslationKey', $options)) {
                        $messageTranslationKey = $options['messageTranslationKey'];
                        if (array_key_exists('messageTranslationDomain', $options)) {
                            $messageTranslationDomain = $options['messageTranslationDomain'];
                        }
                    }

                    $request->getSession()->getFlashBag()->add(
                        $messageType,
                        $this->translator->trans($messageTranslationKey, [], $messageTranslationDomain)
                    );
                }

                throw new AccessDeniedException();
            }
        } else {
            $request->attributes->set($parameter, $user = $this->tokenStorage->getToken()->getUser());
        }
    }
604649
public function handleAdd($grid, $request)
    {
        $class     = $request->param('ClassName');
        $classes   = $this->getClasses($grid);
        /** @var GridFieldDetailForm $component */
        $component = $grid->getConfig()->getComponentByType(GridFieldDetailForm::class);

        if (!$component) {
            throw new Exception('The add new multi class component requires the detail form component.');
        }

        if (!$class || !array_key_exists($class, $classes)) {
            throw new HTTPResponse_Exception(400);
        }

        $unsanitisedClass = $this->unsanitiseClassName($class);
        $handler = Injector::inst()->create(
            $this->itemRequestClass,
            $grid,
            $component,
            new $unsanitisedClass(),
            $grid->getForm()->getController(),
            'add-multi-class'
        );
        $handler->setTemplate($component->getTemplate());

        return $handler;
    }
1076270
protected function gridView($view)
    {
        $request = request();

        $fields = $this->sg_searchable_fields;

        $filters = function ($query) use ($request, $fields) {

            $q = $request->get('q', NULL);
            if ($q !== NULL) {
                foreach ($fields as $index => $name) {
                    if ($index == 0) {
                        $query->where($name, 'like', "%{$q}%");
                    }
                    else {
                        $query->orWhere($name, 'like', "%{$q}%");
                    }
                }
            }
        };

        $order   = strtolower($request->get('order', $this->sg_initial_field));
        $by      = strtolower($request->get('by', $this->sg_initial_order));
        $perpage = $request->get('perpage', $this->sg_initial_perpage);

        $collection = $this->getDataProvider()
            ->where($filters)
            ->orderBy($order, $by)
            ->paginate($perpage)
            ->appends($request->all());

        $view_pagination = config('sortablegrid.views.pagination');

        // Guarda os dados para o blade identificar
        session([
            'sg.fields'          => $this->sg_fields,
            'sg.searchable'      => $this->sg_searchable_fields,
            'sg.orderly'         => $this->sg_orderly_fields,
            'sg.order_field'     => $order,
            'sg.order_direction' => $by,
            'sg.total_registers' => $collection->total(),
            'sg.first_item'      => $collection->firstItem(),
            'sg.last_item'       => $collection->lastItem(),
            'sg.last_page'       => $collection->lastPage(),
            'sg.invalid_page'    => ($collection->currentPage() > $collection->lastPage()),
            'sg.pagination'      => $collection->links($view_pagination),
            'sg.perpage'         => $perpage,
        ]);

        return view($view)->with('collection', $collection);
    }
746926
public static function translate($key, $params = [], $language = null, Viewmodel $viewmodel = null) {
		
		$identifier = null;

		if(null !== $viewmodel) {
			$identifier = static :: load($viewmodel);
		}

		if(null === $key) {
			$key = '';
		}

		//Check if key is a string
		if(false === is_string($key)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
		}

		//Check if params is an array
		if(null !== $params && false === is_array($params)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
		}

		//Check if language is a string
		if(null !== $language && false === is_string($language)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($language)), E_USER_ERROR);
		}

		//Set default language if non given
		if(null === $language) {
			$language = static :: $language;
		}

		//If identifier is known (usually with a viewmodel as last param)
		if(null !== $identifier) {

			if(true === isset(static :: $translations[$identifier], static :: $translations[$identifier][$language])) {

				if(true === isset(static :: $translations[$identifier][$language][$key])) {
					return vsprintf(static :: $translations[$identifier][$language][$key], $params);
				}
			}
		}

		//Check the full resource for the translation
		foreach(static :: $translations as $translation) {

			if(true === isset($translation[$language][$key])) {
				return vsprintf($translation[$language][$key], $params);
			}
		}

		//No translation found
		return vsprintf($key, $params);
	}
1179499
public function updateAction(Request $request, $id)
    {
        $response = ['error' => false];

        try {
            $this->get('ongr_translations.translation_manager')->edit($id, $request);
        } catch (\LogicException $e) {
            $response = ['error' => true];
        }

        return new JsonResponse($response);
    }
341446
public function servicoInfo(Request $request, TranslatorInterface $translator)
    {
        $em       = $this->getDoctrine()->getManager();
        $id       = (int) $request->get('id');
        $usuario  = $this->getUser();
        $unidade  = $usuario->getLotacao()->getUnidade();
        $servico  = $em->find(Servico::class, $id);
        $envelope = new Envelope();
        
        if (!$servico) {
            throw new Exception($translator->trans('error.invalid_service', [], self::DOMAIN));
        }
        
        $data = [
            'nome' => $servico->getNome(),
            'descricao' => $servico->getDescricao()
        ];

        // ultima senha
        $atendimento = $em->getRepository(Atendimento::class)->getUltimo($unidade, $servico);
        
        if ($atendimento) {
            $data['senha']   = $atendimento->getSenha()->__toString();
            $data['senhaId'] = $atendimento->getId();
        } else {
            $data['senha']   = '-';
            $data['senhaId'] = '';
        }
        
        // subservicos
        $data['subservicos'] = [];
        $subservicos = $em->getRepository(Servico::class)->getSubservicos($servico);

        foreach ($subservicos as $s) {
            $data['subservicos'][] = $s->getNome();
        }

        $envelope->setData($data);

        return $this->json($envelope);
    }
336868
public function createRowAction(Request $request)
    {
        $container = $this->findContainer(intval($request->attributes->get('containerId')));

        $target = is_null($container->getCopy()) ? $container : $container->getCopy();

        try {
            $row = $this->getEditor()->createDefaultRow([], $target);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

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

        $viewBuilder = $this->getViewBuilder();

        $data = [
            'created'    => $viewBuilder->buildRow($row)->getAttributes()->getId(),
            'containers' => [$viewBuilder->buildContainer($container)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
595788
public function listAction(Request $request)
    {
        list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPage($request);

        return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
    }
254491
public function create(Request $request, FormBuilder $formBuilder, $id)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin', 'editor']);

        // Check if pagetype id exist, otherwise gtfo
        if (!$id) {
            return redirect()->route('admin.pages.page.select');
        }

        // Get pagetype, or fail..
        $pagetype = PageType::findOrFail($id);

        // Get fields
        $fields = $pagetype->fields ?: [];

        // Build the form
        $form = $formBuilder->createByArray($fields, [
            'method' => 'POST',
            'url' => route('admin.pages.page.store'),
            'name' => 'content'
        ]);

        return view('page::pages.create', [
            'pagetype' => $pagetype,
            'form' => $form
        ]);
    }
785921
public function historyAction(Request $request, $id)
    {
        $document = $this->get('ongr_translations.translation_manager')->get($id);

        if (empty($document)) {
            return new JsonResponse(['error' => true, 'message' => 'translation not found']);
        }

        return new JsonResponse($this->get('ongr_translations.history_manager')->get($document));
    }
658429
public function postGenerateAction(Request $request)
    {
        $parentUuid = $this->getRequestParameter($request, 'parent');
        $parts = $this->getRequestParameter($request, 'parts', true);
        $templateKey = $this->getRequestParameter($request, 'template', true);
        $webspaceKey = $this->getRequestParameter($request, 'webspace', true);
        $languageCode = $this->getLocale($request);

        $result = $this->getResourceLocatorRepository()->generate(
            $parts,
            $parentUuid,
            $webspaceKey,
            $languageCode,
            $templateKey
        );

        return $this->handleView($this->view($result));
    }