src/snac/server/ServerExecutor.php
/**
     * Download/Serialize a Constellation
     *
     * This method handles the downloading of content in any type. Download tasks include serializing a
     * constellation as EAC-CPF XML, and downloading the XML (a string) as a file.
     *
     * @param string[] $input Input array from the Server object
     * @throws \snac\exceptions\SNACInputException
     * @return string[] The response to send to the client
     */
Download/Serialize a Constellation
This method handles the downloading of content in any type. Download tasks include serializing a
constellation as EAC-CPF XML, and downloading the XML (a string) as a file.

@param string[] $input Input array from the Server object
@throws \snac\exceptions\SNACInputException
@return string[] The response to send to the client
Download / Serialize a Constellation This method handles the downloading of content in any type . Download tasks include serializing a constellation as EAC - CPF XML and downloading the XML ( a string ) as a file . @param string [] $input Input array from the Server object @throws \ snac \ exceptions \ SNACInputException @return string [] The response to send to the client
public function downloadConstellation($input) {
        if (!isset($input["type"])) {
            throw new \snac\exceptions\SNACInputException("No download type specified", 400);
        }
        $constellations = $this->readConstellationFromDatabase($input, true);
        if ($constellations == null || count($constellations) > 1) {
            throw new \snac\exceptions\SNACInputException("Constellation does not exist", 404);
        }
        $constellation = $constellations[0];
        $tmp = $this->cStore->searchVocabulary("relation_type", "mayBeSameAs");
        $maybeSameType = new \snac\data\Term();
        if (isset($tmp[0])) {
            $maybeSameType = $tmp[0];
        } else {
            $maybeSameType->setType("relation_type");
            $maybeSameType->setTerm("mayBeSameAs");
        }
        $maybesames = $this->cStore->listMaybeSameConstellations($constellation->getID(),\snac\server\database\DBUtil::$READ_MICRO_SUMMARY);
        foreach ($maybesames as $maybesame) {
            $relation = new \snac\data\ConstellationRelation();
            $relation->setSourceConstellation($constellation->getID());
            $relation->setSourceArkID($constellation->getArk());
            $relation->setTargetConstellation($maybesame->getID());
            $relation->setTargetArkID($maybesame->getArk());
            $relation->setTargetEntityType($maybesame->getEntityType());
            $relation->setContent($maybesame->getPreferredNameEntry()->getOriginal());
            $relation->setType($maybeSameType);
            $constellation->addRelation($relation);
        }
        $response = null;
        switch($input["type"]) {
            case "constellation_json":
                $response["file"] = array();
                $response["file"]["mime-type"] = "application/json";
                $response["file"]["filename"] = $this->arkToFilename($constellation->getArkID()).".json";
                $response["file"]["content"] = base64_encode(json_encode($constellation->toArray(), JSON_PRETTY_PRINT));
                break;
            case "eac-cpf":
                $response["file"] = array();
                $response["file"]["mime-type"] = "text/xml";
                $response["file"]["filename"] = $this->arkToFilename($constellation->getArkID()).".xml";
                $serializer = new \snac\util\EACCPFSerializer();
                $response["file"]["content"] = base64_encode($serializer->serialize($constellation));
                break;
            case "holdings":
                $icid = $input["constellationid"];
                $resources = $this->cStore->getRepoHoldings($icid);
                $fh = fopen('php://temp', 'rw'); 
                fputcsv($fh, array_keys(current($resources))); 
                foreach ( $resources as $row ) {
                    fputcsv($fh, $row);
                }
                rewind($fh);
                $csv = stream_get_contents($fh);
                fclose($fh);
                $response["file"] = array();
                $response["file"]["mime-type"] = "text/csv";
                $response["file"]["filename"] = $icid . "_holdings.csv";
                $response["file"]["content"] = base64_encode($csv);
                break;
            default:
                throw new \snac\exceptions\SNACInputException("Unknown download file type: " . $input["type"], 400);
        }
        return $response;
    }
