Changyan_Synchronizer::insertComments PHP Method

insertComments() private method

get comment information object generated by changyan server
private insertComments ( $cmts, $postID ) : integer
$cmts object of a node of the comment page array file
$postID id of the post which the comments reply to
return integer Array of comments array
    private function insertComments($cmts, $postID)
    {
        global $zbp;
        $commentsArray = array();
        foreach ($cmts as $cmt) {
            foreach ($cmt->comments as $aComment) {
                $commentsArray[] = $aComment;
            }
        }
        $commentsArray = array_reverse($commentsArray);
        $comments = array();
        $commentscy = array();
        foreach ($commentsArray as &$aComment) {
            if (count($aComment->comments) > 3) {
                continue;
            }
            $aComment->create_time = (int) substr($aComment->create_time, 0, -3);
            $comments[$aComment->comment_id] = $aComment;
            $commentscy[$aComment->comment_id] = $aComment;
        }
        foreach ($comments as $aComment) {
            $cmt = $this->findCommentInDB($aComment, $postID);
            if ($cmt->ID == 0) {
                //echo $cmt->ID;
                if (isset($aComment->comments[0])) {
                    if (isset($commentscy[$aComment->comments[0]->comment_id])) {
                        if (isset($commentscy[$aComment->comments[0]->comment_id]->ID)) {
                            $cmt->ParentID = $commentscy[$aComment->comments[0]->comment_id]->ID;
                        }
                    }
                } else {
                    $cmt->ParentID = 0;
                }
                $cmt->RootID = Comment::GetRootID($cmt->ParentID);
                $cmt->Save();
                $commentscy[$aComment->comment_id] = $cmt;
                $zbp->comments[$aComment->comment_id] = $cmt;
            } else {
                $commentscy[$aComment->comment_id] = $cmt;
            }
            unset($cmt);
        }
        $commentLastID = 0;
        foreach ($commentscy as $aComment) {
            if (isset($aComment->ID)) {
                if ($aComment->ID > $commentLastID) {
                    $commentLastID = $aComment->ID;
                }
            }
        }
        return $commentLastID;
    }