baum icon indicating copy to clipboard operation
baum copied to clipboard

getNestedList() scope support will be nice

Open parabol opened this issue 10 years ago • 6 comments

parabol avatar Oct 15 '14 20:10 parabol

:+1:

zek avatar Dec 19 '14 22:12 zek

Is it possible to exclude some element with child nodes from getNestedList() results?

* root
** child
*** child child

When you edit "child" element (see above tree) then you don't want to allow selecting current tree element ("child") and "child child" - it should be allowed to exclude them from select box easily.

Something like:

NavItem::withoutNode($navItem)->getNestedList('name', 'id', '-')

daris avatar Dec 29 '14 08:12 daris

I used:

array_diff_key(NavItem::getNestedList('name', 'id', '-'), $navItem->descendantsAndSelf()->lists('name', 'id'))

Is there a better solution?

daris avatar Dec 29 '14 08:12 daris

+1

janareit avatar Apr 17 '15 09:04 janareit

Something like Category::whereAccountId($account_id)->getNestedList('title') would be greatly appreciated;

+1

xaddict avatar Feb 26 '16 15:02 xaddict

even better:

public static function getScopedNestedList($column, $key = null, $seperator = ' ', $company_logged) {
    $instance = new static;

    $key = $key ?: $instance->getKeyName();
    $depthColumn = $instance->getDepthColumnName();

    $nodes = $instance->where('company_id', $company_logged)
                      ->orderBy('lft', 'asc')
                      ->get()
                      ->toArray();

    foreach ($nodes as $key => $value) {

        $name = str_repeat($seperator, $value['depth']) . $value['name'];
        $array[] = array('id'=>$value['id'], 'name'=>$name, 'depth'=>$value['depth']);

    }

    return $array;
}

rafito avatar Jun 22 '17 15:06 rafito