Browse Source

Merge pull request #186 from adam-vessey/6.x-extend-add-relationships

ISLANDORA-766: Allow arrays relationship objects
pull/183/merge
Jonathan Green 12 years ago
parent
commit
9e7067d222
  1. 31
      api/fedora_item.inc

31
api/fedora_item.inc

@ -281,8 +281,8 @@ class Fedora_Item {
* *
* @param string $relationship * @param string $relationship
* The predicate/relationship tag to add * The predicate/relationship tag to add
* @param string $object * @param string|array $object
* The object to be related to. * The object(s) to be related to.
* @param string $namespaceURI * @param string $namespaceURI
* The predicate namespace. * The predicate namespace.
* @param int $literal_value * @param int $literal_value
@ -318,10 +318,6 @@ RDF;
$relsext = $this->get_datastream_dissemination('RELS-EXT'); $relsext = $this->get_datastream_dissemination('RELS-EXT');
if ($literal_value == RELS_TYPE_URI && strpos($object, $f_prefix) !== 0) {
$object = $f_prefix . $object;
}
$relsextxml->loadXML($relsext); $relsextxml->loadXML($relsext);
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description'); $description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
if ($description->length == 0) { if ($description->length == 0) {
@ -333,18 +329,26 @@ RDF;
} }
$description = $description->item(0); $description = $description->item(0);
// Casting a string to an array gives an array containing the string, and
// casting an array to an array does nothing.
foreach ((array)$object as $obj) {
if ($literal_value == RELS_TYPE_URI && strpos($obj, $f_prefix) !== 0) {
$obj = $f_prefix . $obj;
}
// Create the new relationship node. // Create the new relationship node.
$newrel = $relsextxml->createElementNS($namespaceURI, $relationship); $newrel = $relsextxml->createElementNS($namespaceURI, $relationship);
$this->buildRelsStatement($newrel, $object, $literal_value); $this->buildRelsStatement($newrel, $obj, $literal_value);
$description->appendChild($newrel); $description->appendChild($newrel);
}
return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml'); return $this->modify_datastream($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml');
} }
/** /**
* Extension of add_relationship, which acts on RELS-INT. * Extension of add_relationship(), which acts on RELS-INT.
* *
* @param $dsid * @param $dsid
* A string containing either the base dsid (EXAMPLE) * A string containing either the base dsid (EXAMPLE)
@ -367,9 +371,6 @@ RDF;
$rels_text = $this->get_datastream_dissemination('RELS-INT'); $rels_text = $this->get_datastream_dissemination('RELS-INT');
if ($literal_value == RELS_TYPE_URI && strpos($object, $f_prefix) !== 0) {
$object = $f_prefix . $object;
}
if (strpos($dsid, $f_prefix) !== 0) { if (strpos($dsid, $f_prefix) !== 0) {
$dsid = $f_prefix . $this->pid . '/' . $dsid; $dsid = $f_prefix . $this->pid . '/' . $dsid;
} }
@ -391,12 +392,18 @@ RDF;
$relsxml->documentElement->appendChild($description); $relsxml->documentElement->appendChild($description);
} }
foreach ((array)$object as $obj) {
if ($literal_value == RELS_TYPE_URI && strpos($obj, $f_prefix) !== 0) {
$obj = $f_prefix . $object;
}
// Create the new relationship node. // Create the new relationship node.
$newrel = $relsxml->createElementNS($namespaceURI, $relationship); $newrel = $relsxml->createElementNS($namespaceURI, $relationship);
$this->buildRelsStatement($newrel, $object, $literal_value); $this->buildRelsStatement($newrel, $obj, $literal_value);
$description->appendChild($newrel); $description->appendChild($newrel);
}
return $this->modify_datastream($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'application/rdf+xml'); return $this->modify_datastream($relsxml->saveXML(), 'RELS-INT', "Fedora Datastream Relationship Metadata", 'application/rdf+xml');
} }

Loading…
Cancel
Save