/** * Appends Dublin Core metadata. * * Appends a metadata element, an child element with the required format, * and further children for each of the Dublin Core fields present in the * item. */ public function appendMetadata() { $metadataElement = $this->document->createElement('metadata'); $this->parentElement->appendChild($metadataElement); $oai_dc = $this->document->createElementNS(self::METADATA_NAMESPACE, 'oai_dc:dc'); $metadataElement->appendChild($oai_dc); /* Must manually specify XML schema uri per spec, but DOM won't include * a redundant xmlns:xsi attribute, so we just set the attribute */ $oai_dc->setAttribute('xmlns:dc', self::DC_NAMESPACE_URI); $oai_dc->setAttribute('xmlns:xsi', parent::XML_SCHEMA_NAMESPACE_URI); $oai_dc->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA); if (!array_key_exists('0', $this->item)) { $data = array('title' => $this->item['broadperiod'] . ' ' . $this->item['objecttype'], 'creator' => $this->item['identifier'], 'subject' => 'archaeology', 'description' => strip_tags($this->item['description']), 'publisher' => 'The Portable Antiquities Scheme', 'contributor' => $this->item['institution'], 'date' => $this->item['created'], 'type' => $this->item['objecttype'], 'format' => 'text/html', 'id' => $this->item['id'], 'identifier' => self::PAS_RECORD_URL . $this->item['id'], 'source' => 'The Portable Antiquities Scheme Database', 'language' => 'en-GB'); $files = new OaiFinds(); $images = $files->getImages($this->item['id']); if (count($images)) { foreach ($images as $image) { if (!is_null($image['i'])) { $thumbnail = 'http://www.finds.org.uk/images/thumbnails/' . $image['i'] . '.jpg'; $data['relation'] = $thumbnail; } else { $data['relation'] = ''; } } } $data['coverage'] = $this->item['broadperiod']; $data['rights'] = 'The Portable Antiquities Scheme - Creative Commons Share-Alike Non-Commercial'; unset($data['id']); foreach ($data as $k => $v) { $this->appendNewElement($oai_dc, 'dc:' . $k, $v); } } }
/** * Appends the record's header to the XML response. * * Adds the identifier, datestamp and setSpec to a header element, and * appends in to the document. * * @uses appendHeader * @uses appendMetadata */ public function appendHeader() { $table = new OaiFinds(); if (array_key_exists('0', $this->item)) { $itemid = $this->item['0']['id']; $updated = $this->item['0']['created']; $collectionId = $this->item['0']['institution']; } else { $itemid = $this->item['id']; $updated = $this->item['created']; $collectionId = $this->item['institution']; } $item = $table->fetchRow($table->select()->where('finds.id = ?', $itemid)); $object = new Pas_OaiPmhRepository_OaiIdentifier(); $itemNumber = $object->itemToOaiId($itemid); $headerData['identifier'] = $itemNumber; $headerData['datestamp'] = self::dbToUtc($updated); if ($collectionId) { $headerData['setSpec'] = $collectionId; } $this->createElementWithChildren($this->parentElement, 'header', $headerData); }
public function appendMetadata() { $metadataElement = $this->document->createElement('metadata'); $this->parentElement->appendChild($metadataElement); $pnds = $this->document->createElementNS(self::METADATA_NAMESPACE, 'pndsdc:description'); $metadataElement->appendChild($pnds); /* Must manually specify XML schema uri per spec, but DOM won't include * a redundant xmlns:xsi attribute, so we just set the attribute */ $pnds->setAttribute('xmlns', self::OAI_NAMESPACE); $pnds->setAttribute('xmlns:dc', self::DC_NAMESPACE_URI); $pnds->setAttribute('xmlns:dcterms', self::DC_TERMS_NAMESPACE); $pnds->setAttribute('xmlns:xsi', parent::XML_SCHEMA_NAMESPACE_URI); $pnds->setAttribute('xmlns:pndsterms', self::PNDS_TERMS_NAMESPACE); $pnds->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA); if (!array_key_exists('0', $this->item)) { $data = array('identifier' => self::PAS_RECORD_URL . $this->item['id'], 'title' => $this->item['broadperiod'] . ' ' . $this->item['objecttype'], 'description' => strip_tags($this->_xmlEscape($this->item['description'])), 'subject' => 'archaeology', 'type' => $this->item['objecttype']); foreach ($data as $k => $v) { $this->appendNewElement($pnds, 'dc:' . $k, $v); } $rightsURI = $this->appendNewElement($pnds, 'dcterms:license', ''); $rightsURI->setAttribute('valueURI', 'http://creativecommons.org/licenses/by-nc-sa/3.0/'); $this->appendNewElement($pnds, 'dcterms:rightsHolder', 'The Portable Antiquities Scheme'); // $type = $this->appendNewElement($pnds,'dc:type','PhysicalObject'); // $type->setAttribute('encSchemeURI','http://purl.org/dc/terms/DCMIType'); // $type->setAttribute('valueURI','http://purl.org/dc/terms/DCMIType'); $data2 = array('creator' => $this->item['identifier'], 'contributor' => $this->item['institution'], 'publisher' => 'The Portable Antiquities Scheme', 'language' => 'en', 'format' => 'text/html'); foreach ($data2 as $k => $v) { $this->appendNewElement($pnds, 'dc:' . $k, $v); } $spatial = array('county' => $this->item['county'], 'district' => $this->item['district']); $temporal = array('year1' => $this->item['numdate1'], 'year2' => $this->item['numdate2']); if (!is_null($this->item['knownas']) && !is_null($this->item['fourFigure'])) { $coords = new Pas_Geo_Gridcalc($this->item['fourFigure']); $lat = $coords['decimalLatLon']['decimalLatitude']; $lon = $coords['decimalLatLon']['decimalLongitude']; $spatial['coords'] = $lat . ',' . $lon; } foreach ($spatial as $k => $v) { $this->appendNewElement($pnds, 'dcterms:spatial', $v); } foreach ($temporal as $k => $v) { $this->appendNewElement($pnds, 'dcterms:temporal', $v); } $files = new OaiFinds(); $images = $files->getImages($this->item['id']); if (count($images)) { foreach ($images as $image) { if (!is_null($image['i'])) { $thumbnail = 'http://www.finds.org.uk/images/thumbnails/' . $image['i'] . '.jpg'; $this->appendNewElement($pnds, 'pndsterms:thumbnail', $thumbnail); } } } // Append the browse URI to all results } }
/** Add meta data to the xml response in this ESE */ public function appendMetadata() { $metadataElement = $this->document->createElement('metadata'); $this->parentElement->appendChild($metadataElement); $europeana = $this->document->createElementNS(self::METADATA_NAMESPACE, 'ese:record'); $metadataElement->appendChild($europeana); $europeana->setAttribute('xmlns:dc', self::DC_NAMESPACE_URI); $europeana->setAttribute('xmlns:oai_dc', self::DC_METADATA_NAMESPACE); $europeana->setAttribute('xmlns:ese', self::DC_NAMESPACE_URI); $europeana->setAttribute('xmlns:xsi', parent::XML_SCHEMA_NAMESPACE_URI); $europeana->setAttribute('xsi:schemaLocation', self::METADATA_NAMESPACE . ' ' . self::METADATA_SCHEMA); $europeana->setAttribute('xmlns:dcterms', self::DC_TERMS_NAMESPACE); //Create the dublin core metadata from an array of objects if (!array_key_exists('0', $this->item)) { $dc = array('title' => $this->item['broadperiod'] . ' ' . $this->item['objecttype'], 'creator' => $this->item['identifier'], 'subject' => 'archaeology' . ' - ' . $this->item['broadperiod'], 'description' => strip_tags(str_replace(array("\n", "\r", ' '), array('', '', ' '), $this->item['description'])), 'publisher' => 'The Portable Antiquities Scheme', 'contributor' => $this->institution($this->item['institution']), 'date' => $this->item['created'], 'type' => $this->item['objecttype'], 'format' => 'text/html', 'source' => 'The Portable Antiquities Scheme Database', 'language' => 'en', 'identifier' => $this->item['old_findID'], 'coverage' => $this->item['broadperiod'], 'rights' => 'Creative Commons General Public License "Attribution, Non-Commercial, Share-Alike", version 3.'); //Create the spatial arrray $spatial = array('county' => $this->item['county'], 'district' => $this->item['district']); //Check for availability of NGR and therefore latlon conversions if (is_null($this->item['knownas']) && !is_null($this->item['fourFigure'])) { $coords = new Pas_Geo_Gridcalc($this->item['fourFigure']); $lat = $coords['decimalLatLon']['decimalLatitude']; $lon = $coords['decimalLatLon']['decimalLongitude']; $spatial['coords'] = $lat . ',' . $lon; } $dcterms = array('created' => date('Y-m-d', strtotime($this->item['created'])), 'medium' => $this->item['primaryMaterial'], 'isPartOf' => 'Beowulf: The Portable Antiquities Scheme database', 'provenance' => 'Crowdsourced from the public of England and Wales'); $ese = array(); $ese['provider'] = 'The Portable Antiquities Scheme'; $ese['type'] = 'TEXT'; $temporal = array('year1' => $this->item['numdate1'], 'year2' => $this->item['numdate2']); $files = new OaiFinds(); $images = $files->getImages($this->item['id']); $formats = array(); if (count($images)) { foreach ($images as $image) { if (!is_null($image['i'])) { $thumbnail = self::PAS_IMAGE_URL . $image['i'] . '.jpg'; $ese['isShownBy'] = $thumbnail; $number = $image['f']; $formats[$number] = self::PAS_BASE_URL . $image['imagedir'] . $image['f']; } } } $ese['isShownAt'] = self::PAS_RECORD_URL . $this->item['id']; foreach ($dc as $k => $v) { $this->appendNewElement($europeana, 'dc:' . $k, $v); } foreach ($dcterms as $k => $v) { $this->appendNewElement($europeana, 'dcterms:' . $k, $v); } foreach ($formats as $k => $v) { $this->appendNewElement($europeana, 'dcterms:hasFormat', $v); } foreach ($temporal as $k => $v) { $this->appendNewElement($europeana, 'dcterms:temporal', $v); } foreach ($spatial as $k => $v) { $this->appendNewElement($europeana, 'dcterms:spatial', $v); } foreach ($ese as $k => $v) { $this->appendNewElement($europeana, 'ese:' . $k, $v); } } }
/** * Responds to the two main List verbs, includes resumption and limiting. * * @param string $verb OAI-PMH verb for the request * @param string $metadataPrefix Metadata prefix * @param int $cursor Offset in response to begin output at * @param mixed $set Optional set argument * @param string $from Optional from date argument * @param string $until Optional until date argument * @uses createResumptionToken() */ private function listResponse($verb, $metadataPrefix, $cursor, $set, $from, $until) { $listLimit = 30; $itemTable = new OaiFinds(); $items = $itemTable->getRecords($cursor, $set, $from, $until); $totals = $itemTable->getCountAllFinds($set, $from, $until); $rows = $totals['0']['c']; if (count($items) == 0) { $this->throwError(self::OAI_ERR_NO_RECORDS_MATCH, 'No records match the given criteria'); } else { if ($verb == 'ListIdentifiers') { $method = 'appendHeader'; } else { if ($verb == 'ListRecords') { $method = 'appendRecord'; } } $verbElement = $this->document->createElement($verb); $this->document->documentElement->appendChild($verbElement); foreach ($items as $item) { $record = new $this->metadataFormats[$metadataPrefix]($item, $verbElement); $record->{$method}(); } $total = $cursor + $listLimit; if ($rows > $total) { $token = $this->createResumptionToken($verb, $metadataPrefix, $cursor, $set, $from, $until); $tokenElement = $this->document->createElement('resumptionToken', $token->id); $tokenElement->setAttribute('expirationDate', self::dbToUtc($token->expiration)); $tokenElement->setAttribute('completeListSize', $rows); $tokenElement->setAttribute('cursor', $cursor + $listLimit); $verbElement->appendChild($tokenElement); } else { if ($cursor != 0) { $tokenElement = $this->document->createElement('resumptionToken'); $verbElement->appendChild($tokenElement); } } } }