src/Post/PostRepository.php
public function getIndexForNumber($discussionId, $number, User $actor = null)
    {
        $query = Discussion::find($discussionId)
            ->posts()
            ->whereVisibleTo($actor)
            ->where('created_at', '<', function ($query) use ($discussionId, $number) {
                $query->select('created_at')
                      ->from('posts')
                      ->where('discussion_id', $discussionId)
                      ->whereNotNull('number')
                      ->take(1)

                      // We don't add $number as a binding because for some
                      // reason doing so makes the bindings go out of order.
                      ->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')');
            });

        return $query->count();
    }
public function getIndexForNumber($discussionId, $number, User $actor = null)
    {
        $query = Discussion::find($discussionId)
            ->posts()
            ->whereVisibleTo($actor)
            ->where('created_at', '<', function ($query) use ($discussionId, $number) {
                $query->select('created_at')
                      ->from('posts')
                      ->where('discussion_id', $discussionId)
                      ->whereNotNull('number')
                      ->take(1)

                      // We don't add $number as a binding because for some
                      // reason doing so makes the bindings go out of order.
                      ->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')');
            });

        return $query->count();
    }
public function getIndexForNumber ( $ discussionId , $ number , User $ actor = null ) { $ query = Discussion :: find ( $ discussionId ) -> posts ( ) -> whereVisibleTo ( $ actor ) -> where ( 'created_at' , '<' , function ( $ query ) use ( $ discussionId , $ number ) { $ query -> select ( 'created_at' ) -> from ( 'posts' ) -> where ( 'discussion_id' , $ discussionId ) -> whereNotNull ( 'number' ) -> take ( 1 ) // We don't add $number as a binding because for some // reason doing so makes the bindings go out of order. -> orderByRaw ( 'ABS(CAST(number AS SIGNED) - ' . ( int ) $ number . ')' ) ; } ) ; return $ query -> count ( ) ; }
Get the position within a discussion where a post with a certain number
is. If the post with that number does not exist, the index of the
closest post to it will be returned.

@param int $discussionId
@param int $number
@param \Flarum\User\User|null $actor
@return int
Get the position within a discussion where a post with a certain number is . If the post with that number does not exist the index of the closest post to it will be returned .