Browse Source

Merge branch '7.x' of github.com:Islandora/islandora into 7.x

pull/120/head
jonathangreen 13 years ago
parent
commit
a90080cb59
  1. 4
      includes/islandora.ingest.inc
  2. 10
      islandora_basic_collection/admin/islandora_basic_collection.admin.inc
  3. 150
      islandora_basic_collection/includes/ChangeContentModels.inc
  4. 25
      islandora_basic_collection/includes/ChildCollection.inc
  5. 51
      islandora_basic_collection/includes/CollectionManagement.inc
  6. 22
      islandora_basic_collection/includes/CollectionManagerTable.inc
  7. 115
      islandora_basic_collection/includes/CollectionPolicy.inc
  8. 28
      islandora_basic_collection/includes/DeleteCollection.inc
  9. 47
      islandora_basic_collection/includes/ManagePolicies.inc
  10. 18
      islandora_basic_collection/includes/MoveCollection.inc
  11. 61
      islandora_basic_collection/islandora_basic_collection.install
  12. 32
      islandora_basic_collection/islandora_basic_collection.module

4
includes/islandora.ingest.inc

@ -13,9 +13,9 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation
$connection = new RestConnection($user);
$object = $connection->repository->constructObject($namespace);
foreach($content_models as $content_model) {
$object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model);
$object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model['pid']);
}
$object->relationships->add($relationship['uri'], $relationship['value'], $collection_pid);
$object->relationships->add(FEDORA_RELS_EXT_URI, $relationship, $collection_pid);
module_invoke_all('islandora_ingest_pre_ingest', $object, $content_models, $collection_pid);
return $object;
}

10
islandora_basic_collection/admin/islandora_basic_collection.admin.inc

@ -1,5 +1,14 @@
<?php
/**
* @file
* islandora_basic_collection.admin.inc
*/
/**
*
* @return type
*/
function islandora_basic_collection_admin() {
$form = array();
$form['islandora_basic_collection_use_for_default_tab'] = array(
@ -20,4 +29,3 @@ function islandora_basic_collection_admin() {
return system_settings_form($form);
}

150
islandora_basic_collection/includes/ChangeContentModels.inc

@ -0,0 +1,150 @@
<?php
/**
* @file
* ChangeContentModels.inc
*/
function islandora_change_content_models_form($form, &$form_state, $collection_pid) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
$content_models = get_content_models_list($collection_pid);
$cm_options = array();
$name_mappings = array();
foreach ($content_models as $content_model) {
if ($content_model != "islandora:collectionCModel") {
$item = new FedoraObject($content_model, $rest_connection->repository);
$cm_name = $item->Label;
$cm_options[$content_model] = $cm_name;
}
}
$namespace = substr($collection_pid, 0, strpos($collection_pid, ":"));
$collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY');
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$collection_policy_datastream = $collection_object->getDatastream($collection_policy_dsid);
$supported_collection_models = array();
if ($collection_policy_datastream->content) {
$collection_policy = new CollectionPolicy($collection_policy_datastream->content);
$supported_collection_models = $collection_policy->getContentModels();
}
$collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":"));
$collection_name = $collection_object->label;
$new_content_models = get_content_models_as_option_array();
$current_models_in_policy = array();
if ($supported_collection_models) {
foreach ($supported_collection_models as $supported_model) {
$current_models_in_policy[$supported_model['pid']] = $supported_model['pid'];
}
}
$form['change_cmodel']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Change Content Models within @collection_pid", array('@collection_pid' => $collection_pid)),
);
$form['change_cmodel']['current_content_model'] = array(
'#title' => "Choose content model to be changed",
'#type' => 'select',
'#options' => $current_models_in_policy,
'#description' => t("All objects in this collection with the selected content model will be changed."),
);
$form['change_cmodel']['new_content_model'] = array(
'#title' => "Choose new content model",
'#type' => 'select',
'#options' => $new_content_models,
'#description' => t("The new content model to be assigned to selected objects."),
);
$form['change_cmodel']['collection_pid'] = array(
'#type' => 'hidden',
'#value' => $collection_pid,
);
$form['change_cmodel']['submit'] = array(
'#type' => 'submit',
'#value' => t('Change content model associations'),
'#id' => 'change_model',
);
return $form;
}
function islandora_change_content_models_form_validate($form, &$form_state) {
}
function islandora_change_content_models_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
$current_content_model = $form_state['values']['current_content_model'];
$new_content_model = $form_state['values']['new_content_model'];
$collection_pid = $form_state['values']['collection_pid'];
$current_content_model_object = new FedoraObject($current_content_model, $rest_connection->repository);
$collection_object = new FedoraObject($form_state['values']['collection_pid'], $rest_connection->repository);
$collection_policy_datastream = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'));
$policy = new CollectionPolicy($collection_policy_datastream->content);
$collection_policy_xml = new DOMDocument();
$collection_policy_xml->loadXML($collection_policy_datastream->content);
$add_to_policy = TRUE;
$policy_content_models = $policy->getContentModels();
foreach ($policy_content_models as $policy_content_model) {
if ($policy_content_model['pid'] == $current_content_model) {
$namespace = $policy_content_model['namespace'];
}
if ($policy_content_model['pid'] == $new_content_model) {
$add_to_policy = FALSE;
}
}
if ($add_to_policy) {
$new_content_model_object = new FedoraObject($new_content_model, $rest_connection->repository);
$new_content_model_datastream = $new_content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
$content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model');
$content_model_element = $collection_policy_xml->createElement('content_model');
$content_model_element->setAttribute('name', $new_content_model_object->label);
$content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_model_element->setAttribute('namespace', $namespace);
$content_model_element->setAttribute('pid', $new_content_model_object->id);
$content_models_element->item(0)->appendChild($content_model_element);
$new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY');
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML());
$new_collection_policy_datastream->label = 'COLLECTION_POLICY';
$collection_object->ingestDatastream($new_collection_policy_datastream);
}
$query = "select \$object from <#ri>
where (\$object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/$current_content_model>
and (\$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid>
or \$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/$collection_pid>)
and \$object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)";
$objects = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$count = 0;
foreach ($objects as $object) {
if (!$object['object']['value']) {
continue;
}
$fedora_item = new FedoraObject($object['object']['value'], $rest_connection->repository);
$fedora_item->relationships->remove(FEDORA_MODEL_URI, 'hasModel', $current_content_model);
$fedora_item->relationships->add(FEDORA_MODEL_URI, 'hasModel', $new_content_model);
$count++;
}
drupal_set_message(t('@current_content_model changed to @new_content_model on @count objects', array('@current_content_model' => $current_content_model, '@new_content_model' => $new_content_model, '@count' => $count)));
}

