src/snac/server/database/DBUtil.php
/**
     * Save Relation aka  ConstellationRelation
     *
     * This is cpfRelation aka a relation to a constellation (as opposed to a relation to archival material).
     *
     * "ConstellationRelation" has had many names: cpfRelation relation,
     * related_identity. We're attempting to make that more consistent, although the class is
     * ConstellationRelation and the SQL table is related_identity.
     *
     * ignored: we know our own id value: sourceConstellation, // id fk
     * ignored: we know our own ark: sourceArkID,  // ark why are we repeating this?
     * ignored: always 'simple', altType, cpfRelation@xlink:type vocab source_type, .type
     *
     * | placeholder | php                 | what                                                       | sql               |
     * |-------------+---------------------+------------------------------------------------------------+-------------------|
     * |           1 | $vhInfo['version']  |                                                            | version           |
     * |           2 | $vhInfo['ic_id']  |                                                            | ic_id           |
     * |           3 | targetConstellation | id fk to version_history                                   | .related_id       |
     * |           4 | targetArkID         | ark                                                        | .related_ark      |
     * |           5 | targetEntityType    | cpfRelation@xlink:role, vocab entity_type, Term object     | .role             |
     * |           6 | type                | cpfRelation@xlink:arcrole vocab relation_type, Term object | .arcrole          |
     * |           7 | cpfRelationType     | AnF only, so far                                           | .relation_type    |
     * |           8 | content             | cpfRelation/relationEntry, usually a name                  | .relation_entry   |
     * |           9 | dates               | cpfRelation/date (or dateRange)                            | .date             |
     * |          10 | note                | cpfRelation/descriptiveNote                                | .descriptive_note |
     *
     * New convention: when there are dates, make them the second arg. Final arg is a list of all the
     * scalar values that will eventually be passed to execute() in the SQL function. This convention
     * is already in use in a couple of places, but needs to be done for some existing functions.
     *
     * Ignore ConstellationRelation->$altType. It was always "simple".
     *
     * altType is cpfRelationType, at least in the CPF.
     *
     * Don't save the source info, because we are the source and have already saved the source data as
     * part of ourself.
     *
     * getRelations() returns \snac\data\ConstellationRelation[]
     * $fdata is \snac\data\ConstellationRelation
     *
     * @param integer[] $vhInfo list with keys version, ic_id.
     *
     * @param $cObj \snac\data\Constellation object
     */
Save Relation aka  ConstellationRelation
This is cpfRelation aka a relation to a constellation (as opposed to a relation to archival material).

"ConstellationRelation" has had many names: cpfRelation relation,
related_identity. We're attempting to make that more consistent, although the class is
ConstellationRelation and the SQL table is related_identity.

we know our own id value: sourceConstellation, // id fk
ignored: we know our own ark: sourceArkID,  // ark why are we repeating this.
ignored: always 'simple', altType, cpfRelation@xlink:type vocab source_type, .type



New convention: when there are dates, make them the second arg. Final arg is a list of all the
scalar values that will eventually be passed to execute() in the SQL function. This convention
is already in use in a couple of places, but needs to be done for some existing functions.



altType is cpfRelationType, at least in the CPF.

Don't save the source info, because we are the source and have already saved the source data as
part of ourself.



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