public function downloadConstellation ( $ input ) { if ( ! isset ( $ input [ " type " ] ) ) { throw new \ snac \ exceptions \ SNACInputException ( " No download type specified " , 400 ) ; } $ constellations = $ this -> readConstellationFromDatabase ( $ input , true ) ; if ( $ constellations == null || count ( $ constellations ) > 1 ) { throw new \ snac \ exceptions \ SNACInputException ( " Constellation does not exist " , 404 ) ; } $ constellation = $ constellations [ 0 ] ; $ tmp = $ this -> cStore -> searchVocabulary ( " relation_type " , " mayBeSameAs " ) ; $ maybeSameType = new \ snac \ data \ Term ( ) ; if ( isset ( $ tmp [ 0 ] ) ) { $ maybeSameType = $ tmp [ 0 ] ; } else { $ maybeSameType -> setType ( " relation_type " ) ; $ maybeSameType -> setTerm ( " mayBeSameAs " ) ; } $ maybesames = $ this -> cStore -> listMaybeSameConstellations ( $ constellation -> getID ( ) , \ snac \ server \ database \ DBUtil :: $ READ_MICRO_SUMMARY ) ; foreach ( $ maybesames as $ maybesame ) { $ relation = new \ snac \ data \ ConstellationRelation ( ) ; $ relation -> setSourceConstellation ( $ constellation -> getID ( ) ) ; $ relation -> setSourceArkID ( $ constellation -> getArk ( ) ) ; $ relation -> setTargetConstellation ( $ maybesame -> getID ( ) ) ; $ relation -> setTargetArkID ( $ maybesame -> getArk ( ) ) ; $ relation -> setTargetEntityType ( $ maybesame -> getEntityType ( ) ) ; $ relation -> setContent ( $ maybesame -> getPreferredNameEntry ( ) -> getOriginal ( ) ) ; $ relation -> setType ( $ maybeSameType ) ; $ constellation -> addRelation ( $ relation ) ; } $ response = null ; switch ( $ input [ " type " ] ) { case " constellation_json " : $ response [ " file " ] = array ( ) ; $ response [ " file " ] [ " mime-type " ] = " application/json " ; $ response [ " file " ] [ " filename " ] = $ this -> arkToFilename ( $ constellation -> getArkID ( ) ) . " .json " ; $ response [ " file " ] [ " content " ] = base64_encode ( json_encode ( $ constellation -> toArray ( ) , JSON_PRETTY_PRINT ) ) ; break ; case " eac-cpf " : $ response [ " file " ] = array ( ) ; $ response [ " file " ] [ " mime-type " ] = " text/xml " ; $ response [ " file " ] [ " filename " ] = $ this -> arkToFilename ( $ constellation -> getArkID ( ) ) . " .xml " ; $ serializer = new \ snac \ util \ EACCPFSerializer ( ) ; $ response [ " file " ] [ " content " ] = base64_encode ( $ serializer -> serialize ( $ constellation ) ) ; break ; case " holdings " : $ icid = $ input [ " constellationid " ] ; $ resources = $ this -> cStore -> getRepoHoldings ( $ icid ) ; $ fh = fopen ( 'php://temp' , 'rw' ) ; fputcsv ( $ fh , array_keys ( current ( $ resources ) ) ) ; foreach ( $ resources as $ row ) { fputcsv ( $ fh , $ row ) ; } rewind ( $ fh ) ; $ csv = stream_get_contents ( $ fh ) ; fclose ( $ fh ) ; $ response [ " file " ] = array ( ) ; $ response [ " file " ] [ " mime-type " ] = " text/csv " ; $ response [ " file " ] [ " filename " ] = $ icid . " _holdings.csv " ; $ response [ " file " ] [ " content " ] = base64_encode ( $ csv ) ; break ; default : throw new \ snac \ exceptions \ SNACInputException ( " Unknown download file type:  " . $ input [ " type " ] , 400 ) ; } return $ response ; }
Download/Serialize a Constellation
 This method handles the downloading of content in any type.
Download / Serialize a Constellation This method handles the downloading of content in any type .
// The downloaded version should include maybesame relations // Get the mayBeSameAs term from the database so we can populate the maybe same links // Add the maybe same constellations into the downloaded version as Constellation Relations # don't create a file, attempt to use memory instead // Add column headings