本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getDefaultLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getDefaultLocale方法的具体用法?PHP Request::getDefaultLocale怎么用?PHP Request::getDefaultLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getDefaultLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* Finds and displays a Users of a Journal with roles
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$eventDispatcher = $this->get('event_dispatcher');
if (!$this->isGranted('VIEW', $journal, 'userRole')) {
throw new AccessDeniedException("You are not authorized for view this page");
}
$source = new Entity('OjsJournalBundle:JournalUser');
$source->manipulateRow(function (Row $row) use($request) {
/* @var JournalUser $entity */
$entity = $row->getEntity();
if (!is_null($entity)) {
$entity->getJournal()->setDefaultLocale($request->getDefaultLocale());
if (!is_null($entity)) {
$row->setField('journal', $entity->getJournal()->getTitle());
}
}
return $row;
});
$grid = $this->get('grid');
$grid->setSource($source);
$gridAction = $this->get('grid_action');
$rowAction = [];
$rowAction[] = $gridAction->editAction('ojs_journal_user_edit', ['journalId' => $journal->getId(), 'id']);
$rowAction[] = $gridAction->deleteAction('ojs_journal_user_delete', ['journalId' => $journal->getId(), 'id']);
$actionColumn = new ActionsColumn("actions", "actions");
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$listEvent = new ListEvent();
$listEvent->setGrid($grid);
$eventDispatcher->dispatch(JournalUserEvents::LISTED, $listEvent);
$grid = $listEvent->getGrid();
return $grid->getGridResponse('OjsJournalBundle:JournalUser:index.html.twig');
}
示例2: indexAction
/**
* Lists all article entities for journal
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$this->throw404IfNotFound($journal);
if (!$this->isGranted('VIEW', $journal, 'articles')) {
throw new AccessDeniedException("You not authorized for this page!");
}
$source = new Entity('OjsJournalBundle:Article');
$source->manipulateRow(function (Row $row) use($request) {
/** @var Article $entity */
$entity = $row->getEntity();
$entity->setDefaultLocale($request->getDefaultLocale());
if (!is_null($entity)) {
$row->setField('title', $entity->getTitle());
if (!is_null($entity->getIssue())) {
$row->setField('issue', $entity->getIssue()->getTitle());
}
}
return $row;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_journal_article_show', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->editAction('ojs_journal_article_edit', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->deleteAction('ojs_journal_article_delete', ['id', 'journalId' => $journal->getId()]);
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
return $grid->getGridResponse('OjsJournalBundle:Article:index.html.twig', ['journal' => $journal]);
}
示例3: journalAction
/**
* @param Request $request
* @return RedirectResponse|Response
*/
public function journalAction(Request $request)
{
$allowanceSetting = $this->getDoctrine()->getRepository('OjsAdminBundle:SystemSetting')->findOneBy(['name' => 'journal_application']);
if ($allowanceSetting) {
if (!$allowanceSetting->getValue()) {
return $this->render('OjsSiteBundle:Site:not_available.html.twig', ['title' => 'title.journal_application', 'message' => 'message.application_not_available']);
}
}
$application = new Journal();
$application->setCurrentLocale($request->getDefaultLocale());
$form = $this->createForm(new JournalApplicationType(), $application);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$application->setStatus(0);
/** @var JournalContact $contact */
if ($application->getJournalContacts()) {
foreach ($application->getJournalContacts() as $contact) {
$contact->setJournal($application);
}
}
$em = $this->getDoctrine()->getManager();
$em->persist($application);
$em->flush();
return $this->redirect($this->get('router')->generate('ojs_apply_journal_success'));
}
$session = $this->get('session');
$session->getFlashBag()->add('error', $this->get('translator')->trans('An error has occured. Please check the form and resubmit.'));
$session->save();
}
return $this->render('OjsSiteBundle:Application:journal.html.twig', array('form' => $form->createView()));
}
示例4: indexAction
public function indexAction(Request $request)
{
$data = array();
$source = new Entity('OjsJournalBundle:Journal');
$source->manipulateRow(function (Row $row) use($request) {
/* @var Journal $entity */
$entity = $row->getEntity();
$entity->setDefaultLocale($request->getDefaultLocale());
if (!is_null($entity)) {
$row->setField('title', $entity->getTitle());
}
return $row;
});
$alias = $source->getTableAlias();
$source->manipulateQuery(function (QueryBuilder $query) use($alias) {
$query->andWhere($alias . '.status = :status')->setParameter('status', '0');
return $query;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$rowAction = array();
$rowAction[] = $gridAction->editAction('ojs_admin_application_journal_edit', 'id');
$rowAction[] = $gridAction->showAction('ojs_admin_application_journal_show', 'id');
$rowAction[] = $gridAction->deleteAction('ojs_admin_application_journal_delete', 'id');
$actionColumn = new ActionsColumn("actions", 'actions');
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data['grid'] = $grid;
return $grid->getGridResponse('OjsAdminBundle:AdminApplication:journal.html.twig', $data);
}
示例5: indexAction
/**
* Lists all Period entities.
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
if (!$this->isGranted('VIEW', new Period())) {
throw new AccessDeniedException("You are not authorized for view this page");
}
$source = new Entity('OjsJournalBundle:Period');
$source->manipulateRow(function (Row $row) use($request) {
/* @var Journal $entity */
$entity = $row->getEntity();
$entity->setDefaultLocale($request->getDefaultLocale());
if (!is_null($entity)) {
$row->setField('period', $entity->getPeriod());
}
return $row;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_admin_period_show', 'id');
$rowAction[] = $gridAction->editAction('ojs_admin_period_edit', 'id');
$rowAction[] = $gridAction->deleteAction('ojs_admin_period_delete', 'id');
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data = [];
$data['grid'] = $grid;
return $grid->getGridResponse('OjsAdminBundle:AdminPeriod:index.html.twig', $data);
}
示例6: indexAction
/**
* Lists all ArticleAuthor entities.
*
* @param Integer $articleId
* @return Response
*/
public function indexAction($articleId, Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$article = $this->getDoctrine()->getRepository('OjsJournalBundle:Article')->find($articleId);
$this->throw404IfNotFound($article);
if (!$this->isGranted('VIEW', $journal, 'articles')) {
throw new AccessDeniedException("You not authorized for this page!");
}
$source = new Entity('OjsJournalBundle:ArticleAuthor');
$source->manipulateRow(function (Row $row) use($request) {
/* @var ArticleAuthor $entity */
$entity = $row->getEntity();
if (!is_null($entity)) {
$entity->getArticle()->setDefaultLocale($request->getDefaultLocale());
$row->setField('article', $entity->getArticle()->getTitle());
}
return $row;
});
$tableAlias = $source->getTableAlias();
$source->manipulateQuery(function (QueryBuilder $qb) use($article, $tableAlias) {
return $qb->where($tableAlias . '.article = :article')->setParameter('article', $article);
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_journal_article_author_show', ['id', 'journalId' => $journal->getId(), 'articleId' => $articleId]);
$rowAction[] = $gridAction->editAction('ojs_journal_article_author_edit', ['id', 'journalId' => $journal->getId(), 'articleId' => $articleId]);
$rowAction[] = $gridAction->deleteAction('ojs_journal_article_author_delete', ['id', 'journalId' => $journal->getId(), 'articleId' => $articleId]);
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data = [];
$data['grid'] = $grid;
$data['article'] = $article;
return $grid->getGridResponse('OjsJournalBundle:ArticleAuthor:index.html.twig', $data);
}
示例7: localeRedirectAction
/**
* This route decides wheater a request has a missing locale or it is a missing page
*
* @param Request $request
*
* @return Response
*/
public function localeRedirectAction(Request $request)
{
$requestUri = $request->getRequestUri();
$explodedUri = explode('/', $requestUri);
$doubleSlash = substr($requestUri, 0, 2) === '//';
if (!$doubleSlash) {
// does not start with 2 slashes
if (strlen($explodedUri[1]) !== 2) {
// no locale supplied
$matchingRoute = $this->get('router')->match("/" . $requestUri);
} else {
// 404
throw $this->createNotFoundException();
}
} else {
$requestUri = substr($requestUri, 2);
// Removed first 2 slashes
$locale = empty($request->getLocale()) ? $request->getDefaultLocale() : mb_substr($request->getLocale(), 0, 2);
$requestUri = '/' . $locale . '/' . $requestUri;
$matchingRoute = $this->get('router')->match($requestUri);
}
if ($matchingRoute['_controller'] === 'Ashura\\OptionalLocaleBundle\\Controller\\DefaultController::localeRedirectAction') {
throw $this->createNotFoundException();
}
return $this->forward($matchingRoute['_controller']);
}
示例8: indexAction
/**
* Lists all JournalIndex entities.
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
if (!$this->isGranted('VIEW', $journal, 'index')) {
throw new AccessDeniedException("You are not authorized for view this page!");
}
$source = new Entity('OjsJournalBundle:JournalIndex');
$source->manipulateRow(function (Row $row) use($request) {
/* @var JournalIndex $entity */
$entity = $row->getEntity();
$entity->getJournal()->setDefaultLocale($request->getDefaultLocale());
return $row;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_journal_index_show', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->editAction('ojs_journal_index_edit', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->deleteAction('ojs_journal_index_delete', ['id', 'journalId' => $journal->getId()]);
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data = [];
$data['grid'] = $grid;
return $grid->getGridResponse('OjsJournalBundle:JournalIndex:index.html.twig', $data);
}
示例9: indexAction
public function indexAction(Request $request)
{
$data = array();
$source = new Entity('OjsJournalBundle:Journal');
$source->manipulateRow(function (Row $row) use($request) {
/* @var Journal $entity */
$entity = $row->getEntity();
$entity->setDefaultLocale($request->getDefaultLocale());
if (!is_null($entity)) {
$row->setField('title', $entity->getTitle());
}
return $row;
});
$alias = $source->getTableAlias();
$source->manipulateQuery(function (QueryBuilder $query) use($alias) {
$query->andWhere($alias . '.status = :status')->setParameter('status', JournalStatuses::STATUS_PREPARING);
return $query;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$saveAction = new RowAction('<i class="fa fa-save"></i>', 'ojs_admin_application_journal_save');
$saveAction->setRouteParameters(['id']);
$saveAction->setAttributes(['class' => 'btn btn-primary btn-xs', 'title' => $this->get('translator')->trans('journal.merge_as_new_journal')]);
$rowAction = array();
$rowAction[] = $saveAction;
$rowAction[] = $gridAction->editAction('ojs_admin_application_journal_edit', 'id');
$rowAction[] = $gridAction->showAction('ojs_admin_application_journal_show', 'id');
$rowAction[] = $gridAction->deleteAction('ojs_admin_application_journal_delete', 'id');
$actionColumn = new ActionsColumn("actions", 'actions');
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data['grid'] = $grid;
return $grid->getGridResponse('OjsAdminBundle:AdminApplication:journal.html.twig', $data);
}
示例10: indexAction
/**
* Lists all Design entities.
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
if (!$this->isGranted('VIEW', $journal, 'design')) {
throw new AccessDeniedException("You are not authorized for view this journal's designs!");
}
$source = new Entity('OjsJournalBundle:Design');
$tableAlias = $source->getTableAlias();
$source->manipulateQuery(function ($query) use($tableAlias, $journal) {
$query->andWhere($tableAlias . '.owner = :journal')->setParameter('journal', $journal);
});
$source->manipulateRow(function (Row $row) use($request) {
/* @var Design $entity */
$entity = $row->getEntity();
if (!is_null($entity)) {
$entity->getOwner()->setDefaultLocale($request->getDefaultLocale());
$row->setField('owner', $entity->getOwner()->getTitle());
}
return $row;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_journal_design_show', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->editAction('ojs_journal_design_edit', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->deleteAction('ojs_journal_design_delete', ['id', 'journalId' => $journal->getId()]);
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$data = [];
$data['grid'] = $grid;
return $grid->getGridResponse('OjsJournalBundle:Design:index.html.twig', $data);
}
示例11: setLocale
private function setLocale(Request $request)
{
try {
$this->translator->setLocale($request->getLocale());
} catch (\InvalidArgumentException $e) {
$this->translator->setLocale($request->getDefaultLocale());
}
}
示例12: newAction
/**
* Displays a form to create a new JournalPost entity.
*
* @param Request $request
* @return Response
*/
public function newAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
if (!$this->isGranted('CREATE', $journal, 'posts')) {
throw new AccessDeniedException("You are not authorized for this post!");
}
$entity = new JournalPost();
$entity->setCurrentLocale($request->getDefaultLocale());
$form = $this->createCreateForm($entity);
return $this->render('OjsJournalBundle:JournalPost:new.html.twig', ['entity' => $entity, 'form' => $form->createView()]);
}
示例13: getTranslationsFields
/**
* @param $object
* @param $field
* @return mixed
*/
public function getTranslationsFields($object, $field)
{
if ($this->objectTranslations[$object->getId()]->count() > 0) {
return $this->getCurrentTranslation($object, $field);
}
$repoTranslation = $this->em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
$languages = array_merge($this->request->getLanguages(), [$this->request->getDefaultLocale()]);
$elements = $repoTranslation->findBy(['foreignKey' => $object->getId(), 'objectClass' => get_class($object), 'locale' => $languages]);
foreach ($elements as $element) {
$this->objectTranslations[$object->getId()]->add($element);
}
return $this->getCurrentTranslation($object, $field);
}
示例14: indexAction
/**
* Lists all article entities for journal
*
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$eventDispatcher = $this->get('event_dispatcher');
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$this->throw404IfNotFound($journal);
$translator = $this->get('translator');
if (!$this->isGranted('VIEW', $journal, 'articles')) {
throw new AccessDeniedException("You not authorized for this page!");
}
$source = new Entity('OjsJournalBundle:Article');
$source->manipulateRow(function (Row $row) use($request, $translator) {
/** @var Article $entity */
$entity = $row->getEntity();
if (!is_null($entity)) {
$entity->setDefaultLocale($request->getDefaultLocale());
$doi = $entity->getDoi();
if ($doi !== null) {
$row->setField('title', $entity->getTitle() . ' / ' . $doi);
} else {
$row->setField('title', $entity->getTitle());
}
$row->setField('status', $translator->trans(Article::$statuses[$entity->getStatus()]));
if (!is_null($entity->getIssue())) {
$row->setField('issue', $entity->getIssue()->getTitle());
}
}
return $row;
});
$grid = $this->get('grid')->setSource($source);
$gridAction = $this->get('grid_action');
$actionColumn = new ActionsColumn("actions", 'actions');
$rowAction[] = $gridAction->showAction('ojs_journal_article_show', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->editAction('ojs_journal_article_edit', ['id', 'journalId' => $journal->getId()]);
$rowAction[] = $gridAction->deleteAction('ojs_journal_article_delete', ['id', 'journalId' => $journal->getId()]);
$actionColumn->setRowActions($rowAction);
$grid->addColumn($actionColumn);
$grid->getColumn('numerator')->manipulateRenderCell(function ($value, $row, $router) use($journal) {
if ($journal->getTitleAbbr() !== null) {
return $journal->getTitleAbbr() . '.' . $value;
} else {
return $journal->getSlug() . '.' . $value;
}
});
$listEvent = new ListEvent();
$listEvent->setGrid($grid);
$eventDispatcher->dispatch(ArticleEvents::LISTED, $listEvent);
$grid = $listEvent->getGrid();
return $grid->getGridResponse('OjsJournalBundle:Article:index.html.twig');
}
示例15: createAction
/**
* Creates a new Page entity.
*
* @param Request $request
* @return RedirectResponse|Response
*/
public function createAction(Request $request)
{
$entity = new AdminPage();
$entity->setCurrentLocale($request->getDefaultLocale());
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$entity->setSlug($entity->getTranslationByLocale($request->getDefaultLocale())->getTitle());
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
$this->successFlashBag('successful.create');
return $this->redirectToRoute('ojs_admin_page_show', ['id' => $entity->getId()]);
}
return $this->render('OjsAdminBundle:AdminPage:new.html.twig', ['entity' => $entity, 'form' => $form->createView()]);
}