@param $cObj \snac\data\Constellation object
Save Relation aka ConstellationRelation This is cpfRelation aka a relation to a constellation ( as opposed to a relation to archival material ) . " ConstellationRelation " has had many names : cpfRelation relation related_identity . We ' re attempting to make that more consistent although the class is ConstellationRelation and the SQL table is related_identity . we know our own id value : sourceConstellation // id fk ignored : we know our own ark : sourceArkID // ark why are we repeating this . ignored : always ' simple ' altType cpfRelation@xlink : type vocab source_type . type New convention : when there are dates make them the second arg . Final arg is a list of all the scalar values that will eventually be passed to execute () in the SQL function . This convention is already in use in a couple of places but needs to be done for some existing functions . altType is cpfRelationType at least in the CPF . Don ' t save the source info because we are the source and have already saved the source data as part of ourself . @param integer [] $vhInfo list with keys version ic_id . @param $cObj \ snac \ data \ Constellation object
private function saveRelation($vhInfo, $cObj)
    {
        foreach ($cObj->getRelations() as $fdata)
        {
            $relID = $fdata->getID();
            if ($this->prepOperation($vhInfo, $fdata))
            {
                [$targetArk, $targetEntityType, $content] = [$fdata->getTargetArkID(), $fdata->getTargetEntityType(), $fdata->getContent()];
                if (!isset($targetArk, $targetEntityType, $content) ) {
                    $targetConstellation = $this->readPublishedConstellationByID($fdata->getTargetConstellation(), DBUtil::$READ_NRD|DBUtil::$READ_PREFERRED_NAME);
                    $fdata->setTargetArkID($targetConstellation->getArk());
                    $fdata->setTargetEntityType($targetConstellation->getEntityType());
                    $fdata->setContent($targetConstellation->getPreferredNameEntry()->getOriginal());
                }
                $relID = $this->sql->insertRelation($vhInfo,
                                                    $fdata->getTargetConstellation(),
                                                    $fdata->getTargetArkID(),
                                                    $this->termID($fdata->getTargetEntityType()),
                                                    $this->termID($fdata->getType()),            
                                                    $this->termID($fdata->getcpfRelationType()), 
                                                    $fdata->getContent(),
                                                    $fdata->getNote(),
                                                    $fdata->getID());
                $fdata->setID($relID);
                $fdata->setVersion($vhInfo['version']);
                $fdata->setSourceConstellation($vhInfo['ic_id']);
                $fdata->setSourceArkID($cObj->getArk());
            }
            $this->saveMeta($vhInfo, $fdata, 'related_identity', $relID);
            foreach ($fdata->getDateList() as $date)
            {
                $this->saveDate($vhInfo, $date, 'related_identity', $relID);
            }
        }
    }
private function saveRelation ( $ vhInfo , $ cObj ) { foreach ( $ cObj -> getRelations ( ) as $ fdata ) { $ relID = $ fdata -> getID ( ) ; if ( $ this -> prepOperation ( $ vhInfo , $ fdata ) ) { [ $ targetArk , $ targetEntityType , $ content ] = [ $ fdata -> getTargetArkID ( ) , $ fdata -> getTargetEntityType ( ) , $ fdata -> getContent ( ) ] ; if ( ! isset ( $ targetArk , $ targetEntityType , $ content ) ) { $ targetConstellation = $ this -> readPublishedConstellationByID ( $ fdata -> getTargetConstellation ( ) , DBUtil :: $ READ_NRD | DBUtil :: $ READ_PREFERRED_NAME ) ; $ fdata -> setTargetArkID ( $ targetConstellation -> getArk ( ) ) ; $ fdata -> setTargetEntityType ( $ targetConstellation -> getEntityType ( ) ) ; $ fdata -> setContent ( $ targetConstellation -> getPreferredNameEntry ( ) -> getOriginal ( ) ) ; } $ relID = $ this -> sql -> insertRelation ( $ vhInfo , $ fdata -> getTargetConstellation ( ) , $ fdata -> getTargetArkID ( ) , $ this -> termID ( $ fdata -> getTargetEntityType ( ) ) , $ this -> termID ( $ fdata -> getType ( ) ) , $ this -> termID ( $ fdata -> getcpfRelationType ( ) ) , $ fdata -> getContent ( ) , $ fdata -> getNote ( ) , $ fdata -> getID ( ) ) ; $ fdata -> setID ( $ relID ) ; $ fdata -> setVersion ( $ vhInfo [ 'version' ] ) ; $ fdata -> setSourceConstellation ( $ vhInfo [ 'ic_id' ] ) ; $ fdata -> setSourceArkID ( $ cObj -> getArk ( ) ) ; } $ this -> saveMeta ( $ vhInfo , $ fdata , 'related_identity' , $ relID ) ; foreach ( $ fdata -> getDateList ( ) as $ date ) { $ this -> saveDate ( $ vhInfo , $ date , 'related_identity' , $ relID ) ; } } }
Save Relation aka  ConstellationRelation
 This is cpfRelation aka a relation to a constellation (as opposed to a relation to archival material).
Save Relation aka ConstellationRelation This is cpfRelation aka a relation to a constellation ( as opposed to a relation to archival material ) .
// Check for null relation values, fetch if needed // arcrole // $cpfRelTypeID, // Be nice and fill in the source Constellation