TYPO3 CMS  TYPO3_7-6
AjaxController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
34  public function switchWorkspaceAction(ServerRequestInterface $request, ResponseInterface $response)
35  {
36  $parsedBody = $request->getParsedBody();
37  $queryParams = $request->getQueryParams();
38  $workspaceId = (int)(isset($parsedBody['workspaceId']) ? $parsedBody['workspaceId'] : $queryParams['workspaceId']);
39  $pageId = (int)(isset($parsedBody['pageId']) ? $parsedBody['pageId'] : $queryParams['pageId']);
40  $finalPageUid = 0;
41  $originalPageId = $pageId;
42 
43  $this->getBackendUser()->setWorkspace($workspaceId);
44 
45  while ($pageId) {
46  $page = BackendUtility::getRecordWSOL('pages', $pageId, '*',
47  ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')');
48  if ($page) {
49  if ($this->getBackendUser()->doesUserHaveAccess($page, 1)) {
50  break;
51  }
52  } else {
53  $page = BackendUtility::getRecord('pages', $pageId);
54  }
55  $pageId = $page['pid'];
56  }
57 
58  if (isset($page['uid'])) {
59  $finalPageUid = (int)$page['uid'];
60  }
61 
62  $ajaxResponse = [
64  'workspaceId' => $workspaceId,
65  'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid
66  ];
67  $response->getBody()->write(json_encode($ajaxResponse));
68  return $response;
69  }
70 
74  protected function getBackendUser()
75  {
76  return $GLOBALS['BE_USER'];
77  }
78 }
switchWorkspaceAction(ServerRequestInterface $request, ResponseInterface $response)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)