Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param array $comments
- */
- public static function see($comments)
- {
- foreach ($comments as $key => $comment) {
- if ($comment['parent_id'] !== null) {
- $comment['child_comments'] = collect(self::$comments)->map(function ($key, $item) use ($comment) {
- if ($item['id'] === $comment['parent_id']) {
- return $item;
- }
- });
- if (!in_array($comment['id'], self::$ids)) {
- self::$ids[] = $comment['id'];
- $comment['level'] = self::$treeLevel;
- self::$treeLevel++;
- self::$tree[] = $comment;
- CommentRepository::see($comment['child_comments']);
- }
- } else {
- if (!in_array($comment['id'], self::$ids)) {
- self::$ids[] = $comment['id'];
- $comment['level'] = 0;
- self::$treeLevel = 1;
- self::$tree[] = $comment;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement