Browse Source

Fixed my stupid mistakes in Ingest

I added the collection policy class, although a more stripped down
version of it and fixed in ingest function that calls it.
pull/110/head
jonathangreen 13 years ago
parent
commit
d1992386fe
  1. 150
      islandora_basic_collection/includes/CollectionPolicy.inc
  2. 15
      islandora_basic_collection/islandora_basic_collection.module

150
islandora_basic_collection/includes/CollectionPolicy.inc

@ -0,0 +1,150 @@
<?php
/**
* @file
* This file contains the classes for parsing the collection policy infomration.
*/
/**
* Collection Policy class
*/
class CollectionPolicy {
/**
* Constructor
* NOTE: Use the static constructor methods whenever possible.
*
* @param string $xmlStr
* The COLLECTION_POLICY in string form
*
* @return CollectionPolicy
* The parsed collection policy.
*/
public function __construct($xmlStr) {
$this->xml = new DOMDocument();
$this->xml->loadXML($xmlStr);
$this->name = 'Collection Policy';
}
/**
* Gets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @return string $relationship
*/
public function getRelationship() {
$ret = trim($this->xml->getElementsByTagName('relationship')->item(0)->nodeValue);
return $ret;
}
/**
* Sets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @param string $relationship
* @return boolean $ret
*/
public function setRelationship($relationship) {
$ret = FALSE;
if ($this->validate()) {
$relationshipEl = $this->xml->getElementsByTagName('relationship')->item(0);
$relationshipEl->nodeValue = trim($relationship);
$ret = TRUE;
}
return $ret;
}
/**
* Gets a list of ContentModel objects supported by this collection.
*
* @return ContentModel[] $models
*/
function getContentModels() {
$ret = array();
$content_models = $this->xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model');
for ($i = 0; $i < $content_models->length; $i++) {
$cm = array();
$cm['pid'] = $content_models->item($i)->getAttribute('pid');
$cm['namespace'] = $content_models->item($i)->getAttribute('namespace');
$cm['name'] = $content_models->item($i)->getAttribute('name');
if ($cm !== FALSE) {
$ret[] = $cm;
}
}
return $ret;
}
/**
* Removes the specified content model from the collection policy. This will only
* prevent future ingests of the removed model to the collection. $cm should be
* a valid ContentModel object. Returns FALSE on failure or when the CM was not found in
* the collection policy.
*
* @param ContentModel $cm
* @return boolean $valid
*/
function removeModel($cm) {
$ret = FALSE;
if ($this->validate() && $cm->validate()) {
$contentmodelsEl = $this->xml->getElementsByTagName('content_models');
$models = $contentmodelsEl->item(0)->getElementsByTagName('content_model');
$found = FALSE;
for ($i = 0; $found === FALSE && $i < $models->length; $i++) {
if ($models->item($i)->getAttribute('pid') == $cm->pid) {
$found = $models->item($i);
}
}
if ($found !== FALSE && $models->length > 1) {
$contentmodelsEl->item(0)->removeChild($found);
$ret = TRUE;
}
}
return $ret;
}
/**
* addModel ??
* @param ContentModel $cm
* @param type $namespace
* @return type
*/
function addModel($cm, $namespace) {
$ret = FALSE;
if (self::valid_pid($namespace) && $this->validate() && $cm->validate()) {
$contentmodelsEl = $this->xml->getElementsByTagName('content_models');
$models = $contentmodelsEl->item(0)->getElementsByTagName('content_model');
$found = FALSE;
for ($i = 0; !$found && $i < $models->length; $i++) {
if ($models->item($i)->getAttribute('pid') == $cm->pid)
$found = TRUE;
}
if (!$found) {
$cmEl = $this->xml->createElement('content_model');
$cmEl->setAttribute('name', $cm->getName());
$cmEl->setAttribute('dsid', $cm->dsid);
$cmEl->setAttribute('namespace', $namespace);
$cmEl->setAttribute('pid', $cm->pid);
$contentmodelsEl->item(0)->appendChild($cmEl);
}
$ret = !$found;
}
return $ret;
}
/**
* getName ??
* @return type
*/
function getName() {
$ret = FALSE;
if ($this->validate()) {
$ret = $this->xml->getElementsByTagName('collection_policy')->item(0)->getAttribute('name');
}
return $ret;
}
}

15
islandora_basic_collection/islandora_basic_collection.module

@ -140,18 +140,11 @@ function islandora_basic_collection_get_objects($object) {
function islandora_basic_collection_islandora_ingest_get_information($models, $object) { function islandora_basic_collection_islandora_ingest_get_information($models, $object) {
if(in_array('info:fedora/islandora:collectionCModel', $models) && isset($object['COLLECTION_POLICY'])) { if(in_array('info:fedora/islandora:collectionCModel', $models) && isset($object['COLLECTION_POLICY'])) {
try { try {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy');
$return = array(); $return = array();
$xml = new SimpleXMLElement($object['COLLECTION_POLICY']); $policy = new CollectionPolicy($object['COLLECTION_POLICY']->content);
$cms = $xml->getElementsByTagName('content_models')->item(0)->getElementsByTagName('content_model'); $return['models'] = $policy->getContentModels();
$return['contentsmodels'] = array(); $return['relationship'] = $policy->getRelationship();
foreach($cms as $cm) {
$contentmodel = array();
$contentmodel['name'] = (string) $cm['name'];
$contentmodel['namespace'] = (string) $cm['namespace'];
$contentmodel['pid'] = (string) $cm['pid'];
$return['contentsmodels'] = (string) $contentmodel;
}
$return['relationship'] = trim($xml->getElementsByTagName('relationship')->item(0)->nodeValue);
return $return; return $return;
} }

Loading…
Cancel
Save