0512b873ab802391f6e6f3a2a4a546c9e1d6682e
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / AbstractWizardController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
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
17 use TYPO3\CMS\Backend\Template\DocumentTemplate;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Database\DatabaseConnection;
21 use TYPO3\CMS\Core\Type\Bitmask\Permission;
22 use TYPO3\CMS\Lang\LanguageService;
23
24 /**
25 * Class AbstractWizardController
26 */
27 class AbstractWizardController {
28
29 /**
30 * Checks access for element
31 *
32 * @param string $table Table name
33 * @param int $uid Record uid
34 * @return bool
35 */
36 protected function checkEditAccess($table, $uid) {
37 $calcPermissionRecord = BackendUtility::getRecord($table, $uid);
38 BackendUtility::fixVersioningPid($table, $calcPermissionRecord);
39 if (is_array($calcPermissionRecord)) {
40 // If pages:
41 if ($table === 'pages') {
42 $calculatedPermissions = $this->getBackendUserAuthentication()->calcPerms($calcPermissionRecord);
43 $hasAccess = $calculatedPermissions & Permission::PAGE_EDIT;
44 } else {
45 // Fetching pid-record first.
46 $calculatedPermissions = $this->getBackendUserAuthentication()->calcPerms(
47 BackendUtility::getRecord('pages', $calcPermissionRecord['pid']));
48 $hasAccess = $calculatedPermissions & Permission::CONTENT_EDIT;
49 }
50 // Check internals regarding access:
51 if ($hasAccess) {
52 $hasAccess = $this->getBackendUserAuthentication()->recordEditAccessInternals($table, $calcPermissionRecord);
53 }
54 } else {
55 $hasAccess = FALSE;
56 }
57 return (bool)$hasAccess;
58 }
59
60 /**
61 * Returns an instance of BackendUserAuthentication
62 *
63 * @return BackendUserAuthentication
64 */
65 protected function getBackendUserAuthentication() {
66 return $GLOBALS['BE_USER'];
67 }
68
69 /**
70 * Returns an instance of LanguageService
71 *
72 * @return LanguageService
73 */
74 protected function getLanguageService() {
75 return $GLOBALS['LANG'];
76 }
77
78 /**
79 * Returns the backpath
80 *
81 * @return string
82 */
83 protected function getBackPath() {
84 return $GLOBALS['BACK_PATH'];
85 }
86
87 /**
88 * Returns an instance of DocumentTemplate
89 *
90 * @return DocumentTemplate
91 */
92 protected function getDocumentTemplate() {
93 return $GLOBALS['TBE_TEMPLATE'];
94 }
95
96 /**
97 * Returns an instance of DatabaseConnection
98 *
99 * @return DatabaseConnection
100 */
101 protected function getDatabaseConnection() {
102 return $GLOBALS['TYPO3_DB'];
103 }
104
105 }