App\Models\Forum\Topic::postsPosition PHP 메소드

postsPosition() 공개 메소드

public postsPosition ( $sortedPosts )
    public function postsPosition($sortedPosts)
    {
        if ($sortedPosts->count() === 0) {
            return [];
        }
        $firstPostPosition = $this->postPosition($sortedPosts->first()->post_id);
        $postIds = $sortedPosts->map(function ($p) {
            return $p->post_id;
        });
        $buf = [];
        $currentPostPosition = $firstPostPosition;
        foreach ($postIds as $postId) {
            $buf[$postId] = $currentPostPosition;
            $currentPostPosition++;
        }
        return $buf;
    }