src/snac/server/database/DBUtil.php
/**
     * Save a name
     *
     * Once we have AbstractData->$operation implemented, make this method private, and fix DBUtilTest to use
     * setOperation() to update only the name of a constellation. In the meantime, saveName() needs to be public.
     *
     * In the declarative sense "name" is all name data, here a list of name objects, as well as related
     * contributor data, language data, date data.
     *
     * This exists primarily to make the code here in DBUtil more legible.
     *
     * Note about \snac\data\Language objects. This is the Language of the entry. Language object's
     * getLanguage() returns a Term object. Language getScript() returns a Term object for the script. The
     * database only uses the id of each Term.
     *
     * Constellation name entry data is already an array of name entry data.
     * getUseDates() returns SNACDate[] (An array of SNACDate objects.)
     *
     * When saving a name, the database assigns it a new id, and returns that id. We must be sure to use
     * $nameID for related dates, etc.
     *
     * @param integer[] $vhInfo associative list with keys 'version', 'ic_id'.
     *
     * @param \snac\data\NameEntry Name entry object
     *
     */
Save a name
Once we have AbstractData->$operation implemented, make this method private, and fix DBUtilTest to use
setOperation() to update only the name of a constellation. In the meantime, saveName() needs to be public.

In the declarative sense "name" is all name data, here a list of name objects, as well as related
contributor data, language data, date data.

This exists primarily to make the code here in DBUtil more legible.

Note about \snac\data\Language objects. This is the Language of the entry. Language object's
getLanguage() returns a Term object. Language getScript() returns a Term object for the script. The
database only uses the id of each Term.

Constellation name entry data is already an array of name entry data.

When saving a name, the database assigns it a new id, and returns that id. We must be sure to use
$nameID for related dates, etc.

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

@param \snac\data\NameEntry Name entry object
Save a name Once we have AbstractData - > $operation implemented make this method private and fix DBUtilTest to use setOperation () to update only the name of a constellation . In the meantime saveName () needs to be public . In the declarative sense " name " is all name data here a list of name objects as well as related contributor data language data date data . This exists primarily to make the code here in DBUtil more legible . Note about \ snac \ data \ Language objects . This is the Language of the entry . Language object ' s getLanguage () returns a Term object . Language getScript () returns a Term object for the script . The database only uses the id of each Term . Constellation name entry data is already an array of name entry data . When saving a name the database assigns it a new id and returns that id . We must be sure to use $nameID for related dates etc . @param integer [] $vhInfo associative list with keys ' version ' ' ic_id ' . @param \ snac \ data \ NameEntry Name entry object
public function saveName($vhInfo, $cObj)
    {
        foreach ($cObj->getNameEntries() as $ndata)
        {
            $nameID = $ndata->getID();
            if ($this->prepOperation($vhInfo, $ndata))
            {
                $nameID = $this->sql->insertName($vhInfo,
                                                 $ndata->getOriginal(),
                                                 $ndata->getPreferenceScore(),
                                                 $ndata->getID());
                $ndata->setID($nameID);
                $ndata->setVersion($vhInfo['version']);
            }
            $this->saveMeta($vhInfo, $ndata, 'name', $nameID);
            if ($componentList = $ndata->getComponents())
            {
                foreach($componentList as $cp)
                {
                    if ($this->prepOperation($vhInfo, $cp))
                    {
                        $rid = $this->sql->insertComponent($vhInfo,
                                                           $cp->getID(),
                                                           $nameID,
                                                           $cp->getText(),
                                                           $this->termID($cp->getType()),
                                                           $cp->getOrder());
                        $cp->setID($rid);
                        $cp->setVersion($vhInfo['version']);
                    }
                }
            }
            if ($contribList = $ndata->getContributors())
            {
                foreach($contribList as $cb)
                {
                    $rid = $cb->getID();
                    if ($this->prepOperation($vhInfo, $cb))
                    {
                        $rid = $this->sql->insertContributor($vhInfo,
                                                             $cb->getID(),
                                                             $nameID,
                                                             $cb->getName(),
                                                             $this->termID($cb->getType()),
                                                             $this->termID($cb->getRule()));
                        $cb->setID($rid);
                        $cb->setVersion($vhInfo['version']);
                    }
                }
            }
            $this->saveLanguage($vhInfo, $ndata, 'name', $nameID);
            $dateList = $ndata->getDateList();
            foreach ($ndata->getDateList() as $date)
            {
                $this->saveDate($vhInfo, $date, 'name', $nameID);
            }
        }
    }
public function saveName ( $ vhInfo , $ cObj ) { foreach ( $ cObj -> getNameEntries ( ) as $ ndata ) { $ nameID = $ ndata -> getID ( ) ; if ( $ this -> prepOperation ( $ vhInfo , $ ndata ) ) { $ nameID = $ this -> sql -> insertName ( $ vhInfo , $ ndata -> getOriginal ( ) , $ ndata -> getPreferenceScore ( ) , $ ndata -> getID ( ) ) ; $ ndata -> setID ( $ nameID ) ; $ ndata -> setVersion ( $ vhInfo [ 'version' ] ) ; } $ this -> saveMeta ( $ vhInfo , $ ndata , 'name' , $ nameID ) ; if ( $ componentList = $ ndata -> getComponents ( ) ) { foreach ( $ componentList as $ cp ) { if ( $ this -> prepOperation ( $ vhInfo , $ cp ) ) { $ rid = $ this -> sql -> insertComponent ( $ vhInfo , $ cp -> getID ( ) , $ nameID , $ cp -> getText ( ) , $ this -> termID ( $ cp -> getType ( ) ) , $ cp -> getOrder ( ) ) ; $ cp -> setID ( $ rid ) ; $ cp -> setVersion ( $ vhInfo [ 'version' ] ) ; } } } if ( $ contribList = $ ndata -> getContributors ( ) ) { foreach ( $ contribList as $ cb ) { $ rid = $ cb -> getID ( ) ; if ( $ this -> prepOperation ( $ vhInfo , $ cb ) ) { $ rid = $ this -> sql -> insertContributor ( $ vhInfo , $ cb -> getID ( ) , $ nameID , $ cb -> getName ( ) , $ this -> termID ( $ cb -> getType ( ) ) , $ this -> termID ( $ cb -> getRule ( ) ) ) ; $ cb -> setID ( $ rid ) ; $ cb -> setVersion ( $ vhInfo [ 'version' ] ) ; } } } $ this -> saveLanguage ( $ vhInfo , $ ndata , 'name' , $ nameID ) ; $ dateList = $ ndata -> getDateList ( ) ; foreach ( $ ndata -> getDateList ( ) as $ date ) { $ this -> saveDate ( $ vhInfo , $ date , 'name' , $ nameID ) ; } } }
Save a name
 Once we have AbstractData->$operation implemented, make this method private, and fix DBUtilTest to use
 setOperation() to update only the name of a constellation.
Save a name Once we have AbstractData - > $operation implemented make this method private and fix DBUtilTest to use setOperation () to update only the name of a constellation .
/*
             * Inline the code that would be saveComponent() because it is only used here.
             */ /*
                 * $ndata->getID() is null for inserted name. $nameID is walways non-null.
                 *
                 * $nameID and $ndata->getID() will be the same for a name that is being updated. getID() will
                 * be null for inserted names since there's no id until after insert. $nameID will always be
                 * non-null.
                 *
                 * Both ids are the record id, not the constellation id.
                 *
                 */ // Why initialize $rid? if(true) $rid will be set and used.