‪TYPO3CMS  9.5
CollectionService.php
Go to the documentation of this file.
1 <?php
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 
21 
26 {
30  protected ‪$dataHandler;
31 
36 
40  protected ‪$dependencyResolver;
41 
45  protected ‪$dataArray;
46 
51 
55  public function ‪getDependencyResolver()
56  {
57  if (!isset($this->dependencyResolver)) {
58  $this->dependencyResolver = GeneralUtility::makeInstance(Dependency\DependencyResolver::class);
59  $this->dependencyResolver->setOuterMostParentsRequireReferences(true);
60  $this->dependencyResolver->setWorkspace($this->‪getWorkspace());
61 
62  $this->dependencyResolver->setEventCallback(
64  $this->‪getDependencyCallback('createNewDependentElementCallback')
65  );
66 
67  $this->dependencyResolver->setEventCallback(
69  $this->‪getDependencyCallback('createNewDependentElementChildReferenceCallback')
70  );
71 
72  $this->dependencyResolver->setEventCallback(
74  $this->‪getDependencyCallback('createNewDependentElementParentReferenceCallback')
75  );
76  }
77 
79  }
80 
88  protected function ‪getDependencyCallback($method, array $targetArguments = [])
89  {
90  return GeneralUtility::makeInstance(
91  Dependency\EventCallback::class,
93  $method,
94  $targetArguments
95  );
96  }
97 
103  protected function ‪getElementEntityProcessor()
104  {
105  if (!isset($this->elementEntityProcessor)) {
106  $this->elementEntityProcessor = GeneralUtility::makeInstance(Dependency\ElementEntityProcessor::class);
107  $this->elementEntityProcessor->setWorkspace($this->‪getWorkspace());
108  }
110  }
111 
117  protected function ‪getWorkspace()
118  {
119  return (int)‪$GLOBALS['BE_USER']->workspace;
120  }
121 
128  public function ‪process(array ‪$dataArray)
129  {
130  $collection = 0;
131  $this->dataArray = ‪$dataArray;
132  $this->nestedDataArray = [];
133 
134  $outerMostParents = $this->‪getDependencyResolver()->‪getOuterMostParents();
135 
136  if (empty($outerMostParents)) {
137  return ‪$this->dataArray;
138  }
139 
140  // For each outer most parent, get all nested child elements:
141  foreach ($outerMostParents as $outerMostParent) {
143  $outerMostParent,
144  ++$collection
145  );
146  }
147 
148  $processedDataArray = $this->‪finalize($this->dataArray);
149 
150  unset($this->dataArray);
151  unset($this->nestedDataArray);
152 
153  return $processedDataArray;
154  }
155 
163  protected function ‪finalize(array ‪$dataArray)
164  {
165  $processedDataArray = [];
166  foreach (‪$dataArray as $dataElement) {
167  $dataElementIdentifier = $dataElement['id'];
168  $processedDataArray[] = $dataElement;
169  // Insert children (if any)
170  if (!empty($this->nestedDataArray[$dataElementIdentifier])) {
171  $processedDataArray = array_merge(
172  $processedDataArray,
173  $this->‪finalize($this->nestedDataArray[$dataElementIdentifier])
174  );
175  unset($this->nestedDataArray[$dataElementIdentifier]);
176  }
177  }
178 
179  return $processedDataArray;
180  }
181 
190  protected function ‪resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier = '', $collectionLevel = 0)
191  {
192  $parentIdentifier = $parent->__toString();
193  $parentIsSet = isset($this->dataArray[$parentIdentifier]);
194 
195  if ($parentIsSet) {
196  $this->dataArray[$parentIdentifier][‪GridDataService::GridColumn_Collection] = $collection;
197  $this->dataArray[$parentIdentifier][‪GridDataService::GridColumn_CollectionLevel] = $collectionLevel;
198  $this->dataArray[$parentIdentifier][‪GridDataService::GridColumn_CollectionCurrent] = md5($parentIdentifier);
199  $this->dataArray[$parentIdentifier][‪GridDataService::GridColumn_CollectionChildren] = count($parent->getChildren());
200  $nextParentIdentifier = $parentIdentifier;
201  $collectionLevel++;
202  }
203 
204  foreach ($parent->getChildren() as $child) {
206  $child->getElement(),
207  $collection,
208  $nextParentIdentifier,
209  $collectionLevel
210  );
211 
212  $childIdentifier = $child->getElement()->__toString();
213  if (!empty($nextParentIdentifier) && isset($this->dataArray[$childIdentifier])) {
214  // Remove from dataArray, but collect to process later
215  // and add it just next to the accordant parent element
216  $this->dataArray[$childIdentifier][‪GridDataService::GridColumn_CollectionParent] = md5($nextParentIdentifier);
217  $this->nestedDataArray[$nextParentIdentifier][] = $this->dataArray[$childIdentifier];
218  unset($this->dataArray[$childIdentifier]);
219  }
220  }
221  }
222 }
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\$dataArray
‪array $dataArray
Definition: CollectionService.php:41
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity
Definition: ElementEntity.php:24
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\$dataHandler
‪TYPO3 CMS Core DataHandling DataHandler $dataHandler
Definition: CollectionService.php:29
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\$nestedDataArray
‪array $nestedDataArray
Definition: CollectionService.php:45
‪TYPO3\CMS\Workspaces\Dependency\DependencyResolver
Definition: DependencyResolver.php:23
‪TYPO3\CMS\Workspaces\Dependency\EventCallback
Definition: EventCallback.php:21
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\EVENT_Construct
‪const EVENT_Construct
Definition: ElementEntity.php:27
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\getElementEntityProcessor
‪Dependency ElementEntityProcessor getElementEntityProcessor()
Definition: CollectionService.php:98
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\getDependencyResolver
‪Dependency DependencyResolver getDependencyResolver()
Definition: CollectionService.php:50
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\getWorkspace
‪int getWorkspace()
Definition: CollectionService.php:112
‪TYPO3\CMS\Workspaces\Service\GridDataService\GridColumn_CollectionCurrent
‪const GridColumn_CollectionCurrent
Definition: GridDataService.php:46
‪TYPO3\CMS\Workspaces\Dependency
Definition: DependencyEntityFactory.php:2
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService
Definition: CollectionService.php:26
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\$elementEntityProcessor
‪Dependency ElementEntityProcessor $elementEntityProcessor
Definition: CollectionService.php:33
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\EVENT_CreateChildReference
‪const EVENT_CreateChildReference
Definition: ElementEntity.php:28
‪TYPO3\CMS\Workspaces\Service\Dependency
Definition: CollectionService.php:2
‪TYPO3\CMS\Workspaces\Service\GridDataService\GridColumn_CollectionLevel
‪const GridColumn_CollectionLevel
Definition: GridDataService.php:44
‪TYPO3\CMS\Workspaces\Dependency\DependencyResolver\getOuterMostParents
‪array ElementEntity[] getOuterMostParents()
Definition: DependencyResolver.php:132
‪TYPO3\CMS\Workspaces\Dependency\ElementEntityProcessor
Definition: ElementEntityProcessor.php:26
‪TYPO3\CMS\Workspaces\Dependency\ElementEntity\EVENT_CreateParentReference
‪const EVENT_CreateParentReference
Definition: ElementEntity.php:29
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\resolveDataArrayChildDependencies
‪resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier='', $collectionLevel=0)
Definition: CollectionService.php:185
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\getDependencyCallback
‪Dependency EventCallback getDependencyCallback($method, array $targetArguments=[])
Definition: CollectionService.php:83
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Workspaces\Service\GridDataService\GridColumn_Collection
‪const GridColumn_Collection
Definition: GridDataService.php:43
‪TYPO3\CMS\Workspaces\Service\GridDataService\GridColumn_CollectionParent
‪const GridColumn_CollectionParent
Definition: GridDataService.php:45
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\process
‪array process(array $dataArray)
Definition: CollectionService.php:123
‪TYPO3\CMS\Workspaces\Service\GridDataService\GridColumn_CollectionChildren
‪const GridColumn_CollectionChildren
Definition: GridDataService.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\finalize
‪array finalize(array $dataArray)
Definition: CollectionService.php:158
‪TYPO3\CMS\Workspaces\Service\Dependency\CollectionService\$dependencyResolver
‪Dependency DependencyResolver $dependencyResolver
Definition: CollectionService.php:37
‪TYPO3\CMS\Workspaces\Service\GridDataService
Definition: GridDataService.php:35