Last active
February 10, 2020 11:01
-
-
Save ogrosko/f8154c9295099dc1a9094f282e11ed21 to your computer and use it in GitHub Desktop.
Typo3 page tree flat sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return array | |
*/ | |
public function getSortingMatrix(): array | |
{ | |
$matrix = []; | |
$rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->getUid())->get(); | |
foreach ($rootLine as $level => $item) { | |
$matrix[$level] = $item['sorting']; | |
} | |
return $matrix; | |
} | |
/** | |
* Sort pages based on sorting and accept tree sorting | |
*/ | |
\usort($solutions, function ($a, $b) { | |
$verdict = 0; | |
$aMatrix = $a->getSortingMatrix(); | |
$bMatrix = $b->getSortingMatrix(); | |
foreach ($aMatrix as $level => $sorting) { | |
if ($sorting === $bMatrix[$level]) { | |
continue; | |
} | |
$verdict = $sorting - $bMatrix[$level]; | |
} | |
return $verdict; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment