‪TYPO3CMS  ‪main
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  public function ‪getOpenDocuments(): array
32  {
33  $openDocuments = [];
34  $sessionOpenDocuments = $this->‪getBackendUser()->getModuleData('FormEngine', 'ses');
35 
36  if ($sessionOpenDocuments !== null) {
37  $openDocuments = $sessionOpenDocuments[0];
38  }
39 
40  return $openDocuments;
41  }
42 
46  public function ‪getRecentDocuments(): array
47  {
48  return $this->‪getBackendUser()->getModuleData('opendocs::recent') ?: [];
49  }
50 
56  public function ‪closeDocument(string ‪$identifier): void
57  {
58  $openDocuments = $this->‪getOpenDocuments();
59 
60  if (!isset($openDocuments[‪$identifier])) {
61  return;
62  }
63 
64  $document = $openDocuments[‪$identifier];
65  unset($openDocuments[‪$identifier]);
66 
67  $this->‪storeOpenDocuments($openDocuments);
68  $this->‪addToRecentDocuments($identifier, $document);
69  }
70 
74  public function ‪closeAllDocuments(): void
75  {
76  $openDocuments = $this->‪getOpenDocuments();
77  $this->‪storeOpenDocuments([]);
78  foreach ($openDocuments as ‪$identifier => $document) {
79  $this->‪addToRecentDocuments(‪$identifier, $document);
80  }
81  }
82 
86  protected function ‪storeOpenDocuments(array $openDocuments): void
87  {
88  [, $lastOpenDocumentIdentifier] = $this->‪getBackendUser()->getModuleData('FormEngine', 'ses');
89  $this->‪getBackendUser()->pushModuleData('FormEngine', [$openDocuments, $lastOpenDocumentIdentifier]);
90  }
91 
98  protected function ‪addToRecentDocuments(string ‪$identifier, array $document): void
99  {
100  $recentDocuments = $this->‪getRecentDocuments();
101  $recentDocuments = array_merge(
102  [‪$identifier => $document],
103  $recentDocuments
104  );
105 
106  // Allow a maximum of 8 recent documents
107  if (count($recentDocuments) > 8) {
108  $recentDocuments = array_slice($recentDocuments, 0, 8);
109  }
110 
111  $this->‪getBackendUser()->pushModuleData('opendocs::recent', $recentDocuments);
112  }
113 
115  {
116  return ‪$GLOBALS['BE_USER'];
117  }
118 }
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getRecentDocuments
‪getRecentDocuments()
Definition: OpenDocumentService.php:46
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\closeAllDocuments
‪closeAllDocuments()
Definition: OpenDocumentService.php:74
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\addToRecentDocuments
‪addToRecentDocuments(string $identifier, array $document)
Definition: OpenDocumentService.php:98
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getBackendUser
‪getBackendUser()
Definition: OpenDocumentService.php:114
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getOpenDocuments
‪getOpenDocuments()
Definition: OpenDocumentService.php:31
‪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\storeOpenDocuments
‪storeOpenDocuments(array $openDocuments)
Definition: OpenDocumentService.php:86
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\closeDocument
‪closeDocument(string $identifier)
Definition: OpenDocumentService.php:56
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37