TYPO3 CMS  TYPO3_7-6
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 
20 
25 {
29  protected $dataHandler;
30 
35 
40 
44  protected $dataArray;
45 
49  protected $nestedDataArray;
50 
54  public function getDependencyResolver()
55  {
56  if (!isset($this->dependencyResolver)) {
57  $this->dependencyResolver = GeneralUtility::makeInstance(\TYPO3\CMS\Version\Dependency\DependencyResolver::class);
58  $this->dependencyResolver->setOuterMostParentsRequireReferences(true);
59  $this->dependencyResolver->setWorkspace($this->getWorkspace());
60 
61  $this->dependencyResolver->setEventCallback(
63  $this->getDependencyCallback('createNewDependentElementCallback')
64  );
65 
66  $this->dependencyResolver->setEventCallback(
68  $this->getDependencyCallback('createNewDependentElementChildReferenceCallback')
69  );
70 
71  $this->dependencyResolver->setEventCallback(
73  $this->getDependencyCallback('createNewDependentElementParentReferenceCallback')
74  );
75  }
76 
78  }
79 
87  protected function getDependencyCallback($method, array $targetArguments = [])
88  {
90  \TYPO3\CMS\Version\Dependency\EventCallback::class,
91  $this->getElementEntityProcessor(), $method, $targetArguments
92  );
93  }
94 
100  protected function getElementEntityProcessor()
101  {
102  if (!isset($this->elementEntityProcessor)) {
103  $this->elementEntityProcessor = GeneralUtility::makeInstance(Dependency\ElementEntityProcessor::class);
104  $this->elementEntityProcessor->setWorkspace($this->getWorkspace());
105  }
107  }
108 
114  protected function getWorkspace()
115  {
116  return (int)$GLOBALS['BE_USER']->workspace;
117  }
118 
125  public function process(array $dataArray)
126  {
127  $collection = 0;
128  $this->dataArray = $dataArray;
129  $this->nestedDataArray = [];
130 
131  $outerMostParents = $this->getDependencyResolver()->getOuterMostParents();
132 
133  if (empty($outerMostParents)) {
134  return $this->dataArray;
135  }
136 
137  // For each outer most parent, get all nested child elements:
138  foreach ($outerMostParents as $outerMostParent) {
140  $outerMostParent,
141  ++$collection
142  );
143  }
144 
145  $processedDataArray = $this->finalize($this->dataArray);
146 
147  unset($this->dataArray);
148  unset($this->nestedDataArray);
149 
150  return $processedDataArray;
151  }
152 
160  protected function finalize(array $dataArray)
161  {
162  $processedDataArray = [];
163  foreach ($dataArray as $dataElement) {
164  $dataElementIdentifier = $dataElement['id'];
165  $processedDataArray[] = $dataElement;
166  // Insert children (if any)
167  if (!empty($this->nestedDataArray[$dataElementIdentifier])) {
168  $processedDataArray = array_merge(
169  $processedDataArray,
170  $this->finalize($this->nestedDataArray[$dataElementIdentifier])
171  );
172  unset($this->nestedDataArray[$dataElementIdentifier]);
173  }
174  }
175 
176  return $processedDataArray;
177  }
178 
187  protected function resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier = '', $collectionLevel = 0)
188  {
189  $parentIdentifier = $parent->__toString();
190  $parentIsSet = isset($this->dataArray[$parentIdentifier]);
191 
192  if ($parentIsSet) {
193  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_Collection] = $collection;
194  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionLevel] = $collectionLevel;
195  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionCurrent] = md5($parentIdentifier);
196  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionChildren] = count($parent->getChildren());
197  $nextParentIdentifier = $parentIdentifier;
198  $collectionLevel++;
199  }
200 
201  foreach ($parent->getChildren() as $child) {
203  $child->getElement(),
204  $collection,
205  $nextParentIdentifier,
206  $collectionLevel
207  );
208 
209  $childIdentifier = $child->getElement()->__toString();
210  if (!empty($nextParentIdentifier) && isset($this->dataArray[$childIdentifier])) {
211  // Remove from dataArray, but collect to process later
212  // and add it just next to the accordant parent element
213  $this->dataArray[$childIdentifier][GridDataService::GridColumn_CollectionParent] = md5($nextParentIdentifier);
214  $this->nestedDataArray[$nextParentIdentifier][] = $this->dataArray[$childIdentifier];
215  unset($this->dataArray[$childIdentifier]);
216  }
217  }
218  }
219 }
getDependencyCallback($method, array $targetArguments=[])
resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier='', $collectionLevel=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']