‪TYPO3CMS  9.5
OpenDocumentService.php
Go to the documentation of this file.
1 <?php
2 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 
25 {
29  protected ‪$backendUser;
30 
36  {
37  $this->backendUser = ‪$backendUser ?: ‪$GLOBALS['BE_USER'];
38  }
39 
45  public function ‪getOpenDocuments(): array
46  {
47  $openDocuments = [];
48  $sessionOpenDocuments = $this->backendUser->getModuleData('FormEngine', 'ses');
49 
50  if ($sessionOpenDocuments !== null) {
51  $openDocuments = $sessionOpenDocuments[0];
52  }
53 
54  return $openDocuments;
55  }
56 
62  public function ‪getRecentDocuments(): array
63  {
64  return $this->backendUser->getModuleData('opendocs::recent') ?: [];
65  }
66 
72  public function ‪closeDocument(string $identifier): void
73  {
74  $openDocuments = $this->‪getOpenDocuments();
75 
76  if (!isset($openDocuments[$identifier])) {
77  return;
78  }
79 
80  $document = $openDocuments[$identifier];
81  unset($openDocuments[$identifier]);
82 
83  $this->‪storeOpenDocuments($openDocuments);
84  $this->‪addToRecentDocuments($identifier, $document);
85  }
86 
92  protected function ‪storeOpenDocuments(array $openDocuments): void
93  {
94  list(, $lastOpenDocumentIdentifier) = $this->backendUser->getModuleData('FormEngine', 'ses');
95  $this->backendUser->pushModuleData('FormEngine', [$openDocuments, $lastOpenDocumentIdentifier]);
96  }
97 
104  protected function ‪addToRecentDocuments(string $identifier, array $document): void
105  {
106  $recentDocuments = $this->‪getRecentDocuments();
107  $recentDocuments = array_merge(
108  [$identifier => $document],
109  $recentDocuments
110  );
111 
112  // Allow a maximum of 8 recent documents
113  if (count($recentDocuments) > 8) {
114  $recentDocuments = array_slice($recentDocuments, 0, 8);
115  }
116 
117  $this->backendUser->pushModuleData('opendocs::recent', $recentDocuments);
118  }
119 }
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\__construct
‪__construct(BackendUserAuthentication $backendUser=null)
Definition: OpenDocumentService.php:34
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\addToRecentDocuments
‪addToRecentDocuments(string $identifier, array $document)
Definition: OpenDocumentService.php:103
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getRecentDocuments
‪array getRecentDocuments()
Definition: OpenDocumentService.php:61
‪TYPO3\CMS\Opendocs\Service
Definition: OpenDocumentService.php:3
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:25
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\$backendUser
‪BackendUserAuthentication $backendUser
Definition: OpenDocumentService.php:28
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\storeOpenDocuments
‪storeOpenDocuments(array $openDocuments)
Definition: OpenDocumentService.php:91
‪$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:71
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService\getOpenDocuments
‪array getOpenDocuments()
Definition: OpenDocumentService.php:44