‪TYPO3CMS  10.4
OpenDocumentService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
27 {
31  protected ‪$backendUser;
32 
38  {
39  $this->backendUser = ‪$backendUser ?: ‪$GLOBALS['BE_USER'];
40  }
41 
47  public function ‪getOpenDocuments(): array
48  {
49  $openDocuments = [];
50  $sessionOpenDocuments = $this->backendUser->getModuleData('FormEngine', 'ses');
51 
52  if ($sessionOpenDocuments !== null) {
53  $openDocuments = $sessionOpenDocuments[0];
54  }
55 
56  return $openDocuments;
57  }
58 
64  public function ‪getRecentDocuments(): array
65  {
66  return $this->backendUser->getModuleData('opendocs::recent') ?: [];
67  }
68 
74  public function ‪closeDocument(string $identifier): void
75  {
76  $openDocuments = $this->‪getOpenDocuments();
77 
78  if (!isset($openDocuments[$identifier])) {
79  return;
80  }
81 
82  $document = $openDocuments[$identifier];
83  unset($openDocuments[$identifier]);
84 
85  $this->‪storeOpenDocuments($openDocuments);
86  $this->‪addToRecentDocuments($identifier, $document);
87  }
88 
92  public function ‪closeAllDocuments(): void
93  {
94  $openDocuments = $this->‪getOpenDocuments();
95  $this->‪storeOpenDocuments([]);
96  foreach ($openDocuments as $identifier => $document) {
97  $this->‪addToRecentDocuments($identifier, $document);
98  }
99  }
100 
106  protected function ‪storeOpenDocuments(array $openDocuments): void
107  {
108  [, $lastOpenDocumentIdentifier] = $this->backendUser->getModuleData('FormEngine', 'ses');
109  $this->backendUser->pushModuleData('FormEngine', [$openDocuments, $lastOpenDocumentIdentifier]);
110  }
111 
118  protected function ‪addToRecentDocuments(string $identifier, array $document): void
119  {
120  $recentDocuments = $this->‪getRecentDocuments();
121  $recentDocuments = array_merge(
122  [$identifier => $document],
123  $recentDocuments
124  );
125 
126  // Allow a maximum of 8 recent documents
127  if (count($recentDocuments) > 8) {
128  $recentDocuments = array_slice($recentDocuments, 0, 8);
129  }
130 
131  $this->backendUser->pushModuleData('opendocs::recent', $recentDocuments);
132  }
133 }
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\__construct
‪__construct(BackendUserAuthentication $backendUser=null)
Definition: OpenDocumentService.php:36
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\closeAllDocuments
‪closeAllDocuments()
Definition: OpenDocumentService.php:91
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\addToRecentDocuments
‪addToRecentDocuments(string $identifier, array $document)
Definition: OpenDocumentService.php:117
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getRecentDocuments
‪array getRecentDocuments()
Definition: OpenDocumentService.php:63
‪TYPO3\CMS\Opendocs\Service
Definition: OpenDocumentService.php:18
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:27
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\$backendUser
‪BackendUserAuthentication $backendUser
Definition: OpenDocumentService.php:30
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\storeOpenDocuments
‪storeOpenDocuments(array $openDocuments)
Definition: OpenDocumentService.php:105
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\closeDocument
‪closeDocument(string $identifier)
Definition: OpenDocumentService.php:73
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getOpenDocuments
‪array getOpenDocuments()
Definition: OpenDocumentService.php:46