Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. /**
  2.      * @param array $comments
  3.      */
  4.     public static function see($comments)
  5.     {
  6.         foreach ($comments as $key => $comment) {
  7.             if ($comment['parent_id'] !== null) {
  8.  
  9.                 $comment['child_comments'] = collect(self::$comments)->map(function ($key, $item) use ($comment) {
  10.                     if ($item['id'] === $comment['parent_id']) {
  11.                         return $item;
  12.                     }
  13.                 });
  14.  
  15.                 if (!in_array($comment['id'], self::$ids)) {
  16.                     self::$ids[] = $comment['id'];
  17.                     $comment['level'] = self::$treeLevel;
  18.  
  19.                     self::$treeLevel++;
  20.                     self::$tree[] = $comment;
  21.  
  22.                     CommentRepository::see($comment['child_comments']);
  23.                 }
  24.             } else {
  25.                 if (!in_array($comment['id'], self::$ids)) {
  26.                     self::$ids[] = $comment['id'];
  27.                     $comment['level'] = 0;
  28.                     self::$treeLevel = 1;
  29.                     self::$tree[] = $comment;
  30.                 }
  31.             }
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement