Last active
April 15, 2016 10:33
-
-
Save bryjbrown/0f457852b7e02e35068cb04aaf6533b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getCollectionData($collection_pid) { | |
$user = user_load(1); | |
$repository = islandora_get_tuque_connection($user); | |
$query = <<<EOQ | |
SELECT ?pid ?label ?cmodel | |
FROM <#ri> | |
WHERE { | |
?pid <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid> ; | |
<fedora-model:label> ?label ; | |
<fedora-model:hasModel> ?cmodel | |
FILTER (?cmodel != <info:fedora/fedora-system:FedoraObject-3.0>) | |
} | |
EOQ; | |
$results = $repository->repository->ri->sparqlQuery($query); | |
$subCollections = array(); | |
$recordCount = 0; | |
foreach($results as $result) { | |
if ($result['cmodel']['value'] != 'islandora:collectionCModel') { | |
$recordCount = $recordCount + 1; | |
} | |
else { | |
$subCollections[] = $result['pid']['value']; | |
} | |
} | |
$ret = array('records' => $recordCount, 'collections' => $subCollections); | |
$collection_title = islandora_object_load($collection_pid)->label; | |
$msg = "<a href=\"/islandora/object/$collection_pid\">$collection_title [$recordCount]</a>\n<ul>\n"; | |
foreach ($subCollections as $subCollection) { | |
$submsg = getCollectionData($subCollection); | |
$msg .= "<li>$submsg</li>\n"; | |
} | |
$msg .= "</ul>"; | |
return $msg; | |
} | |
// Initiate function with target collection PID of your choice | |
echo getCollectionData('islandora:root'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This would work well inside a custom module (providing content for a block, for example).
Is the 'isMemberOfCollection' predicate transitive? If so you might be able to get all the subcollections using just one SPARQL query.