public function flattenTree(array &$list = [], array $tree, $prefix = '')
{
$is_root = empty($list);
if (isset($tree['periods'])) {
foreach ($tree['periods'] as $period) {
$this->flattenTree($list, $period, "{$prefix} {$period['name']}");
}
unset($tree['periods']);
}
$tree['name'] = trim($prefix);
$list[] = $tree;
if ($is_root) {
usort($list, function ($a, $b) {
if ($a['duration'] == $b['duration']) {
return 0;
}
return $a['duration'] > $b['duration'] ? -1 : 1;
});
}
}