public function getCustomDirChildren(string $cabin, int $directoryId = 0, int $selected = 0, int $skip = 0, int $depth = 0) : array
{
$level = [];
if ($directoryId === 0) {
$branches = $this->db->run('SELECT * FROM airship_custom_dir WHERE cabin = ? AND parent IS NULL', $cabin);
if (empty($branches)) {
return [];
}
} else {
$branches = $this->db->run('SELECT * FROM airship_custom_dir WHERE parent = ?', $directoryId);
if (empty($branches)) {
throw new CustomPageNotFoundException(\__('No branches'));
}
}
// Now let's recurse:
foreach ($branches as $br) {
$br['selected'] = $br['directoryid'] === $selected;
try {
if ($skip && $skip === (int) $br['directoryid']) {
continue;
}
$br['children'] = $this->getCustomDirChildren($cabin, (int) $br['directoryid'], $selected, $skip, $depth + 1);
} catch (CustomPageNotFoundException $e) {
$br['children'] = null;
}
$level[] = $br;
}
return $level;
}