src/Sortable.php
public function getSortValBeforeAll($groupingId = null)
    {
        if ($groupingId === null && $this->grpColumn) {
            throw new SortableException(
                'groupingId may be omitted only when grpColumn is not configured.'
            );
        }

        $query = (new Query())
            ->select([$this->pkColumn, $this->srtColumn])
            ->from($this->targetTable)
            ->where([
                'and',
                $this->grpColumn ? ['=', $this->grpColumn, $groupingId] : [],
                $this->skipRowsClause()
            ])
            ->orderBy([$this->srtColumn => SORT_ASC])
            ->limit(1);

        $result = $query->one($this->db);

        if ($result && $result[$this->srtColumn] == 1) {
            $this->rebuildSortAfter($result[$this->pkColumn], true);
            $sortVal = $this->getIniSortVal();
        }
        else if ($result) {
            $sortVal = ceil($result[$this->srtColumn] / 2);
        }
        else $sortVal = $this->getIniSortVal();

        return (int)$sortVal;
    }
public function getSortValBeforeAll($groupingId = null)
    {
        if ($groupingId === null && $this->grpColumn) {
            throw new SortableException(
                'groupingId may be omitted only when grpColumn is not configured.'
            );
        }

        $query = (new Query())
            ->select([$this->pkColumn, $this->srtColumn])
            ->from($this->targetTable)
            ->where([
                'and',
                $this->grpColumn ? ['=', $this->grpColumn, $groupingId] : [],
                $this->skipRowsClause()
            ])
            ->orderBy([$this->srtColumn => SORT_ASC])
            ->limit(1);

        $result = $query->one($this->db);

        if ($result && $result[$this->srtColumn] == 1) {
            $this->rebuildSortAfter($result[$this->pkColumn], true);
            $sortVal = $this->getIniSortVal();
        }
        else if ($result) {
            $sortVal = ceil($result[$this->srtColumn] / 2);
        }
        else $sortVal = $this->getIniSortVal();

        return (int)$sortVal;
    }
public function getSortValBeforeAll ( $ groupingId = null ) { if ( $ groupingId === null && $ this -> grpColumn ) { throw new SortableException ( 'groupingId may be omitted only when grpColumn is not configured.' ) ; } $ query = ( new Query ( ) ) -> select ( [ $ this -> pkColumn , $ this -> srtColumn ] ) -> from ( $ this -> targetTable ) -> where ( [ 'and' , $ this -> grpColumn ? [ '=' , $ this -> grpColumn , $ groupingId ] : [ ] , $ this -> skipRowsClause ( ) ] ) -> orderBy ( [ $ this -> srtColumn => SORT_ASC ] ) -> limit ( 1 ) ; $ result = $ query -> one ( $ this -> db ) ; if ( $ result && $ result [ $ this -> srtColumn ] == 1 ) { $ this -> rebuildSortAfter ( $ result [ $ this -> pkColumn ] , true ) ; $ sortVal = $ this -> getIniSortVal ( ) ; } else if ( $ result ) { $ sortVal = ceil ( $ result [ $ this -> srtColumn ] / 2 ) ; } else $ sortVal = $ this -> getIniSortVal ( ) ; return ( int ) $ sortVal ; }
Derives a sort value for a record to be inserted before all items.

@param null|int $groupingId
@return int
@throws SortableException
Derives a sort value for a record to be inserted before all items .