public function getTreeAsFlat($id, $offset = null, $limit = null, $filter = null, $orderFields = 'Name', $orderDirection = 'asc')
{
$query = $this->SQL->from('Category')->where('DisplayAs <>', 'Heading')->where('ParentCategoryID', $id)->limit($limit, $offset)->orderBy($orderFields, $orderDirection);
if ($filter) {
$query->like('Name', $filter);
}
$categoryTree = $query->get()->resultArray();
self::calculateData($categoryTree);
self::joinUserData($categoryTree);
foreach ($categoryTree as &$category) {
// Fix the depth to be relative, not global.
$category['Depth'] = 1;
// We don't have children, but trees are expected to have this key.
$category['Children'] = [];
}
return $categoryTree;
}