Completed
Push — master ( 5794c5...08c98b )
by Fabien
53:00
created
Classes/Tool/AbstractTool.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -18,40 +18,40 @@
 block discarded – undo
18 18
  */
19 19
 abstract class AbstractTool implements ToolInterface
20 20
 {
21
-    /**
22
-     * @param string $templateNameAndPath
23
-     * @return StandaloneView
24
-     * @throws \InvalidArgumentException
25
-     */
26
-    protected function initializeStandaloneView($templateNameAndPath)
27
-    {
28
-        $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
21
+	/**
22
+	 * @param string $templateNameAndPath
23
+	 * @return StandaloneView
24
+	 * @throws \InvalidArgumentException
25
+	 */
26
+	protected function initializeStandaloneView($templateNameAndPath)
27
+	{
28
+		$templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
29 29
 
30
-        /** @var StandaloneView $view */
31
-        $view = GeneralUtility::makeInstance(StandaloneView::class);
30
+		/** @var StandaloneView $view */
31
+		$view = GeneralUtility::makeInstance(StandaloneView::class);
32 32
 
33
-        $view->setTemplatePathAndFilename($templateNameAndPath);
34
-        return $view;
35
-    }
33
+		$view->setTemplatePathAndFilename($templateNameAndPath);
34
+		return $view;
35
+	}
36 36
 
37
-    /**
38
-     * Returns an instance of the current Backend User.
39
-     *
40
-     * @return BackendUserAuthentication
41
-     */
42
-    protected function getBackendUser()
43
-    {
44
-        return $GLOBALS['BE_USER'];
45
-    }
37
+	/**
38
+	 * Returns an instance of the current Backend User.
39
+	 *
40
+	 * @return BackendUserAuthentication
41
+	 */
42
+	protected function getBackendUser()
43
+	{
44
+		return $GLOBALS['BE_USER'];
45
+	}
46 46
 
47
-    /**
48
-     * Get the Vidi Module Loader.
49
-     *
50
-     * @return ModuleLoader
51
-     * @throws \InvalidArgumentException
52
-     */
53
-    protected function getModuleLoader()
54
-    {
55
-        return GeneralUtility::makeInstance(ModuleLoader::class);
56
-    }
47
+	/**
48
+	 * Get the Vidi Module Loader.
49
+	 *
50
+	 * @return ModuleLoader
51
+	 * @throws \InvalidArgumentException
52
+	 */
53
+	protected function getModuleLoader()
54
+	{
55
+		return GeneralUtility::makeInstance(ModuleLoader::class);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
Classes/Tool/ModulePreferencesTool.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -22,121 +22,121 @@
 block discarded – undo
22 22
  */
23 23
 class ModulePreferencesTool extends AbstractTool
24 24
 {
25
-    /**
26
-     * Display the title of the tool on the welcome screen.
27
-     *
28
-     * @return string
29
-     */
30
-    public function getTitle()
31
-    {
32
-        return LocalizationUtility::translate(
33
-            'module_preferences_for',
34
-            'vidi',
35
-            array(Tca::table($this->getModuleLoader()->getDataType())->getTitle())
36
-        );
37
-    }
38
-
39
-    /**
40
-     * Display the description of the tool in the welcome screen.
41
-     *
42
-     * @return string
43
-     */
44
-    public function getDescription()
45
-    {
46
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/Launcher.html';
47
-        $view = $this->initializeStandaloneView($templateNameAndPath);
48
-        $view->assign('sitePath', Environment::getPublicPath() . '/');
49
-        return $view->render();
50
-    }
51
-
52
-    /**
53
-     * Do the job!
54
-     *
55
-     * @param array $arguments
56
-     * @return string
57
-     */
58
-    public function work(array $arguments = array())
59
-    {
60
-        if (isset($arguments['save'])) {
61
-            // Revert visible <-> excluded
62
-            $excludedFields = array_diff(
63
-                Tca::grid()->getAllFieldNames(),
64
-                $arguments['excluded_fields'],
65
-                $this->getExcludedFieldsFromTca()
66
-            );
67
-            $arguments['excluded_fields'] = $excludedFields;
68
-            $this->getModulePreferences()->save($arguments);
69
-        }
70
-
71
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html';
72
-        $view = $this->initializeStandaloneView($templateNameAndPath);
73
-
74
-        $view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle());
75
-
76
-        // Fetch the menu of visible items.
77
-        $menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS);
78
-        $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems);
79
-
80
-        // Fetch the default number of menu visible items.
81
-        $menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT);
82
-        $view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible);
83
-
84
-        // Get the visible columns
85
-        $view->assign('columns', Tca::grid()->getAllFieldNames());
86
-
87
-        return $view->render();
88
-    }
89
-
90
-    /**
91
-     * @return array
92
-     */
93
-    protected function getExcludedFieldsFromTca()
94
-    {
95
-        $tca = Tca::grid()->getTca();
96
-        $excludedFields = [];
97
-        if (!empty($tca['excluded_fields'])) {
98
-            $excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true);
99
-        } elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason.
100
-            $excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true);
101
-        }
102
-        return $excludedFields;
103
-    }
104
-
105
-    /**
106
-     * Tell whether the tools should be displayed according to the context.
107
-     *
108
-     * @return bool
109
-     */
110
-    public function isShown()
111
-    {
112
-        return $this->getBackendUser()->isAdmin();
113
-    }
114
-
115
-    /**
116
-     * Get the Vidi Module Loader.
117
-     *
118
-     * @return ModuleLoader|object
119
-     */
120
-    protected function getModuleLoader()
121
-    {
122
-        return GeneralUtility::makeInstance(ModuleLoader::class);
123
-    }
124
-
125
-    /**
126
-     * @return ModulePreferences|object
127
-     */
128
-    protected function getModulePreferences()
129
-    {
130
-        return GeneralUtility::makeInstance(ModulePreferences::class);
131
-    }
132
-
133
-    /**
134
-     * Get the Vidi Module Loader.
135
-     *
136
-     * @return GridAnalyserService|object
137
-     */
138
-    protected function getGridAnalyserService()
139
-    {
140
-        return GeneralUtility::makeInstance(GridAnalyserService::class);
141
-    }
25
+	/**
26
+	 * Display the title of the tool on the welcome screen.
27
+	 *
28
+	 * @return string
29
+	 */
30
+	public function getTitle()
31
+	{
32
+		return LocalizationUtility::translate(
33
+			'module_preferences_for',
34
+			'vidi',
35
+			array(Tca::table($this->getModuleLoader()->getDataType())->getTitle())
36
+		);
37
+	}
38
+
39
+	/**
40
+	 * Display the description of the tool in the welcome screen.
41
+	 *
42
+	 * @return string
43
+	 */
44
+	public function getDescription()
45
+	{
46
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/Launcher.html';
47
+		$view = $this->initializeStandaloneView($templateNameAndPath);
48
+		$view->assign('sitePath', Environment::getPublicPath() . '/');
49
+		return $view->render();
50
+	}
51
+
52
+	/**
53
+	 * Do the job!
54
+	 *
55
+	 * @param array $arguments
56
+	 * @return string
57
+	 */
58
+	public function work(array $arguments = array())
59
+	{
60
+		if (isset($arguments['save'])) {
61
+			// Revert visible <-> excluded
62
+			$excludedFields = array_diff(
63
+				Tca::grid()->getAllFieldNames(),
64
+				$arguments['excluded_fields'],
65
+				$this->getExcludedFieldsFromTca()
66
+			);
67
+			$arguments['excluded_fields'] = $excludedFields;
68
+			$this->getModulePreferences()->save($arguments);
69
+		}
70
+
71
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ModulePreferences/WorkResult.html';
72
+		$view = $this->initializeStandaloneView($templateNameAndPath);
73
+
74
+		$view->assign('title', Tca::table($this->getModuleLoader()->getDataType())->getTitle());
75
+
76
+		// Fetch the menu of visible items.
77
+		$menuVisibleItems = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS);
78
+		$view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS, $menuVisibleItems);
79
+
80
+		// Fetch the default number of menu visible items.
81
+		$menuDefaultVisible = $this->getModulePreferences()->get(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT);
82
+		$view->assign(ConfigurablePart::MENU_VISIBLE_ITEMS_DEFAULT, $menuDefaultVisible);
83
+
84
+		// Get the visible columns
85
+		$view->assign('columns', Tca::grid()->getAllFieldNames());
86
+
87
+		return $view->render();
88
+	}
89
+
90
+	/**
91
+	 * @return array
92
+	 */
93
+	protected function getExcludedFieldsFromTca()
94
+	{
95
+		$tca = Tca::grid()->getTca();
96
+		$excludedFields = [];
97
+		if (!empty($tca['excluded_fields'])) {
98
+			$excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], true);
99
+		} elseif (!empty($tca['export']['excluded_fields'])) { // only for export for legacy reason.
100
+			$excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], true);
101
+		}
102
+		return $excludedFields;
103
+	}
104
+
105
+	/**
106
+	 * Tell whether the tools should be displayed according to the context.
107
+	 *
108
+	 * @return bool
109
+	 */
110
+	public function isShown()
111
+	{
112
+		return $this->getBackendUser()->isAdmin();
113
+	}
114
+
115
+	/**
116
+	 * Get the Vidi Module Loader.
117
+	 *
118
+	 * @return ModuleLoader|object
119
+	 */
120
+	protected function getModuleLoader()
121
+	{
122
+		return GeneralUtility::makeInstance(ModuleLoader::class);
123
+	}
124
+
125
+	/**
126
+	 * @return ModulePreferences|object
127
+	 */
128
+	protected function getModulePreferences()
129
+	{
130
+		return GeneralUtility::makeInstance(ModulePreferences::class);
131
+	}
132
+
133
+	/**
134
+	 * Get the Vidi Module Loader.
135
+	 *
136
+	 * @return GridAnalyserService|object
137
+	 */
138
+	protected function getGridAnalyserService()
139
+	{
140
+		return GeneralUtility::makeInstance(GridAnalyserService::class);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
Classes/Tool/ToolRegistry.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -18,173 +18,173 @@
 block discarded – undo
18 18
  */
19 19
 class ToolRegistry implements SingletonInterface
20 20
 {
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $tools = [];
25
-
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $overriddenPermissions = [];
30
-
31
-    /**
32
-     * Returns a class instance.
33
-     *
34
-     * @return \Fab\Vidi\Tool\ToolRegistry|object
35
-     */
36
-    public static function getInstance()
37
-    {
38
-        return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class);
39
-    }
40
-
41
-    /**
42
-     * Register a tool for a data type.
43
-     *
44
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
45
-     * @param string $toolName class name which must implement "ToolInterface".
46
-     * @return $this
47
-     */
48
-    public function register($dataType, $toolName)
49
-    {
50
-        if (!isset($this->tools[$dataType])) {
51
-            $this->tools[$dataType] = [];
52
-        }
53
-
54
-        $this->tools[$dataType][] = $toolName;
55
-        return $this;
56
-    }
57
-
58
-    /**
59
-     * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions.
60
-     *
61
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
62
-     * @param string $toolName class name which must implement "ToolInterface".
63
-     * @param $permission
64
-     * @return $this
65
-     */
66
-    public function overridePermission($dataType, $toolName, Closure $permission)
67
-    {
68
-        if (empty($this->overriddenPermissions[$dataType])) {
69
-            $this->overriddenPermissions[$dataType] = [];
70
-        }
71
-
72
-        $this->overriddenPermissions[$dataType][$toolName] = $permission;
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * Un-Register a tool for a given data type.
78
-     *
79
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
80
-     * @param string $toolName class name which must implement "ToolInterface".
81
-     * @return $this
82
-     */
83
-    public function unRegister($dataType, $toolName)
84
-    {
85
-        if ($this->hasTools($dataType, $toolName)) {
86
-            $toolPosition = array_search($toolName, $this->tools['*']);
87
-            if ($toolPosition !== false) {
88
-                unset($this->tools['*'][$toolPosition]);
89
-            }
90
-
91
-            $toolPosition = array_search($toolName, $this->tools[$dataType]);
92
-            if ($toolPosition !== false) {
93
-                unset($this->tools[$dataType][$toolPosition]);
94
-            }
95
-        }
96
-
97
-        return $this;
98
-    }
99
-
100
-    /**
101
-     * Tell whether the given data type has any tools registered.
102
-     *
103
-     * @param string $dataType
104
-     * @return bool
105
-     */
106
-    public function hasAnyTools($dataType)
107
-    {
108
-        $tools = $this->getTools($dataType);
109
-        return !empty($tools);
110
-    }
111
-
112
-    /**
113
-     * Tell whether the given data type has this $tool.
114
-     *
115
-     * @param string $dataType
116
-     * @param string $tool
117
-     * @return bool
118
-     */
119
-    public function hasTools($dataType, $tool)
120
-    {
121
-        return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]);
122
-    }
123
-
124
-    /**
125
-     * Tell whether the given tool is allowed for this data type.
126
-     *
127
-     * @param string $dataType
128
-     * @param string $toolName
129
-     * @return bool
130
-     */
131
-    public function isAllowed($dataType, $toolName)
132
-    {
133
-        $isAllowed = false;
134
-
135
-        if ($this->hasTools($dataType, $toolName)) {
136
-            $permission = $this->getOverriddenPermission($dataType, $toolName);
137
-            if (!is_null($permission)) {
138
-                $isAllowed = $permission();
139
-            } else {
140
-                /** @var ToolInterface $toolName */
141
-                $toolName = GeneralUtility::makeInstance($toolName);
142
-                $isAllowed = $toolName->isShown();
143
-            }
144
-        }
145
-        return $isAllowed;
146
-    }
147
-
148
-    /**
149
-     * Get Registered tools.
150
-     *
151
-     * @param string $dataType
152
-     * @return ToolInterface[]
153
-     */
154
-    public function getTools($dataType)
155
-    {
156
-        $tools = [];
157
-
158
-        foreach (array($dataType, '*') as $toolSource) {
159
-            if (isset($this->tools[$toolSource])) {
160
-                $toolNames = $this->tools[$toolSource];
161
-
162
-                foreach ($toolNames as $toolName) {
163
-                    /** @var ToolInterface $tool */
164
-                    if ($this->isAllowed($dataType, $toolName)) {
165
-                        $tools[] = GeneralUtility::makeInstance($toolName);
166
-                    }
167
-                }
168
-            }
169
-        }
170
-        return $tools;
171
-    }
172
-
173
-    /**
174
-     * Get the proper permission for a tool.
175
-     *
176
-     * @param string $dataType corresponds to the table name or can be "*" for all data types.
177
-     * @param string $toolName class name which must implement "ToolInterface".
178
-     * @return null|Closure
179
-     */
180
-    protected function getOverriddenPermission($dataType, $toolName)
181
-    {
182
-        $permission = null;
183
-        if (isset($this->overriddenPermissions[$dataType][$toolName])) {
184
-            $permission = $this->overriddenPermissions[$dataType][$toolName];
185
-        } elseif (isset($this->overriddenPermissions['*'][$toolName])) {
186
-            $permission = $this->overriddenPermissions['*'][$toolName];
187
-        }
188
-        return $permission;
189
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $tools = [];
25
+
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $overriddenPermissions = [];
30
+
31
+	/**
32
+	 * Returns a class instance.
33
+	 *
34
+	 * @return \Fab\Vidi\Tool\ToolRegistry|object
35
+	 */
36
+	public static function getInstance()
37
+	{
38
+		return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class);
39
+	}
40
+
41
+	/**
42
+	 * Register a tool for a data type.
43
+	 *
44
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
45
+	 * @param string $toolName class name which must implement "ToolInterface".
46
+	 * @return $this
47
+	 */
48
+	public function register($dataType, $toolName)
49
+	{
50
+		if (!isset($this->tools[$dataType])) {
51
+			$this->tools[$dataType] = [];
52
+		}
53
+
54
+		$this->tools[$dataType][] = $toolName;
55
+		return $this;
56
+	}
57
+
58
+	/**
59
+	 * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions.
60
+	 *
61
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
62
+	 * @param string $toolName class name which must implement "ToolInterface".
63
+	 * @param $permission
64
+	 * @return $this
65
+	 */
66
+	public function overridePermission($dataType, $toolName, Closure $permission)
67
+	{
68
+		if (empty($this->overriddenPermissions[$dataType])) {
69
+			$this->overriddenPermissions[$dataType] = [];
70
+		}
71
+
72
+		$this->overriddenPermissions[$dataType][$toolName] = $permission;
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * Un-Register a tool for a given data type.
78
+	 *
79
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
80
+	 * @param string $toolName class name which must implement "ToolInterface".
81
+	 * @return $this
82
+	 */
83
+	public function unRegister($dataType, $toolName)
84
+	{
85
+		if ($this->hasTools($dataType, $toolName)) {
86
+			$toolPosition = array_search($toolName, $this->tools['*']);
87
+			if ($toolPosition !== false) {
88
+				unset($this->tools['*'][$toolPosition]);
89
+			}
90
+
91
+			$toolPosition = array_search($toolName, $this->tools[$dataType]);
92
+			if ($toolPosition !== false) {
93
+				unset($this->tools[$dataType][$toolPosition]);
94
+			}
95
+		}
96
+
97
+		return $this;
98
+	}
99
+
100
+	/**
101
+	 * Tell whether the given data type has any tools registered.
102
+	 *
103
+	 * @param string $dataType
104
+	 * @return bool
105
+	 */
106
+	public function hasAnyTools($dataType)
107
+	{
108
+		$tools = $this->getTools($dataType);
109
+		return !empty($tools);
110
+	}
111
+
112
+	/**
113
+	 * Tell whether the given data type has this $tool.
114
+	 *
115
+	 * @param string $dataType
116
+	 * @param string $tool
117
+	 * @return bool
118
+	 */
119
+	public function hasTools($dataType, $tool)
120
+	{
121
+		return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]);
122
+	}
123
+
124
+	/**
125
+	 * Tell whether the given tool is allowed for this data type.
126
+	 *
127
+	 * @param string $dataType
128
+	 * @param string $toolName
129
+	 * @return bool
130
+	 */
131
+	public function isAllowed($dataType, $toolName)
132
+	{
133
+		$isAllowed = false;
134
+
135
+		if ($this->hasTools($dataType, $toolName)) {
136
+			$permission = $this->getOverriddenPermission($dataType, $toolName);
137
+			if (!is_null($permission)) {
138
+				$isAllowed = $permission();
139
+			} else {
140
+				/** @var ToolInterface $toolName */
141
+				$toolName = GeneralUtility::makeInstance($toolName);
142
+				$isAllowed = $toolName->isShown();
143
+			}
144
+		}
145
+		return $isAllowed;
146
+	}
147
+
148
+	/**
149
+	 * Get Registered tools.
150
+	 *
151
+	 * @param string $dataType
152
+	 * @return ToolInterface[]
153
+	 */
154
+	public function getTools($dataType)
155
+	{
156
+		$tools = [];
157
+
158
+		foreach (array($dataType, '*') as $toolSource) {
159
+			if (isset($this->tools[$toolSource])) {
160
+				$toolNames = $this->tools[$toolSource];
161
+
162
+				foreach ($toolNames as $toolName) {
163
+					/** @var ToolInterface $tool */
164
+					if ($this->isAllowed($dataType, $toolName)) {
165
+						$tools[] = GeneralUtility::makeInstance($toolName);
166
+					}
167
+				}
168
+			}
169
+		}
170
+		return $tools;
171
+	}
172
+
173
+	/**
174
+	 * Get the proper permission for a tool.
175
+	 *
176
+	 * @param string $dataType corresponds to the table name or can be "*" for all data types.
177
+	 * @param string $toolName class name which must implement "ToolInterface".
178
+	 * @return null|Closure
179
+	 */
180
+	protected function getOverriddenPermission($dataType, $toolName)
181
+	{
182
+		$permission = null;
183
+		if (isset($this->overriddenPermissions[$dataType][$toolName])) {
184
+			$permission = $this->overriddenPermissions[$dataType][$toolName];
185
+		} elseif (isset($this->overriddenPermissions['*'][$toolName])) {
186
+			$permission = $this->overriddenPermissions['*'][$toolName];
187
+		}
188
+		return $permission;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
Classes/Tool/ConfiguredPidTool.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,76 +19,76 @@
 block discarded – undo
19 19
  */
20 20
 class ConfiguredPidTool extends AbstractTool
21 21
 {
22
-    /**
23
-     * Display the title of the tool on the welcome screen.
24
-     *
25
-     * @return string
26
-     */
27
-    public function getTitle(): string
28
-    {
29
-        return sprintf(
30
-            '%s (%s)',
31
-            LocalizationUtility::translate('tool.configured_pid', 'vidi'),
32
-            $this->getModulePidService()->getConfiguredNewRecordPid()
33
-        );
34
-    }
22
+	/**
23
+	 * Display the title of the tool on the welcome screen.
24
+	 *
25
+	 * @return string
26
+	 */
27
+	public function getTitle(): string
28
+	{
29
+		return sprintf(
30
+			'%s (%s)',
31
+			LocalizationUtility::translate('tool.configured_pid', 'vidi'),
32
+			$this->getModulePidService()->getConfiguredNewRecordPid()
33
+		);
34
+	}
35 35
 
36
-    /**
37
-     * Display the description of the tool in the welcome screen.
38
-     *
39
-     * @return string
40
-     */
41
-    public function getDescription(): string
42
-    {
43
-        $templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html';
44
-        $view = $this->initializeStandaloneView($templateNameAndPath);
45
-        $view->assignMultiple([
46
-            'sitePath' => Environment::getPublicPath() . '/',
47
-            'dataType' => $this->getModuleLoader()->getDataType(),
48
-            'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(),
49
-            'errors' => $this->getModulePidService()->validateConfiguredPid(),
50
-        ]);
36
+	/**
37
+	 * Display the description of the tool in the welcome screen.
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function getDescription(): string
42
+	{
43
+		$templateNameAndPath = 'EXT:vidi/Resources/Private/Standalone/Tool/ConfiguredPid/Launcher.html';
44
+		$view = $this->initializeStandaloneView($templateNameAndPath);
45
+		$view->assignMultiple([
46
+			'sitePath' => Environment::getPublicPath() . '/',
47
+			'dataType' => $this->getModuleLoader()->getDataType(),
48
+			'configuredPid' => $this->getModulePidService()->getConfiguredNewRecordPid(),
49
+			'errors' => $this->getModulePidService()->validateConfiguredPid(),
50
+		]);
51 51
 
52
-        return $view->render();
53
-    }
52
+		return $view->render();
53
+	}
54 54
 
55
-    /**
56
-     * Do the job
57
-     *
58
-     * @param array $arguments
59
-     * @return string
60
-     */
61
-    public function work(array $arguments = array()): string
62
-    {
63
-        return '';
64
-    }
55
+	/**
56
+	 * Do the job
57
+	 *
58
+	 * @param array $arguments
59
+	 * @return string
60
+	 */
61
+	public function work(array $arguments = array()): string
62
+	{
63
+		return '';
64
+	}
65 65
 
66
-    /**
67
-     * Tell whether the tools should be displayed according to the context.
68
-     *
69
-     * @return bool
70
-     */
71
-    public function isShown(): bool
72
-    {
73
-        return $this->getBackendUser()->isAdmin();
74
-    }
66
+	/**
67
+	 * Tell whether the tools should be displayed according to the context.
68
+	 *
69
+	 * @return bool
70
+	 */
71
+	public function isShown(): bool
72
+	{
73
+		return $this->getBackendUser()->isAdmin();
74
+	}
75 75
 
76
-    /**
77
-     * Get the Vidi Module Loader.
78
-     *
79
-     * @return ModuleLoader|object
80
-     */
81
-    protected function getModuleLoader(): ModuleLoader
82
-    {
83
-        return GeneralUtility::makeInstance(ModuleLoader::class);
84
-    }
76
+	/**
77
+	 * Get the Vidi Module Loader.
78
+	 *
79
+	 * @return ModuleLoader|object
80
+	 */
81
+	protected function getModuleLoader(): ModuleLoader
82
+	{
83
+		return GeneralUtility::makeInstance(ModuleLoader::class);
84
+	}
85 85
 
86
-    /**
87
-     * @return ModulePidService|object
88
-     */
89
-    public function getModulePidService()
90
-    {
91
-        /** @var ModulePidService $modulePidService */
92
-        return GeneralUtility::makeInstance(ModulePidService::class);
93
-    }
86
+	/**
87
+	 * @return ModulePidService|object
88
+	 */
89
+	public function getModulePidService()
90
+	{
91
+		/** @var ModulePidService $modulePidService */
92
+		return GeneralUtility::makeInstance(ModulePidService::class);
93
+	}
94 94
 }
Please login to merge, or discard this patch.
Classes/Module/ModulePidService.php 1 patch
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -21,212 +21,212 @@
 block discarded – undo
21 21
  */
22 22
 class ModulePidService
23 23
 {
24
-    /**
25
-     * The data type (table)
26
-     *
27
-     * @var string
28
-     */
29
-    protected $dataType = '';
30
-
31
-    /**
32
-     * A collection of speaking error messages why the pid is invalid.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $errors = [];
37
-
38
-    /**
39
-     * ModulePidService constructor.
40
-     */
41
-    public function __construct()
42
-    {
43
-        $this->dataType = $this->getModuleLoader()->getDataType();
44
-    }
45
-
46
-    /**
47
-     * Returns a class instance
48
-     *
49
-     * @return \Fab\Vidi\Module\ModulePidService|object
50
-     */
51
-    public static function getInstance()
52
-    {
53
-        return GeneralUtility::makeInstance(self::class);
54
-    }
55
-
56
-    /**
57
-     * @return bool
58
-     */
59
-    public function isConfiguredPidValid(): bool
60
-    {
61
-        $errors = $this->validateConfiguredPid();
62
-        return empty($errors);
63
-    }
64
-
65
-    /**
66
-     * @return array
67
-     */
68
-    public function validateConfiguredPid(): array
69
-    {
70
-        $configuredPid = $this->getConfiguredNewRecordPid();
71
-        $this->validateRootLevel($configuredPid);
72
-        $this->validatePageExist($configuredPid);
73
-        $this->validateDoktype($configuredPid);
74
-        return $this->errors;
75
-    }
76
-
77
-    /**
78
-     * Return the default configured pid.
79
-     *
80
-     * @return int
81
-     */
82
-    public function getConfiguredNewRecordPid(): int
83
-    {
84
-        if (GeneralUtility::_GP(Parameter::PID)) {
85
-            $configuredPid = (int)GeneralUtility::_GP(Parameter::PID);
86
-        } else {
87
-            // Get pid from User TSConfig if any.
88
-            $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType);
89
-            $result = $this->getBackendUser()->getTSConfig($tsConfigPath);
90
-            $configuredPid = isset($result['value'])
91
-                ? $configuredPid = (int)$result['value']
92
-                : $this->getModuleLoader()->getDefaultPid();
93
-        }
94
-
95
-        return $configuredPid;
96
-    }
97
-
98
-    /**
99
-     * Check if pid is 0 and given table is allowed on root level.
100
-     *
101
-     * @param int $configuredPid
102
-     * @return void
103
-     */
104
-    protected function validateRootLevel(int $configuredPid): void
105
-    {
106
-        if ($configuredPid > 0) {
107
-            return;
108
-        }
109
-
110
-        $isRootLevel = (bool)Tca::table()->get('rootLevel');
111
-        if (!$isRootLevel) {
112
-            $this->errors[] = sprintf(
113
-                'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;',
114
-                $this->dataType
115
-            );
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Check if a page exists for the configured pid
121
-     *
122
-     * @param int $configuredPid
123
-     * @return void
124
-     */
125
-    protected function validatePageExist(int $configuredPid): void
126
-    {
127
-        if ($configuredPid === 0) {
128
-            return;
129
-        }
130
-
131
-        $page = $this->getPage($configuredPid);
132
-        if (empty($page)) {
133
-            $this->errors[] = sprintf(
134
-                'No page found for the configured page id "%s".',
135
-                $configuredPid
136
-            );
137
-        }
138
-    }
139
-
140
-    /**
141
-     * Check if configured page is a sysfolder and if it is allowed.
142
-     *
143
-     * @param int $configuredPid
144
-     * @return void
145
-     */
146
-    protected function validateDoktype(int $configuredPid): void
147
-    {
148
-        if ($configuredPid === 0) {
149
-            return;
150
-        }
151
-
152
-        $page = $this->getPage($configuredPid);
153
-        if (!empty($page)
154
-            && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER
155
-            && !$this->isTableAllowedOnStandardPages()
156
-            && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) {
157
-            $this->errors[] = sprintf(
158
-                'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.',
159
-                $configuredPid,
160
-                $this->dataType
161
-            );
162
-        }
163
-    }
164
-
165
-    /**
166
-     * Check if given table is allowed on standard pages
167
-     *
168
-     * @return bool
169
-     * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages()
170
-     */
171
-    protected function isTableAllowedOnStandardPages(): bool
172
-    {
173
-        $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']);
174
-        return in_array($this->dataType, $allowedTables, true);
175
-    }
176
-
177
-    /**
178
-     * Returns the page record of the configured pid
179
-     *
180
-     * @param int $configuredPid
181
-     * @return array
182
-     */
183
-    protected function getPage(int $configuredPid): ?array
184
-    {
185
-        $query = $this->getQueryBuilder('pages');
186
-        $query->getRestrictions()->removeAll(); // we are in BE context.
187
-
188
-        $page = $query->select('doktype')
189
-            ->from('pages')
190
-            ->where(
191
-                'deleted = 0',
192
-                'uid = ' . $configuredPid
193
-            )
194
-            ->execute()
195
-            ->fetch();
196
-
197
-        return is_array($page)
198
-            ? $page
199
-            : [];
200
-    }
201
-
202
-    /**
203
-     * @param string $tableName
204
-     * @return object|QueryBuilder
205
-     */
206
-    protected function getQueryBuilder($tableName): QueryBuilder
207
-    {
208
-        /** @var ConnectionPool $connectionPool */
209
-        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
210
-        return $connectionPool->getQueryBuilderForTable($tableName);
211
-    }
212
-
213
-    /**
214
-     * Returns an instance of the current Backend User.
215
-     *
216
-     * @return BackendUserAuthentication
217
-     */
218
-    protected function getBackendUser()
219
-    {
220
-        return $GLOBALS['BE_USER'];
221
-    }
222
-
223
-    /**
224
-     * Get the Vidi Module Loader.
225
-     *
226
-     * @return ModuleLoader|object
227
-     */
228
-    protected function getModuleLoader()
229
-    {
230
-        return GeneralUtility::makeInstance(ModuleLoader::class);
231
-    }
24
+	/**
25
+	 * The data type (table)
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $dataType = '';
30
+
31
+	/**
32
+	 * A collection of speaking error messages why the pid is invalid.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $errors = [];
37
+
38
+	/**
39
+	 * ModulePidService constructor.
40
+	 */
41
+	public function __construct()
42
+	{
43
+		$this->dataType = $this->getModuleLoader()->getDataType();
44
+	}
45
+
46
+	/**
47
+	 * Returns a class instance
48
+	 *
49
+	 * @return \Fab\Vidi\Module\ModulePidService|object
50
+	 */
51
+	public static function getInstance()
52
+	{
53
+		return GeneralUtility::makeInstance(self::class);
54
+	}
55
+
56
+	/**
57
+	 * @return bool
58
+	 */
59
+	public function isConfiguredPidValid(): bool
60
+	{
61
+		$errors = $this->validateConfiguredPid();
62
+		return empty($errors);
63
+	}
64
+
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function validateConfiguredPid(): array
69
+	{
70
+		$configuredPid = $this->getConfiguredNewRecordPid();
71
+		$this->validateRootLevel($configuredPid);
72
+		$this->validatePageExist($configuredPid);
73
+		$this->validateDoktype($configuredPid);
74
+		return $this->errors;
75
+	}
76
+
77
+	/**
78
+	 * Return the default configured pid.
79
+	 *
80
+	 * @return int
81
+	 */
82
+	public function getConfiguredNewRecordPid(): int
83
+	{
84
+		if (GeneralUtility::_GP(Parameter::PID)) {
85
+			$configuredPid = (int)GeneralUtility::_GP(Parameter::PID);
86
+		} else {
87
+			// Get pid from User TSConfig if any.
88
+			$tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType);
89
+			$result = $this->getBackendUser()->getTSConfig($tsConfigPath);
90
+			$configuredPid = isset($result['value'])
91
+				? $configuredPid = (int)$result['value']
92
+				: $this->getModuleLoader()->getDefaultPid();
93
+		}
94
+
95
+		return $configuredPid;
96
+	}
97
+
98
+	/**
99
+	 * Check if pid is 0 and given table is allowed on root level.
100
+	 *
101
+	 * @param int $configuredPid
102
+	 * @return void
103
+	 */
104
+	protected function validateRootLevel(int $configuredPid): void
105
+	{
106
+		if ($configuredPid > 0) {
107
+			return;
108
+		}
109
+
110
+		$isRootLevel = (bool)Tca::table()->get('rootLevel');
111
+		if (!$isRootLevel) {
112
+			$this->errors[] = sprintf(
113
+				'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;',
114
+				$this->dataType
115
+			);
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Check if a page exists for the configured pid
121
+	 *
122
+	 * @param int $configuredPid
123
+	 * @return void
124
+	 */
125
+	protected function validatePageExist(int $configuredPid): void
126
+	{
127
+		if ($configuredPid === 0) {
128
+			return;
129
+		}
130
+
131
+		$page = $this->getPage($configuredPid);
132
+		if (empty($page)) {
133
+			$this->errors[] = sprintf(
134
+				'No page found for the configured page id "%s".',
135
+				$configuredPid
136
+			);
137
+		}
138
+	}
139
+
140
+	/**
141
+	 * Check if configured page is a sysfolder and if it is allowed.
142
+	 *
143
+	 * @param int $configuredPid
144
+	 * @return void
145
+	 */
146
+	protected function validateDoktype(int $configuredPid): void
147
+	{
148
+		if ($configuredPid === 0) {
149
+			return;
150
+		}
151
+
152
+		$page = $this->getPage($configuredPid);
153
+		if (!empty($page)
154
+			&& (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER
155
+			&& !$this->isTableAllowedOnStandardPages()
156
+			&& $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) {
157
+			$this->errors[] = sprintf(
158
+				'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.',
159
+				$configuredPid,
160
+				$this->dataType
161
+			);
162
+		}
163
+	}
164
+
165
+	/**
166
+	 * Check if given table is allowed on standard pages
167
+	 *
168
+	 * @return bool
169
+	 * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages()
170
+	 */
171
+	protected function isTableAllowedOnStandardPages(): bool
172
+	{
173
+		$allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']);
174
+		return in_array($this->dataType, $allowedTables, true);
175
+	}
176
+
177
+	/**
178
+	 * Returns the page record of the configured pid
179
+	 *
180
+	 * @param int $configuredPid
181
+	 * @return array
182
+	 */
183
+	protected function getPage(int $configuredPid): ?array
184
+	{
185
+		$query = $this->getQueryBuilder('pages');
186
+		$query->getRestrictions()->removeAll(); // we are in BE context.
187
+
188
+		$page = $query->select('doktype')
189
+			->from('pages')
190
+			->where(
191
+				'deleted = 0',
192
+				'uid = ' . $configuredPid
193
+			)
194
+			->execute()
195
+			->fetch();
196
+
197
+		return is_array($page)
198
+			? $page
199
+			: [];
200
+	}
201
+
202
+	/**
203
+	 * @param string $tableName
204
+	 * @return object|QueryBuilder
205
+	 */
206
+	protected function getQueryBuilder($tableName): QueryBuilder
207
+	{
208
+		/** @var ConnectionPool $connectionPool */
209
+		$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
210
+		return $connectionPool->getQueryBuilderForTable($tableName);
211
+	}
212
+
213
+	/**
214
+	 * Returns an instance of the current Backend User.
215
+	 *
216
+	 * @return BackendUserAuthentication
217
+	 */
218
+	protected function getBackendUser()
219
+	{
220
+		return $GLOBALS['BE_USER'];
221
+	}
222
+
223
+	/**
224
+	 * Get the Vidi Module Loader.
225
+	 *
226
+	 * @return ModuleLoader|object
227
+	 */
228
+	protected function getModuleLoader()
229
+	{
230
+		return GeneralUtility::makeInstance(ModuleLoader::class);
231
+	}
232 232
 }
Please login to merge, or discard this patch.
Classes/Module/ModulePreferences.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -18,216 +18,216 @@
 block discarded – undo
18 18
  */
19 19
 class ModulePreferences implements SingletonInterface
20 20
 {
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $preferences;
25
-
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $tableName = 'tx_vidi_preference';
30
-
31
-    /**
32
-     * @param string $key
33
-     * @param string $dataType
34
-     * @return mixed
35
-     */
36
-    public function get($key, $dataType = '')
37
-    {
38
-        if (empty($dataType)) {
39
-            $dataType = $this->getModuleLoader()->getDataType();
40
-        }
41
-
42
-        if (!$this->isLoaded($dataType)) {
43
-            $this->load($dataType);
44
-        }
45
-
46
-        $value = empty($this->preferences[$dataType][$key]) ? null : $this->preferences[$dataType][$key];
47
-        return $value;
48
-    }
49
-
50
-    /**
51
-     * Tell whether the module is loaded.
52
-     *
53
-     * @param string $dataType
54
-     * @return bool
55
-     */
56
-    public function isLoaded($dataType)
57
-    {
58
-        return !empty($this->preferences[$dataType]);
59
-    }
60
-
61
-    /**
62
-     * @param string $dataType
63
-     * @return array
64
-     */
65
-    public function getAll($dataType = '')
66
-    {
67
-        if (empty($dataType)) {
68
-            $dataType = $this->getModuleLoader()->getDataType();
69
-        }
70
-        $this->load($dataType);
71
-        return $this->preferences[$dataType];
72
-    }
73
-
74
-    /**
75
-     * Get the md5 signature of the preferences.
76
-     *
77
-     * @param string $dataType
78
-     * @return bool
79
-     */
80
-    public function getSignature($dataType = '')
81
-    {
82
-        $preferences = $this->getAll($dataType);
83
-        return md5(serialize($preferences));
84
-    }
85
-
86
-    /**
87
-     * Load preferences.
88
-     *
89
-     * @param string $dataType
90
-     * @return void
91
-     */
92
-    public function load($dataType)
93
-    {
94
-        // Fetch preferences from different sources and overlay them
95
-        $databasePreferences = $this->fetchPreferencesFromDatabase($dataType);
96
-        $generalPreferences = $this->fetchGlobalPreferencesFromTypoScript();
97
-        $specificPreferences = $this->fetchExtraPreferencesFromTypoScript($dataType);
98
-
99
-        $preferences = array_merge($generalPreferences, $specificPreferences, $databasePreferences);
100
-        $this->preferences[$dataType] = $preferences;
101
-    }
102
-
103
-    /**
104
-     * Save preferences
105
-     *
106
-     * @param array $preferences
107
-     * @return void
108
-     */
109
-    public function save($preferences)
110
-    {
111
-        $configurableParts = ConfigurablePart::getParts();
112
-
113
-        $dataType = $this->getModuleLoader()->getDataType();
114
-        $this->getDataService()->delete(
115
-            $this->tableName,
116
-            [
117
-                'data_type' => $dataType
118
-            ]
119
-        );
120
-
121
-        $sanitizedPreferences = [];
122
-        foreach ($preferences as $key => $value) {
123
-            if (in_array($key, $configurableParts)) {
124
-                $sanitizedPreferences[$key] = $value;
125
-            }
126
-        }
127
-
128
-        $this->getDataService()->insert(
129
-            $this->tableName,
130
-            [
131
-                'data_type' => $dataType,
132
-                'preferences' => serialize($sanitizedPreferences),
133
-            ]
134
-        );
135
-    }
136
-
137
-    /**
138
-     * @param $dataType
139
-     * @return array
140
-     */
141
-    public function fetchPreferencesFromDatabase($dataType)
142
-    {
143
-        $preferences = [];
144
-        $record = $this->getDataService()->getRecord(
145
-            $this->tableName,
146
-            [
147
-                'data_type' => $dataType
148
-            ]
149
-        );
150
-
151
-        if (!empty($record)) {
152
-            $preferences = unserialize($record['preferences']);
153
-        }
154
-
155
-        return $preferences;
156
-    }
157
-
158
-    /**
159
-     * Returns the module settings.
160
-     *
161
-     * @return array
162
-     */
163
-    protected function fetchGlobalPreferencesFromTypoScript()
164
-    {
165
-        $settings = $this->getSettings();
166
-
167
-        $configurableParts = ConfigurablePart::getParts();
168
-        $preferences = [];
169
-        foreach ($settings as $key => $value) {
170
-            if (in_array($key, $configurableParts)) {
171
-                $preferences[$key] = $value;
172
-            }
173
-        }
174
-
175
-        return $preferences;
176
-    }
177
-
178
-    /**
179
-     * Returns the module settings.
180
-     *
181
-     * @param string $dataType
182
-     * @return array
183
-     */
184
-    protected function fetchExtraPreferencesFromTypoScript($dataType)
185
-    {
186
-        $generalSettings = $this->getSettings();
187
-
188
-        $preferences = [];
189
-        if (isset($generalSettings[$dataType . '.'])) {
190
-            $settings = $generalSettings[$dataType . '.'];
191
-
192
-            $configurableParts = ConfigurablePart::getParts();
193
-            foreach ($settings as $key => $value) {
194
-                if (in_array($key, $configurableParts)) {
195
-                    $preferences[$key] = $value;
196
-                }
197
-            }
198
-        }
199
-
200
-        return $preferences;
201
-    }
202
-
203
-    /**
204
-     * Returns the module settings.
205
-     *
206
-     * @return array
207
-     */
208
-    protected function getSettings()
209
-    {
210
-        /** @var BackendConfigurationManager $backendConfigurationManager */
211
-        $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
212
-        $configuration = $backendConfigurationManager->getTypoScriptSetup();
213
-        return $configuration['module.']['tx_vidi.']['settings.'];
214
-    }
215
-
216
-    /**
217
-     * @return object|DataService
218
-     */
219
-    protected function getDataService(): DataService
220
-    {
221
-        return GeneralUtility::makeInstance(DataService::class);
222
-    }
223
-
224
-    /**
225
-     * Get the Vidi Module Loader.
226
-     *
227
-     * @return ModuleLoader|object
228
-     */
229
-    protected function getModuleLoader()
230
-    {
231
-        return GeneralUtility::makeInstance(ModuleLoader::class);
232
-    }
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $preferences;
25
+
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $tableName = 'tx_vidi_preference';
30
+
31
+	/**
32
+	 * @param string $key
33
+	 * @param string $dataType
34
+	 * @return mixed
35
+	 */
36
+	public function get($key, $dataType = '')
37
+	{
38
+		if (empty($dataType)) {
39
+			$dataType = $this->getModuleLoader()->getDataType();
40
+		}
41
+
42
+		if (!$this->isLoaded($dataType)) {
43
+			$this->load($dataType);
44
+		}
45
+
46
+		$value = empty($this->preferences[$dataType][$key]) ? null : $this->preferences[$dataType][$key];
47
+		return $value;
48
+	}
49
+
50
+	/**
51
+	 * Tell whether the module is loaded.
52
+	 *
53
+	 * @param string $dataType
54
+	 * @return bool
55
+	 */
56
+	public function isLoaded($dataType)
57
+	{
58
+		return !empty($this->preferences[$dataType]);
59
+	}
60
+
61
+	/**
62
+	 * @param string $dataType
63
+	 * @return array
64
+	 */
65
+	public function getAll($dataType = '')
66
+	{
67
+		if (empty($dataType)) {
68
+			$dataType = $this->getModuleLoader()->getDataType();
69
+		}
70
+		$this->load($dataType);
71
+		return $this->preferences[$dataType];
72
+	}
73
+
74
+	/**
75
+	 * Get the md5 signature of the preferences.
76
+	 *
77
+	 * @param string $dataType
78
+	 * @return bool
79
+	 */
80
+	public function getSignature($dataType = '')
81
+	{
82
+		$preferences = $this->getAll($dataType);
83
+		return md5(serialize($preferences));
84
+	}
85
+
86
+	/**
87
+	 * Load preferences.
88
+	 *
89
+	 * @param string $dataType
90
+	 * @return void
91
+	 */
92
+	public function load($dataType)
93
+	{
94
+		// Fetch preferences from different sources and overlay them
95
+		$databasePreferences = $this->fetchPreferencesFromDatabase($dataType);
96
+		$generalPreferences = $this->fetchGlobalPreferencesFromTypoScript();
97
+		$specificPreferences = $this->fetchExtraPreferencesFromTypoScript($dataType);
98
+
99
+		$preferences = array_merge($generalPreferences, $specificPreferences, $databasePreferences);
100
+		$this->preferences[$dataType] = $preferences;
101
+	}
102
+
103
+	/**
104
+	 * Save preferences
105
+	 *
106
+	 * @param array $preferences
107
+	 * @return void
108
+	 */
109
+	public function save($preferences)
110
+	{
111
+		$configurableParts = ConfigurablePart::getParts();
112
+
113
+		$dataType = $this->getModuleLoader()->getDataType();
114
+		$this->getDataService()->delete(
115
+			$this->tableName,
116
+			[
117
+				'data_type' => $dataType
118
+			]
119
+		);
120
+
121
+		$sanitizedPreferences = [];
122
+		foreach ($preferences as $key => $value) {
123
+			if (in_array($key, $configurableParts)) {
124
+				$sanitizedPreferences[$key] = $value;
125
+			}
126
+		}
127
+
128
+		$this->getDataService()->insert(
129
+			$this->tableName,
130
+			[
131
+				'data_type' => $dataType,
132
+				'preferences' => serialize($sanitizedPreferences),
133
+			]
134
+		);
135
+	}
136
+
137
+	/**
138
+	 * @param $dataType
139
+	 * @return array
140
+	 */
141
+	public function fetchPreferencesFromDatabase($dataType)
142
+	{
143
+		$preferences = [];
144
+		$record = $this->getDataService()->getRecord(
145
+			$this->tableName,
146
+			[
147
+				'data_type' => $dataType
148
+			]
149
+		);
150
+
151
+		if (!empty($record)) {
152
+			$preferences = unserialize($record['preferences']);
153
+		}
154
+
155
+		return $preferences;
156
+	}
157
+
158
+	/**
159
+	 * Returns the module settings.
160
+	 *
161
+	 * @return array
162
+	 */
163
+	protected function fetchGlobalPreferencesFromTypoScript()
164
+	{
165
+		$settings = $this->getSettings();
166
+
167
+		$configurableParts = ConfigurablePart::getParts();
168
+		$preferences = [];
169
+		foreach ($settings as $key => $value) {
170
+			if (in_array($key, $configurableParts)) {
171
+				$preferences[$key] = $value;
172
+			}
173
+		}
174
+
175
+		return $preferences;
176
+	}
177
+
178
+	/**
179
+	 * Returns the module settings.
180
+	 *
181
+	 * @param string $dataType
182
+	 * @return array
183
+	 */
184
+	protected function fetchExtraPreferencesFromTypoScript($dataType)
185
+	{
186
+		$generalSettings = $this->getSettings();
187
+
188
+		$preferences = [];
189
+		if (isset($generalSettings[$dataType . '.'])) {
190
+			$settings = $generalSettings[$dataType . '.'];
191
+
192
+			$configurableParts = ConfigurablePart::getParts();
193
+			foreach ($settings as $key => $value) {
194
+				if (in_array($key, $configurableParts)) {
195
+					$preferences[$key] = $value;
196
+				}
197
+			}
198
+		}
199
+
200
+		return $preferences;
201
+	}
202
+
203
+	/**
204
+	 * Returns the module settings.
205
+	 *
206
+	 * @return array
207
+	 */
208
+	protected function getSettings()
209
+	{
210
+		/** @var BackendConfigurationManager $backendConfigurationManager */
211
+		$backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class);
212
+		$configuration = $backendConfigurationManager->getTypoScriptSetup();
213
+		return $configuration['module.']['tx_vidi.']['settings.'];
214
+	}
215
+
216
+	/**
217
+	 * @return object|DataService
218
+	 */
219
+	protected function getDataService(): DataService
220
+	{
221
+		return GeneralUtility::makeInstance(DataService::class);
222
+	}
223
+
224
+	/**
225
+	 * Get the Vidi Module Loader.
226
+	 *
227
+	 * @return ModuleLoader|object
228
+	 */
229
+	protected function getModuleLoader()
230
+	{
231
+		return GeneralUtility::makeInstance(ModuleLoader::class);
232
+	}
233 233
 }
Please login to merge, or discard this patch.
Classes/Module/Access.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  */
17 17
 class Access extends Enumeration
18 18
 {
19
-    public const USER = 'user,group';
19
+	public const USER = 'user,group';
20 20
 
21
-    public const ADMIN = 'admin';
21
+	public const ADMIN = 'admin';
22 22
 }
Please login to merge, or discard this patch.
Classes/Module/Parameter.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@
 block discarded – undo
16 16
  */
17 17
 class Parameter extends Enumeration
18 18
 {
19
-    public const PID = 'id';
19
+	public const PID = 'id';
20 20
 
21
-    public const SUBMODULE = 'vidiModuleCode';
21
+	public const SUBMODULE = 'vidiModuleCode';
22 22
 
23
-    public const MODULE = 'route';
23
+	public const MODULE = 'route';
24 24
 }
Please login to merge, or discard this patch.
Classes/Module/ModuleName.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@
 block discarded – undo
16 16
  */
17 17
 class ModuleName extends Enumeration
18 18
 {
19
-    public const WEB = 'web';
19
+	public const WEB = 'web';
20 20
 
21
-    public const FILE = 'file';
21
+	public const FILE = 'file';
22 22
 
23
-    public const USER = 'user';
23
+	public const USER = 'user';
24 24
 
25
-    public const ADMIN = 'admin';
25
+	public const ADMIN = 'admin';
26 26
 
27
-    public const SYSTEM = 'system';
27
+	public const SYSTEM = 'system';
28 28
 }
Please login to merge, or discard this patch.