public function getPathFromDirectoryId(int $directoryId, string $cabin = '', array $idsEncountered = []) : array
{
// Let's grab the current row
$row = $this->db->row('SELECT
url,
parent,
cabin
FROM
airship_custom_dir
WHERE
directoryid = ?
AND parent NOT IN ' . $this->db->escapeValueSet($idsEncountered, 'int'), $directoryId);
if (empty($row)) {
// This _shouldn't_ be triggered.
return [];
}
// Did we specify a cabin?
if (!empty($cabin)) {
// Did it match this row's cabin?
if ($row['cabin'] !== $cabin) {
throw new CustomPageNotFoundException(\trk('errors.pages.directory_wrong_cabin', $row['url'], $cabin, $row['cabin']));
}
}
// If we have no parent, just return this row's URL piece. We're done.
if (empty($row['parent'])) {
return [$row['url']];
}
// Prevent infinite loops:
if (\in_array($row['parent'], $idsEncountered)) {
return [$row['url']];
}
// Append the current ID to the encountered IDs list
$idsEncountered[] = $directoryId;
$pieces = $this->getPathFromDirectoryId((int) $row['parent'], $row['cabin'], $idsEncountered);
$pieces[] = $row['url'];
return $pieces;
}