25
islandora_basic_collection/includes/ChildCollection.inc

@ -1,8 +1,20 @@
<?php
/**
* @file
* ChildCollection.inc
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $this_collection_pid
* @return string
*/
function islandora_create_child_collection_form($form, &$form_state, $this_collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$restricted = FALSE;
if (variable_get('fedora_namespace_restriction_enforced', TRUE)) {
@ -18,7 +30,8 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
$form['child_creation']['titlebox'] = array(
'#markup' => t("Create New Child Collection within @collection", array('@collection' => $this_collection_pid)),
'#type' => 'item',
'#title' => t("Create New Child Collection within @collection", array('@collection' => $this_collection_pid)),
);
$form['child_creation']['collection_name'] = array(
@ -32,7 +45,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
'#title' => "Collection PID",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $restConnection->repository->api->m->getNextPid($collection_namespace),
'#default_value' => $rest_connection->repository->api->m->getNextPid($collection_namespace),
'#description' => t("Unique PID for this collection. <br />Pids take the general form of namespace:collection (eg. islandora:pamphlets)"),
);
@ -62,14 +75,14 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
$form['child_creation']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create Collection'),
'#value' => t('Create collection'),
'#id' => 'create_child'
);
return $form;
}
function islandora_create_child_collection_form_validate($form, &$form_state) {
}
function islandora_create_child_collection_form_submit($form, &$form_state) {
@ -94,7 +107,7 @@ function islandora_create_child_collection_form_submit($form, &$form_state) {
$thumbnail_datastream->mimetype = 'image/png';
$fedora_object->ingestDatastream($thumbnail_datastream);
$new_fedora_object = islandora_ingest_add_object($fedora_object);
// $content_models = $form_state['values']['content_models'];
// $collection_policy_xml = simplexml_load_string($collection_policy);
// foreach ($content_models as $content_model) {

51
islandora_basic_collection/includes/CollectionManagement.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* CollectionManagement.inc
*/
/**
* collection creation form
* @param array $form_state
@ -219,7 +224,7 @@ function collection_management_form($this_collection_pid, $content_models) {
'#id' => 'change_model',
);
return($form);
return $form;
}
/**
@ -409,9 +414,9 @@ function collection_management_form_submit($form, &$form_state) {
*/
function delete_objects_as_batch($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$name = $user->name;
$restConnection->repository->purgeObject($pid);
$rest_connection->repository->purgeObject($pid);
}
/**
@ -420,8 +425,8 @@ function delete_objects_as_batch($pid) {
*/
function remove_collection_association($pid, $collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$rest_connection = new RestConnection();
$fedora_object = new FedoraObject($pid, $rest_connection->repository);
$fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid);
}
@ -432,7 +437,7 @@ function remove_collection_association($pid, $collection_pid) {
*/
function get_represented_content_models($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = "select \$model \$title from <#ri>
@ -441,12 +446,14 @@ where (\$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <i
and \$object <info:fedora/fedora-system:def/model#hasModel> \$model
and \$object <dc:title> \$title";
$model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$model_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$represented_models = array();
foreach ($model_pids as $model_pid) {
if ($model_pid && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') {
$represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $model_pid['title']['value'];
if ($model_pid['model']['value'] && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') {
$fedora_object = new FedoraObject($model_pid['model']['value'], $rest_connection->repository);
$content_model_title = $fedora_object->label;
$represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $content_model_title;
}
}
return $represented_models;
@ -454,7 +461,7 @@ where (\$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <i
function get_child_collections($collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = <<<EOD
@ -463,14 +470,14 @@ function get_child_collections($collection_pid) {
and \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid>
EOD;
$lines = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$lines = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$collection_pids = array_values(array_filter($lines));
return $collection_pids;
}
function Islandora_collections_get_collection_from_pid($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = 'select $parent from <#ri>
@ -479,7 +486,7 @@ function Islandora_collections_get_collection_from_pid($pid) {
and $object <dc:identifier> \'' . $pid . '\'
order by $object';
$object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$object_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$object_pids = array_values(array_filter($object_pids));
return $object_pids;
}
@ -494,7 +501,7 @@ function Islandora_collections_get_collection_from_pid($pid) {
*/
function get_related_items_as_array($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
global $user;
@ -534,7 +541,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by ' . $orderby;
$results = $restConnection->repository->ri->itqlQuery($query_string, $limit, $offset);
$results = $rest_connection->repository->ri->itqlQuery($query_string, $limit, $offset);
return $results;
}
@ -568,13 +575,13 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
// $collectionHelper = new CollectionClass();
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$pids = array();
$query = 'select $object from <#ri>
where <info:fedora/' . $pid . '> <fedora-model:hasModel> $object
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>';
// $content_models = $collectionHelper->getRelatedItems($pid, $query);
$content_models = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$content_models = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
if (empty($content_models)) {
return $pids;
@ -604,7 +611,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
*/
function get_content_models_as_option_array() {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
@ -622,7 +629,7 @@ function get_content_models_as_option_array() {
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$list = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$list = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$options = array();
foreach ($list as $item) { //removes blanks
if ($item) {
@ -641,10 +648,10 @@ function get_content_models_as_option_array() {
function getContentModels($collection_pid, $showError = TRUE) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
// module_load_include('inc', 'Fedora_Repository', 'ContentModel');
$collection_stream = $this->getCollectionPolicyStream($collection_pid);
$collection_object = new FedoraObject($collection_pid, $restConnection->repository);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$collection_stream = $collection_object->getDatastream('COLLECTION_POLICY');
try {
$xml = new SimpleXMLElement($collection_stream);

22
islandora_basic_collection/includes/CollectionManagerTable.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* CollectionManagerTable.inc
*/
/**
* Returns a formatted table listing all members of the collection
* defined by the $collection_pid parameter
@ -9,12 +14,12 @@
function islandora_collection_table($collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/' . $collection_pid . '>
or $object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/' . $collection_pid . '>)
and $object <dc:title> $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$keys = array();
$objects = array();
foreach ($results as $result) {
@ -35,15 +40,15 @@ function islandora_collection_table($collection_pid) {
),
);
}
$header = array(
'title' => array('data' => t('Title')),
);
if (!$rows) {
return;
}
$table = array(
'#type' => 'tableselect',
'#header' => $header,
@ -51,7 +56,7 @@ function islandora_collection_table($collection_pid) {
);
return $table;
}
/**
@ -89,19 +94,18 @@ function get_collections_as_option_array() {
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
foreach ($namespaces as $namespace) {
$trimmed_names[] = trim($namespace);
}
$options = array();
foreach ($results as $item) { //removes blanks
// var_dump($item['object']['value']);
$namespace = explode(':', $item['object']['value']);
$namespace = trim($namespace[0]);
if (!$restricted || in_array($namespace, $trimmed_names)) {

115
islandora_basic_collection/includes/CollectionPolicy.inc

@ -16,7 +16,7 @@ class CollectionPolicy {
*
* @param string $xmlStr
* The COLLECTION_POLICY in string form
*
*
* @return CollectionPolicy
* The parsed collection policy.
*/
@ -27,8 +27,8 @@ class CollectionPolicy {
}
/**
* Gets the name of the relationship to use
* for members of this collection.
* Gets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @return string $relationship
@ -39,8 +39,8 @@ class CollectionPolicy {
}
/**
* Sets the name of the relationship to use
* for members of this collection.
* Sets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @param string $relationship
@ -77,8 +77,8 @@ class CollectionPolicy {
}
/**
* 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
* 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.
*
@ -109,7 +109,7 @@ class CollectionPolicy {
* addModel ??
* @param ContentModel $cm
* @param type $namespace
* @return type
* @return type
*/
function addModel($cm, $namespace) {
$ret = FALSE;
@ -141,7 +141,7 @@ class CollectionPolicy {
/**
* getName ??
* @return type
* @return type
*/
function getName() {
$ret = FALSE;
@ -151,101 +151,4 @@ class CollectionPolicy {
return $ret;
}
/**
* valid_pid
* Validates a fedora PID based on the regexp provided in the fedora
* 3.3 documentation.
* http://www.fedora-commons.org/confluence/display/FCR30/Fedora+Identifiers
*
* @param String $pid
* @return boolean $valid
*/
public static function valid_pid($pid) {
$valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
$valid = TRUE;
}
return $valid;
}
/**
* Validates the XMLDatastream against the schema location
* defined by the xmlns:schemaLocation attribute of the root
* element. If the xmlns:schemaLocation attribute does not exist,
* then it is assumed to be the old schema and it attempts to convert
* using the convertFromOldSchema method.
*
* TODO: Maybe change it so that it always validates against a known
* schema. This makes more sense because this class assumes the structure
* to be known after it has been validated.
*
* @return boolean $valid
*/
public function validate() {
global $user;
if ($this->valid === NULL) {
$ret = TRUE;
if ($this->xml == NULL) {
$this->fetchXml();
}
// figure out if we're dealing with a new or old schema
$rootEl = $this->xml->firstChild;
if (!$rootEl->hasAttributes() || $rootEl->attributes->getNamedItem('schemaLocation') === NULL) {
//$tmpname = substr($this->pid, strpos($this->pid, ':') + 1);
$tmpname = user_password(10);
$this->convertFromOldSchema();
drupal_add_js("fedora_repository_print_new_schema_$tmpname = function(tagID) {
var target = document.getElementById(tagID);
var content = target.innerHTML;
var text = '<html><head><title>Title' +
'</title><body>' + content +'</body></html>';
printerWindow = window.open('', '', 'toolbar=no,location=no,' + 'status=no,menu=no,scrollbars=yes,width=650,height=400');
printerWindow.document.open();
printerWindow.document.write(text);
}", 'inline');
if (user_access('administer site configuration')) {
drupal_set_message('<span id="new_schema_' . $tmpname . '" style="display: none;">' . htmlentities($this->xml->saveXML()) . '</span>Warning: XMLDatastream performed conversion of \'' . $this->getIdentifier() . '\' from old schema. Please update the datastream. The new datastream contents are <a href="javascript:fedora_repository_print_new_schema_' . $tmpname . '(\'new_schema_' . $tmpname . '\')">here.</a> ');
}
$rootEl = $this->xml->firstChild;
}
$schemaLocation = NULL;
if ($this->forceSchema) {
// hack because you cant easily get the static property value from
// a subclass.
$vars = get_class_vars(get_class($this));
$schemaLocation = $vars['SCHEMA_URI'];
}
elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) {
//figure out where the schema is located and validate.
list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue);
}
$schemaLocation = NULL;
return TRUE;
if ($schemaLocation !== NULL) {
if (!$this->xml->schemaValidate($schemaLocation)) {
$ret = FALSE;
$errors = libxml_get_errors();
foreach ($errors as $err) {
self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message;
}
}
else {
$this->name = $rootEl->attributes->getNamedItem('name')->nodeValue;
}
}
else {
$ret = FALSE;
self::$errors[] = 'Unable to load schema.';
}
$this->valid = $ret;
}
return $this->valid;
}
}

28
islandora_basic_collection/includes/DeleteCollection.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* DeleteCollection.inc
*/
/**
*
* @param array $form_state
@ -12,9 +17,14 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
$potential_collections = get_collections_as_option_array();
$table = islandora_collection_table($pid);
$deletion_message = ($table) ? "Delete Members of this Collection" : "Delete Collection";
$submit_text_message = ($table) ? "Delete Selected Objects" : "Delete Collection";
$submit_text_message = ($table) ? "Delete selected objects" : "Delete collection";
$form = array();
$form['collection_delete']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Delete objects from @collection_pid", array('@collection_pid' => $pid)),
);
if ($table) {
$form['collection_delete']['table'] = array(
@ -49,10 +59,10 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user;
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$collection_pid = $form_state['values']['current'];
$fedora_object = new FedoraObject($collection_pid, $restConnection->repository);
$fedora_object = new FedoraObject($collection_pid, $rest_connection->repository);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
$parents = Islandora_collections_get_collection_from_pid($collection_pid);
$collection_pid = $form_state['values']['current'];
@ -75,18 +85,18 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
}
}
if (!empty($populated_child_collections)) {
$conflict = false;
$conflict = FALSE;
foreach ($populated_child_collections as $collection) {
if (in_array($collection, $pids)) {
$conflict = true;
drupal_set_message("Populated child collections were not deleted.");
$conflict = TRUE;
drupal_set_message(t("Populated child collections were not deleted."));
}
}
}
$pids_to_delete = array_diff($pids, $populated_child_collections);
foreach ($pids_to_delete as $pid_to_delete) {
$restConnection->repository->purgeObject($pid_to_delete);
$rest_connection->repository->purgeObject($pid_to_delete);
}
drupal_goto("islandora/object/" . $collection_pid);
}
@ -94,8 +104,8 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
function delete_root_collection($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
try {
$restConnection = new RestConnection();
$restConnection->repository->purgeObject($pid);
$rest_connection = new RestConnection();
$rest_connection->repository->purgeObject($pid);
} catch (Exception $e) {
drupal_set_message(t("Collection '@pid' could not be deleted!", array('@pid' => $pid)), 'error');
return;

47
islandora_basic_collection/includes/ManagePolicies.inc

@ -1,30 +1,37 @@
<?php
/**
* @file
* ManagePolicies.inc
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $collection_pid
* @return type
*/
function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$content_models = get_content_models_list($collection_pid);
$cm_options = array();
$name_mappings = array();
foreach ($content_models as $content_model) {
if ($content_model != "islandora:collectionCModel") {
$item = new FedoraObject($content_model, $restConnection->repository);
$item = new FedoraObject($content_model, $rest_connection->repository);
$cm_name = $item->Label;
$cm_options[$content_model] = $cm_name;
}
}
$new_options = array();
if (is_array($content_models) && is_array($cm_options)) {
$new_options = array_diff_key($content_models, $cm_options);
}
$namespace = substr($collection_pid, 0, strpos($collection_pid, ":"));
$collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY');
$collection_object = new FedoraObject($collection_pid, $restConnection->repository);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$collection_policy_string = $collection_object->getDatastream($collection_policy_dsid);
$supported_collection_models = array();
@ -50,6 +57,11 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
$new_options = array_diff_key($new_content_models, $current_models_in_policy);
}
$form['manage_collection_policy']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Manage collection policy for @collection_pid", array('@collection_pid' => $collection_pid)),
);
$form ['manage_collection_policy']['add']['content_model_to_add'] = array(
'#title' => "Choose Content Model",
'#type' => 'select',
@ -77,7 +89,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
$form['manage_collection_policy']['add']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Content Model to Collection Policy'),
'#value' => t('Add content model to collection policy'),
'#id' => 'add_cm'
);
@ -96,10 +108,9 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
'#description' => t("Choose content models to remove from this collection policy."),
);
$form['manage_collection_policy']['remove']['submit'] = array(
'#type' => 'submit',
'#value' => t('Remove Content Model From Collection Policy'),
'#value' => t('Remove content model from collection policy'),
'#id' => 'remove_cm'
);
}
@ -107,16 +118,15 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
}
function islandora_manage_policies_form_validate($form, &$form_state) {
}
function islandora_manage_policies_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora_basic_collection', 'CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$collection_pid = $form_state['values']['parent_collection'];
$collection_object = new FedoraObject($collection_pid, $restConnection->repository);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'));
$collection_policy = '<?xml version="1.0" encoding="UTF-8"?>
<collection_policy xmlns="http://www.islandora.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="" xsi:schemaLocation="http://www.islandora.ca http://syn.lib.umanitoba.ca/collection_policy.xsd">
@ -143,7 +153,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$cp_namespace = $form_state['values']['new_cp_namespace'];
$cp_content_model = $form_state['values']['content_model_to_add'];
$content_model_object = new FedoraObject($cp_content_model, $restConnection->repository);
$content_model_object = new FedoraObject($cp_content_model, $rest_connection->repository);
$content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
@ -160,7 +170,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML());
$new_collection_policy_datastream->label = 'COLLECTION_POLICY';
$collection_object->ingestDatastream($new_collection_policy_datastream);
drupal_set_message("Collection model successfully added");
drupal_set_message(t("Collection model @model successfully added", array('@model' => $content_model_object->label)));
}
//remove content model from collection policy
@ -170,7 +180,6 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$s = '';
foreach ($candidates as $candidate) {
if (is_string($candidate)) {
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
$models = $content_models_element->item(0)->getElementsByTagName('content_model');
$found = FALSE;
@ -195,7 +204,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
if ($count > 1) {
$s = 's';
}
drupal_set_message("$count collection model$s removed");
drupal_set_message(t("$count collection model@s removed", array('@s' => $s)));
}
}
}

18
islandora_basic_collection/includes/MoveCollection.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* MoveCollection.inc
*/
/**
*
* @param array $form_state
@ -16,9 +21,14 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
}
$form = array();
$form['migrate']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Move objects from @collection_pid", array('@collection_pid' => $pid)),
);
$form['migrate']['new_collection'] = array(
'#title' => t('New Collection'),
'#description' => t("All content will be migrated from $pid to the selected collection"),
'#description' => t("All content will be migrated from @pid to the selected collection", array('@pid' => $pid)),
'#type' => 'select',
'#options' => $potential_collections,
);
@ -34,7 +44,7 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
'#type' => 'item',
'#value' => t(""),
);
$form['migrate']['submit'] = array(
'#type' => 'submit',
'#value' => t('Migrate selected objects'),
@ -44,13 +54,13 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
function islandora_collection_migrate_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$pids = array_filter($form_state['values']['table']);
$new_collection = $form_state['values']['new_collection'];
$current = $form_state['values']['current'];
foreach ($pids as $pid) {
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$fedora_object = new FedoraObject($pid, $rest_connection->repository);
$fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current);
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection);
}

61
islandora_basic_collection/islandora_basic_collection.install

@ -1,95 +1,94 @@
<?php
/**
* @file islandora_basic_collection.install
* @file
* islandora_basic_collection.install
*/
function islandora_basic_collection_install() {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
global $base_root;
try {
$restConnection = new RestConnection($user);
$rest_connection = new RestConnection($user);
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return;
}
$content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
$content_model_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
if (empty($content_model_query['results'])) {
try {
$xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_collection_CModel.xml');
$restConnection->api->m->ingest(array('string' => $xml));
$rest_connection->api->m->ingest(array('string' => $xml));
} catch (Exception $e) {
drupal_set_message(t('Unable to install content models %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to install content models %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Content models installed!'));
drupal_set_message(st('Content models installed!'));
}
else {
drupal_set_message(t('Content models already exist!'), 'warning');
drupal_set_message(st('Content models already exist!'), 'warning');
}
$collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root');
$collection_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:root');
if (empty($collection_query['results'])) {
try {
$xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_root_collection.xml');
$restConnection->api->m->ingest(array('string' => $xml));
$fedora_object = new FedoraObject('islandora:root', $restConnection->repository);
$datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $restConnection->repository);
$rest_connection->api->m->ingest(array('string' => $xml));
$fedora_object = new FedoraObject('islandora:root', $rest_connection->repository);
$datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $rest_connection->repository);
$file_path = $base_root . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png';
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromUrl($file_path);
$fedora_object->ingestDatastream($datastream);
} catch (Exception $e) {
drupal_set_message(t('Unable to install collections %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to install collections %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Collections installed!'));
drupal_set_message(st('Collections installed!'));
}
else {
drupal_set_message(t('Collections already exist!'), 'warning');
drupal_set_message(st('Collections already exist!'), 'warning');
}
}
function islandora_basic_collection_uninstall() {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$rest_connection = new RestConnection($user);
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return;
}
$content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
$content_model_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
if (!empty($content_model_query['results'])) {
try {
$restConnection->repository->purgeObject('islandora:collectionCModel');
$rest_connection->repository->purgeObject('islandora:collectionCModel');
} catch (Exception $e) {
drupal_set_message(t('Unable to purge content models %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to purge content models %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Content models purged!'));
drupal_set_message(st('Content models purged!'));
}
else {
drupal_set_message(t('Content models don\'t exist!'), 'warning');
drupal_set_message(st('Content models don\'t exist!'), 'warning');
}
$collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root');
$collection_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:root');
if (!empty($collection_query['results'])) {
try {
$restConnection->repository->purgeObject('islandora:root');
$rest_connection->repository->purgeObject('islandora:root');
} catch (Exception $e) {
drupal_set_message(t('Unable to purge collections %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to purge collections %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Collections purged!'));
drupal_set_message(st('Collections purged!'));
}
else {
drupal_set_message(t('Collections don\'t exist!'), 'warning');
drupal_set_message(st('Collections don\'t exist!'), 'warning');
}
}

32
islandora_basic_collection/islandora_basic_collection.module

@ -1,29 +1,30 @@
<?php
/*
* @file islandora_basic_image.module
*
* an Islandora module to handle basic image cmodels
*
*
* @file
* islandora_basic_collection.module
*
* an Islandora module to handle basic image cmodels
*
*
* This file is part of Islandora.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
/**
* Implementation of hook_menu.
* Implements hook_menu().
* we need some standard entry points so we can have consistent urls for different Object actions
*/
function islandora_basic_collection_menu() {
@ -63,7 +64,7 @@ function islandora_basic_collection_menu() {
/**
* This function is where we create the view for the related menu item
* @param type $object_id
* @return type
* @return type
*/
function islandora_basic_collection_manage_object($object_id) {
@ -73,6 +74,7 @@ function islandora_basic_collection_manage_object($object_id) {
module_load_include('inc', 'islandora_basic_collection', 'includes/MoveCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/ChildCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/ManagePolicies');
module_load_include('inc', 'islandora_basic_collection', 'includes/ChangeContentModels');
$form = array();
@ -105,9 +107,7 @@ function islandora_basic_collection_manage_object($object_id) {
'#collapsed' => TRUE,
);
$form['collection_manager']['change_content_models']['form'] = array(
// '#content' => drupal_get_form($form_id),
);
$form['collection_manager']['change_content_models']['form'] = drupal_get_form('islandora_change_content_models_form', $object_id);
$form['collection_manager']['migrate_members'] = array(
'#type' => 'fieldset',
@ -136,7 +136,7 @@ function islandora_basic_collection_manage_object($object_id) {
* determines whether or not to show this modules manage tab
* @global object $user
* @param string $object_id
* @return boolean
* @return boolean
*/
function islandora_basic_collection_access($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
@ -193,7 +193,7 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
* this module should attempt to respond.
* If ISLANDORA_VIEW_HOOK = TRUE this function will populate the default tab. This should be configurable
* in the modules admin section, otherwise two modules can populate one tab.
* @return array
* @return array
* array of content model pids that this module supports
*/
function islandora_basic_collection_islandora_get_types() {
@ -245,7 +245,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection_grid(&
/**
*
* @global type $base_url
* @param array $variables
* @param array $variables
* an array of variables that will be passed to the theme function
*/
function islandora_basic_collection_preprocess_islandora_basic_collection(&$variables) {

Loading…
Cancel
Save