Comment::children PHP Method

children() public method

Return children comments, if applicable
public children ( ) : CommentArray
return CommentArray
    public function children()
    {
        $field = $this->getField();
        $comments = $this->getPage()->get($field->name);
        $children = $comments->makeNew();
        $children->setPage($this->getPage());
        $children->setField($field);
        $id = $this->id;
        foreach ($comments as $comment) {
            if (!$comment->parent_id) {
                continue;
            }
            if ($comment->parent_id == $id) {
                $children->add($comment);
            }
        }
        return $children;
    }

Usage Example

コード例 #1
0
 /**
  * Walk the tree and register comments in the corresponding collections.
  *
  * @param   array    $nodes
  * @param   Comment  $parent
  */
 protected function walk(&$nodes, $parent = null)
 {
     $collection = $parent instanceof Comment ? $parent->children() : $this;
     foreach ($nodes as $entry) {
         $node = $entry['node'];
         $children =& $entry['children'];
         $node->parent($parent);
         $collection->set($node->id(), $node);
         if (!empty($children)) {
             $this->walk($children, $node);
         }
     }
 }