Airship\Cabin\Bridge\Blueprint\CustomPages::getCustomDirChildren PHP Method

getCustomDirChildren() public method

Recursively grab the children of the custom directory tree
public getCustomDirChildren ( string $cabin, integer $directoryId, integer $selected, integer $skip, integer $depth ) : array
$cabin string Cabin
$directoryId integer Parent directory for which to list directories
$selected integer Which directory is selected by default?
$skip integer Which directory to skip when recusring (for moving and deleting)
$depth integer
return array
    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;
    }