src/Franzose/ClosureTable/Models/Entity.php
protected function siblings($direction = '', $parentId = false, $order = 'asc')
    {
        $parentId = ($parentId === false ? $this->parent_id : $parentId);

        /**
         * @var QueryBuilder $query
         */
        $query = $this->where($this->getParentIdColumn(), '=', $parentId);

        $column = $this->getPositionColumn();

        switch ($direction) {
            case static::QUERY_ALL:
                $query->where($column, '<>', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_PREV_ALL:
                $query->where($column, '<', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_PREV_ONE:
                $query->where($column, '=', $this->position - 1);
                break;

            case static::QUERY_NEXT_ALL:
                $query->where($column, '>', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_NEXT_ONE:
                $query->where($column, '=', $this->position + 1);
                break;

            case static::QUERY_NEIGHBORS:
                $query->whereIn($column, [$this->position - 1, $this->position + 1]);
                break;

            case static::QUERY_LAST:
                $query->orderBy($column, 'desc');
                break;
        }

        if (is_int($direction)) {
            $query->where($column, '=', $direction);
        } else if (is_array($direction)) {
            $query->buildWherePosition($this->getPositionColumn(), $direction);
        }

        return $query;
    }
protected function siblings($direction = '', $parentId = false, $order = 'asc')
    {
        $parentId = ($parentId === false ? $this->parent_id : $parentId);

        /**
         * @var QueryBuilder $query
         */
        $query = $this->where($this->getParentIdColumn(), '=', $parentId);

        $column = $this->getPositionColumn();

        switch ($direction) {
            case static::QUERY_ALL:
                $query->where($column, '<>', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_PREV_ALL:
                $query->where($column, '<', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_PREV_ONE:
                $query->where($column, '=', $this->position - 1);
                break;

            case static::QUERY_NEXT_ALL:
                $query->where($column, '>', $this->position)->orderBy($column, $order);
                break;

            case static::QUERY_NEXT_ONE:
                $query->where($column, '=', $this->position + 1);
                break;

            case static::QUERY_NEIGHBORS:
                $query->whereIn($column, [$this->position - 1, $this->position + 1]);
                break;

            case static::QUERY_LAST:
                $query->orderBy($column, 'desc');
                break;
        }

        if (is_int($direction)) {
            $query->where($column, '=', $direction);
        } else if (is_array($direction)) {
            $query->buildWherePosition($this->getPositionColumn(), $direction);
        }

        return $query;
    }
protected function siblings ( $ direction = '' , $ parentId = false , $ order = 'asc' ) { $ parentId = ( $ parentId === false ? $ this -> parent_id : $ parentId ) ; /**
         * @var QueryBuilder $query
         */ $ query = $ this -> where ( $ this -> getParentIdColumn ( ) , '=' , $ parentId ) ; $ column = $ this -> getPositionColumn ( ) ; switch ( $ direction ) { case static :: QUERY_ALL : $ query -> where ( $ column , '<>' , $ this -> position ) -> orderBy ( $ column , $ order ) ; break ; case static :: QUERY_PREV_ALL : $ query -> where ( $ column , '<' , $ this -> position ) -> orderBy ( $ column , $ order ) ; break ; case static :: QUERY_PREV_ONE : $ query -> where ( $ column , '=' , $ this -> position - 1 ) ; break ; case static :: QUERY_NEXT_ALL : $ query -> where ( $ column , '>' , $ this -> position ) -> orderBy ( $ column , $ order ) ; break ; case static :: QUERY_NEXT_ONE : $ query -> where ( $ column , '=' , $ this -> position + 1 ) ; break ; case static :: QUERY_NEIGHBORS : $ query -> whereIn ( $ column , [ $ this -> position - 1 , $ this -> position + 1 ] ) ; break ; case static :: QUERY_LAST : $ query -> orderBy ( $ column , 'desc' ) ; break ; } if ( is_int ( $ direction ) ) { $ query -> where ( $ column , '=' , $ direction ) ; } else if ( is_array ( $ direction ) ) { $ query -> buildWherePosition ( $ this -> getPositionColumn ( ) , $ direction ) ; } return $ query ; }
Builds a part of the siblings query.

@param string|int|array $direction
@param int|bool $parentId
@param string $order
@return QueryBuilder
Builds a part of the siblings query .