src/snac/server/database/SQL.php
/**
     * Most recent version by status
     *
     * Helper function to return the most recent status version for a given ic_id. If the status is anything
     * except deleted, then the version number must be greater than any existing deleted version. If the
     * deleted version is greater, then whatever status we were asked for was deleted.
     *
     * This can deal with situations where a record was deleted, then undeleted, but never published after
     * undelete. There is no current published for that record.
     *
     * v1:published
     * v2:deleted
     * v3:undelete
     * v4:locked editing
     *
     * @param integer $mainID id value matching version_history.id.
     *
     * @param string $status Constellation status we need
     *
     * @return integer Version number from version_history.version, as is our convention.
     *
     */
Most recent version by status
Helper function to return the most recent status version for a given ic_id. If the status is anything
except deleted, then the version number must be greater than any existing deleted version. If the
deleted version is greater, then whatever status we were asked for was deleted.

This can deal with situations where a record was deleted, then undeleted, but never published after
undelete. There is no current published for that record.

published
v2:deleted
v3:undelete
v4:locked editing

@param integer $mainID id value matching version_history.id.

@param string $status Constellation status we need

@return integer Version number from version_history.version, as is our convention.
Most recent version by status Helper function to return the most recent status version for a given ic_id . If the status is anything except deleted then the version number must be greater than any existing deleted version . If the deleted version is greater then whatever status we were asked for was deleted . This can deal with situations where a record was deleted then undeleted but never published after undelete . There is no current published for that record . published v2 : deleted v3 : undelete v4 : locked editing @param integer $mainID id value matching version_history . id . @param string $status Constellation status we need @return integer Version number from version_history . version as is our convention .
public function selectCurrentVersionByStatus($mainID, $status)
    {
        $deletedVersion = null;
        if ($status != $this->deleted)
        {
            $deletedVersion = $this->selectCurrentVersionByStatus($mainID, $this->deleted);
        }
        $result = $this->sdb->query(
            'select max(version) as version
            from version_history
            where
            version_history.id=$1 and status=$2',
            array($mainID, $status));
        $row = $this->sdb->fetchrow($result);
        $version = $row['version'];
        if ($version && (! $deletedVersion || $version > $deletedVersion))
        {
            return $version;
        }
        return false;
    }
public function selectCurrentVersionByStatus ( $ mainID , $ status ) { $ deletedVersion = null ; if ( $ status != $ this -> deleted ) { $ deletedVersion = $ this -> selectCurrentVersionByStatus ( $ mainID , $ this -> deleted ) ; } $ result = $ this -> sdb -> query ( 'select max(version) as version
            from version_history
            where
            version_history.id=$1 and status=$2' , array ( $ mainID , $ status ) ) ; $ row = $ this -> sdb -> fetchrow ( $ result ) ; $ version = $ row [ 'version' ] ; if ( $ version && ( ! $ deletedVersion || $ version > $ deletedVersion ) ) { return $ version ; } return false ; }
Most recent version by status
 Helper function to return the most recent status version for a given ic_id.
Most recent version by status Helper function to return the most recent status version for a given ic_id .
/*
             * We need to know the version of a deleted constellation. If the most recent version is deleted,
             * we return false.
             *
             * In other words, we only return a version number if the most recent version is not deleted. The
             * tricky bit is that we are constrained by status, so we might not have been asked to return the
             * most recent version (absolute) but the most recent version with a given status. This is what
             * happens when we are asked for the most recent published version, and the absolute most recent
             * is locked editing.
             *
             * This is fine, and exactly what we planned for. A search of published sees the most recent
             * published, if the constellation has not been deleted more recently.
             *
             * This points up a wrinkle in our current implementation where all versions are in the same
             * table. We have to check for more recent deleted (and eventually embargo) because there are
             * multiple copies of the records. While copying data to edit and publish tables seems clumsy, it
             * may be a simpler and more efficient implementation than we are current using.
             */