src/snac/server/database/DBUtil.php
/**
     * Populate one source object
     *
     * This adds a single source to Constellation or SCM. The calling code will loop for Constellation,
     * possibly adding multple Sources to the Constellation.
     *
     * Select a source from the database based on Source id (not constellation id), create a source object and
     * add it to the passed in $cObj. $cObj can be either a Constellation or SCM. This function is called in a
     * loop for Constellation, but only called once for SCM. For the Constellation-loop call see
     * populateSourceConstellation().
     *
     * Note that Constellation will have a list (array) of Source via addSource(), but SNACControlMetadata
     * only has a single Source via setCitation(). The code below checks the get_class() of $cObj to know
     * which method to call.
     *
     * Constellation version aka version_history.id is always the "newest". If only SCM changed, then
     * constellation version would be the same as the SCM version. Thus we should use $vhInfo['verion'].
     *
     * If something else changed, then the Constellation version is newer than the SCM version, and we
     * should still use the constellation version (because always use the newest version available).
     *
     * Note that source is first-order data, especially as viewed by the Constellation. However, these
     * first-order sources may also be "linked" by some SCMs, when an SCM has a citation.
     *
     * apr 4 remove             $newObj->setType($this->populateTerm($rec['type_id']));
     *
     * @param integer[] $vhInfo associative list with keys 'version', 'ic_id'.
     *
     * @param object $cObj Either a \snac\data\Constellation Constellation object, or a
     * \snac\data\SNACControlMetadata object. (In PHP all objects are passed by reference as is the default in
     * php for objects as parameters, and changed in place.)
     *
     * @param integer $sourceID Source record id. This is a source.id value, and is different than foreign
     * keys in some other uses of $fkID in other functions.
     */
Populate one source object
This adds a single source to Constellation or SCM. The calling code will loop for Constellation,
possibly adding multple Sources to the Constellation.

Select a source from the database based on Source id (not constellation id), create a source object and
add it to the passed in $cObj. $cObj can be either a Constellation or SCM. This function is called in a
loop for Constellation, but only called once for SCM. For the Constellation-loop call see
populateSourceConstellation().

Note that Constellation will have a list (array) of Source via addSource(), but SNACControlMetadata
only has a single Source via setCitation(). The code below checks the get_class() of $cObj to know
which method to call.

Constellation version aka version_history.id is always the "newest". If only SCM changed, then
constellation version would be the same as the SCM version. Thus we should use $vhInfo['verion'].

If something else changed, then the Constellation version is newer than the SCM version, and we
should still use the constellation version (because always use the newest version available).

Note that source is first-order data, especially as viewed by the Constellation. However, these
first-order sources may also be "linked" by some SCMs, when an SCM has a citation.

apr 4 remove             $newObj->setType($this->populateTerm($rec['type_id'])).

@param integer[] $vhInfo associative list with keys 'version', 'ic_id'.



@param integer $sourceID Source record id. This is a source.id value, and is different than foreign
keys in some other uses of $fkID in other functions.
Populate one source object This adds a single source to Constellation or SCM . The calling code will loop for Constellation possibly adding multple Sources to the Constellation . Select a source from the database based on Source id ( not constellation id ) create a source object and add it to the passed in $cObj . $cObj can be either a Constellation or SCM . This function is called in a loop for Constellation but only called once for SCM . For the Constellation - loop call see populateSourceConstellation () . Note that Constellation will have a list ( array ) of Source via addSource () but SNACControlMetadata only has a single Source via setCitation () . The code below checks the get_class () of $cObj to know which method to call . Constellation version aka version_history . id is always the " newest " . If only SCM changed then constellation version would be the same as the SCM version . Thus we should use $vhInfo [ ' verion ' ] . If something else changed then the Constellation version is newer than the SCM version and we should still use the constellation version ( because always use the newest version available ) . Note that source is first - order data especially as viewed by the Constellation . However these first - order sources may also be " linked " by some SCMs when an SCM has a citation . apr 4 remove $newObj - > setType ( $this - > populateTerm ( $rec [ ' type_id ' ] )) . @param integer [] $vhInfo associative list with keys ' version ' ' ic_id ' . @param integer $sourceID Source record id . This is a source . id value and is different than foreign keys in some other uses of $fkID in other functions .
private function populateSourceByID($vhInfo, $cObj, $sourceID)
    {
        $tableName = 'source';
        $rows = $this->sql->selectSourceByID($sourceID, $vhInfo['version']);
        foreach ($rows as $rec)
        {
            $newObj = new \snac\data\Source();
            $newObj->setText($rec['text']);
            $newObj->setCitation($rec['citation']);
            $newObj->setNote($rec['note']);
            $newObj->setURI($rec['uri']);
            $newObj->setDBInfo($rec['version'], $rec['id']);
            $type = null;
            $types = $this->searchVocabulary("source_type", "simple");
            if (count($types) == 1) {
                $type = $types[0];
            }
            $newObj->setType($type);
            $this->populateMeta($vhInfo, $newObj, $tableName);
            $this->populateLanguage($vhInfo, $newObj, $rec['id'], $tableName);
            $class = get_class($cObj);
            if ($class == 'snac\data\Constellation')
            {
                $cObj->addSource($newObj);
            }
            else if ($class == 'snac\data\SNACControlMetadata')
            {
                $cObj->setCitation($newObj);
                break;
            }
            else
            {
                $msg = sprintf("Cannot add Source to class: %s\n", $class);
                $this->logDebug($msg);
                throw new \snac\exceptions\SNACDatabaseException($msg);
            }
        }
    }
private function populateSourceByID ( $ vhInfo , $ cObj , $ sourceID ) { $ tableName = 'source' ; $ rows = $ this -> sql -> selectSourceByID ( $ sourceID , $ vhInfo [ 'version' ] ) ; foreach ( $ rows as $ rec ) { $ newObj = new \ snac \ data \ Source ( ) ; $ newObj -> setText ( $ rec [ 'text' ] ) ; $ newObj -> setCitation ( $ rec [ 'citation' ] ) ; $ newObj -> setNote ( $ rec [ 'note' ] ) ; $ newObj -> setURI ( $ rec [ 'uri' ] ) ; $ newObj -> setDBInfo ( $ rec [ 'version' ] , $ rec [ 'id' ] ) ; $ type = null ; $ types = $ this -> searchVocabulary ( " source_type " , " simple " ) ; if ( count ( $ types ) == 1 ) { $ type = $ types [ 0 ] ; } $ newObj -> setType ( $ type ) ; $ this -> populateMeta ( $ vhInfo , $ newObj , $ tableName ) ; $ this -> populateLanguage ( $ vhInfo , $ newObj , $ rec [ 'id' ] , $ tableName ) ; $ class = get_class ( $ cObj ) ; if ( $ class == 'snac\data\Constellation' ) { $ cObj -> addSource ( $ newObj ) ; } else if ( $ class == 'snac\data\SNACControlMetadata' ) { $ cObj -> setCitation ( $ newObj ) ; break ; } else { $ msg = sprintf ( " Cannot add Source to class: %s \n " , $ class ) ; $ this -> logDebug ( $ msg ) ; throw new \ snac \ exceptions \ SNACDatabaseException ( $ msg ) ; } } }
Populate one source object
 This adds a single source to Constellation or SCM.
Populate one source object This adds a single source to Constellation or SCM .
// Constellation version aka version_history.id is always the "newest". See note above. // $newObj->setDisplayName($rec['display_name']); // Set the type to "simple", the default required by Daniel /*
             * setLanguage() is a Language object.
             */ // There is only one Source in the citation, so best that we break now.