Back to PhocacartCategory class

Method nestedToUl

public static
nestedToUl
(mixed $data, mixed $currentCatid = 0)

Method nestedToUl - Source code

public static function nestedToUl($data, $currentCatid = 0)
{
    $result = array();
    if (!empty($data) && count($data) > 0) {
        $result[] = '<ul>';
        foreach ($data as $k => $v) {
            $link = Route::_(PhocacartRoute::getCategoryRoute($v['id'], $v['alias']));
            // Current Category is selected
            if ($currentCatid == $v['id']) {
                $result[] = sprintf('<li data-jstree=\'{"opened":true,"selected":true}\' >%s%s</li>', '<a href="' . $link . '">' . $v['title'] . '</a>', self::nestedToUl($v['children'], $currentCatid));
            } else {
                $result[] = sprintf('<li>%s%s</li>', '<a href="' . $link . '">' . $v['title'] . '</a>', self::nestedToUl($v['children'], $currentCatid));
            }
        }
        $result[] = '</ul>';
    }
    return implode("\n", $result);
}