Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need Review & Test] Can create tree with items from different levels #492

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from

Conversation

oh-bala
Copy link

@oh-bala oh-bala commented Jan 12, 2021

Phenomenon

With below data structure, if I use toTree, the items indexed with 2 will be eliminated from the result.

$categories = [
  0 => [ "id" => 10068, "parent_id" => 1, "name" => "A"],
  1 => [ "id" => 10085, "parent_id" => 10068, "name" => "B" ],
  2 => [ "id" => 10081, "parent_id" => null, "name" => "D" ]
]

Solution needs to be reviewed

The conditional statement modified to include the nodes (ROOT) has no parent.

/** @var Model|NodeTrait $node */
foreach ($this->items as $node) {
    if ($node->getParentId() == $root || ! $node->getParentId()) {
       $items[] = $node;
    }
}

@oh-bala
Copy link
Author

oh-bala commented Jan 12, 2021

linked #491

@oh-bala oh-bala changed the title Can create tree with items from different levels [Need Review & Test] Can create tree with items from different levels Jan 13, 2021
@oh-bala
Copy link
Author

oh-bala commented Jan 13, 2021

Please do not merge the PR, found some issue with duplicated items, I will fix and create a new patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant