TYPO3 CMS  TYPO3_6-2
CollectionService.php
Go to the documentation of this file.
1 <?php
3 
20 
27 
31  protected $dataHandler;
32 
37 
42 
46  protected $dataArray;
47 
51  protected $nestedDataArray;
52 
56  public function getDependencyResolver() {
57  if (!isset($this->dependencyResolver)) {
58  $this->dependencyResolver = GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\Dependency\\DependencyResolver');
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 = array()) {
90  'TYPO3\\CMS\\Version\\Dependency\\EventCallback',
91  $this->getElementEntityProcessor(), $method, $targetArguments
92  );
93  }
94 
100  protected function getElementEntityProcessor() {
101  if (!isset($this->elementEntityProcessor)) {
102  $this->elementEntityProcessor = GeneralUtility::makeInstance(
103  'TYPO3\\CMS\\Version\\Dependency\\ElementEntityProcessor'
104  );
105  $this->elementEntityProcessor->setWorkspace($this->getWorkspace());
106  }
108  }
109 
115  protected function getWorkspace() {
116  return (int)$GLOBALS['BE_USER']->workspace;
117  }
118 
125  public function process(array $dataArray) {
126  $collection = 0;
127  $this->dataArray = $dataArray;
128  $this->nestedDataArray = array();
129 
130  $outerMostParents = $this->getDependencyResolver()->getOuterMostParents();
131 
132  if (empty($outerMostParents)) {
133  return $this->dataArray;
134  }
135 
136  // For each outer most parent, get all nested child elements:
137  foreach ($outerMostParents as $outerMostParent) {
139  $outerMostParent,
140  ++$collection
141  );
142  }
143 
144  $processedDataArray = $this->finalize($this->dataArray);
145 
146  unset($this->dataArray);
147  unset($this->nestedDataArray);
148 
149  return $processedDataArray;
150  }
151 
159  protected function finalize(array $dataArray) {
160  $processedDataArray = array();
161  foreach ($dataArray as $dataElement) {
162  $dataElementIdentifier = $dataElement['id'];
163  $processedDataArray[] = $dataElement;
164  // Insert children (if any)
165  if (!empty($this->nestedDataArray[$dataElementIdentifier])) {
166  $processedDataArray = array_merge(
167  $processedDataArray,
168  $this->finalize($this->nestedDataArray[$dataElementIdentifier])
169  );
170  unset($this->nestedDataArray[$dataElementIdentifier]);
171  }
172  }
173 
174  return $processedDataArray;
175  }
176 
185  protected function resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier = '', $collectionLevel = 0) {
186  $parentIdentifier = $parent->__toString();
187  $parentIsSet = isset($this->dataArray[$parentIdentifier]);
188 
189  if ($parentIsSet) {
190  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_Collection] = $collection;
191  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionLevel] = $collectionLevel;
192  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionCurrent] = md5($parentIdentifier);
193  $this->dataArray[$parentIdentifier][GridDataService::GridColumn_CollectionChildren] = count($parent->getChildren());
194  $nextParentIdentifier = $parentIdentifier;
195  $collectionLevel++;
196  }
197 
198  foreach ($parent->getChildren() as $child) {
200  $child->getElement(),
201  $collection,
202  $nextParentIdentifier,
203  $collectionLevel
204  );
205 
206  $childIdentifier = $child->getElement()->__toString();
207  if (!empty($nextParentIdentifier) && isset($this->dataArray[$childIdentifier])) {
208  // Remove from dataArray, but collect to process later
209  // and add it just next to the accordant parent element
210  $this->dataArray[$childIdentifier][GridDataService::GridColumn_CollectionParent] = md5($nextParentIdentifier);
211  $this->nestedDataArray[$nextParentIdentifier][] = $this->dataArray[$childIdentifier];
212  unset($this->dataArray[$childIdentifier]);
213  }
214  }
215  }
216 
217 }
getDependencyCallback($method, array $targetArguments=array())
resolveDataArrayChildDependencies(Dependency\ElementEntity $parent, $collection, $nextParentIdentifier='', $collectionLevel=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]