SHARE
TWEET

Untitled

a guest Nov 4th, 2016 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top