Browse Source

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

Conflicts:
	islandora.module
pull/122/merge
jonathangreen 13 years ago
parent
commit
d0d8104aea
  1. 34
      islandora.module
  2. 2
      islandora_basic_collection/includes/ChangeContentModels.inc
  3. 117
      islandora_basic_collection/includes/ChildCollection.inc
  4. 522
      islandora_basic_collection/includes/CollectionManagement.inc
  5. 12
      islandora_basic_collection/includes/DeleteCollection.inc
  6. 23
      islandora_basic_collection/includes/ManagePolicies.inc
  7. 17
      islandora_basic_collection/includes/MoveCollection.inc
  8. 4
      islandora_basic_collection/islandora-basic-collection-grid.tpl.php
  9. 32
      islandora_basic_collection/islandora-basic-collection-wrapper.tpl.php
  10. 4
      islandora_basic_collection/islandora-basic-collection.tpl.php
  11. 2
      islandora_basic_collection/islandora_basic_collection.info
  12. 56
      islandora_basic_collection/islandora_basic_collection.module
  13. 7
      islandora_basic_image/islandora_basic_image.install
  14. 8
      islandora_basic_image/xml/simple_islandora_basic_imageCM.xml

34
islandora.module

@ -191,8 +191,8 @@ function islandora_menu() {
$items['islandora/object/%/datastream/%/delete'] = array(
'title' => 'Purge data stream',
'page callback' => 'islandora_purge_datastream',
'page arguments' => array(2, 4),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_purge_datastream', 2, 4),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE),
);
@ -412,6 +412,31 @@ function islandora_islandora_edit_object($fedora_object) {
return array('Default Edit output' => $output);
}
function islandora_purge_datastream($form, &$form_state, $object_id, $datastream_id) {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'includes/datastream');
$connection = new RestConnection();
$object = $connection->repository->getObject($object_id);
$datastream = $object->getDatastream($datastream_id);
$redirect = "islandora/object/$object_id";
// Always provide entity id in the same form key as in the entity edit form.
$form['pid'] = array('#type' => 'value', '#value' => $object_id);
$form['dsid'] = array('#type' => 'value', '#value' => $datastream_id);
$form['col'] = array('#type' => 'value', '#value' => $redirect);
return confirm_form($form,
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)),
"islandora/object/$object_id",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Gives the option of purging or deleting a datastream.
*
@ -427,8 +452,10 @@ function islandora_islandora_edit_object($fedora_object) {
* ID of the datastream
*
*/
function islandora_purge_datastream($object_id, $datastream_id) {
function islandora_purge_datastream_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$object_id = $form_state['values']['pid'];
$datastream_id = $form_state['values']['dsid'];
global $user;
if (!isset($datastream_id)) {
drupal_set_message(t('Cannot remove datastream, datastream id not set'));
@ -516,6 +543,7 @@ function islandora_view_object($object_id = NULL) {
drupal_set_message(t('there was an error loading the view for islandora object %s', array('%s' => $object_id)), 'error');
return "";
}
arsort($arr);
drupal_alter('islandora_display', $arr);
$output = "";
foreach ($arr as $key => $value) {

2
islandora_basic_collection/includes/ChangeContentModels.inc

@ -46,7 +46,7 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p
$form['change_cmodel']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Change Content Models within @collection_pid", array('@collection_pid' => $collection_pid)),
'#title' => t("Change content models within @collection_pid", array('@collection_pid' => $collection_pid)),
);
$form['change_cmodel']['current_content_model'] = array(

117
islandora_basic_collection/includes/ChildCollection.inc

@ -6,11 +6,12 @@
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $this_collection_pid
* @return string
* Create the child collection creation form
*
* @param array $form
* @param array $form_state
* @param string $this_collection_pid
* @return array
*/
function islandora_create_child_collection_form($form, &$form_state, $this_collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
@ -29,13 +30,16 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
}
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
$content_models = get_content_models_as_option_array();
unset($content_models['islandora:collectionCModel']);
$form['child_creation']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Create New Child Collection within @collection", array('@collection' => $this_collection_pid)),
'#title' => t("Create new child collection within @collection", array('@collection' => $this_collection_pid)),
);
$form['child_creation']['collection_name'] = array(
'#title' => "Collection Name",
'#title' => "Collection name",
'#type' => 'textfield',
'#size' => 25,
'#description' => t("Human readable name for this collection"),
@ -51,7 +55,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
if (!$restricted) {
$form['child_creation']['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#title' => "Collection namespace",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $collection_namespace,
@ -60,7 +64,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
}
else {
$form['child_creation']['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#title' => "Collection namespace",
'#type' => 'select',
'#options' => $allowed,
'#default_value' => 'default',
@ -73,6 +77,13 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
'#value' => $this_collection_pid,
);
$form['child_creation']['content_models'] = array(
'#title' => "Choose allowable content models for this collection",
'#type' => 'checkboxes',
'#options' => $content_models,
'#description' => t("Content models describe the behaviours of objects with which they are associated."),
);
$form['child_creation']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create collection'),
@ -82,39 +93,67 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
}
function islandora_create_child_collection_form_validate($form, &$form_state) {
}
/**
* Submit handler for child collection creation form
*
* @global type $base_url
* @param array $form
* @param array $form_state
*/
function islandora_create_child_collection_form_submit($form, &$form_state) {
global $base_url;
module_load_include('inc', 'islandora', '/includes/islandora.ingest');
$thumbnail = $base_url . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png';
$new_collection_pid = $form_state['values']['new_collection_pid'];
$new_collection_label = $form_state['values']['collection_name'];
$namespace = $form_state['values']['collection_namespace'];
// $all_cModels = get_content_models_as_option_array();
$content_models = array(array('pid' => 'islandora:collectionCModel'));
$relationship = 'isMemberOfCollection';
$fedora_object = islandora_ingest_get_object($content_models, $form_state['values']['current'], $relationship, $new_collection_pid);
$fedora_object->label = $new_collection_label;
$thumbnail_datastream = $fedora_object->constructDatastream('TN');
$thumbnail_datastream->setContentFromUrl($thumbnail);
$thumbnail_datastream->label = 'Thumbnail';
$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) {
// if ($content_model) {
// $node = $collection_policy_xml->content_models->addChild('content_model');
// $node->addAttribute('dsid', 'ISLANDORACM');
// $node->addAttribute('name', $all_cModels[$content_model]);
// $node->addAttribute('namespace', $pid_namespace . ':1');
// $node->addAttribute('pid', $content_model);
// }
// }
drupal_goto('/islandora/object/' . $new_collection_pid);
$thumbnail = $base_url . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png';
$new_collection_pid = $form_state['values']['new_collection_pid'];
$new_collection_label = $form_state['values']['collection_name'];
$namespace = $form_state['values']['collection_namespace'];
$all_cModels = get_content_models_as_option_array();
$collection_content_models = array(array('pid' => 'islandora:collectionCModel'));
$relationship = 'isMemberOfCollection';
$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">
<content_models>
<content_model dsid="ISLANDORACM" name="Islandora Collection Model ~ islandora:collectionCModel" namespace="islandora:1" pid="islandora:collectionCModel"/>
</content_models>
<search_terms>
</search_terms>
<staging_area></staging_area>
<relationship>isMemberOfCollection</relationship>
</collection_policy>';
$content_models = $form_state['values']['content_models'];
$collection_policy_xml = new DOMDocument();
$collection_policy_xml->loadXML($collection_policy);
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
$content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model');
foreach ($content_models as $content_model) {
if ($content_model) {
$content_model_element = $collection_policy_xml->createElement('content_model');
$content_model_element->setAttribute('name', $all_cModels[$content_model]);
$content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_model_element->setAttribute('namespace', $namespace . ':1');
$content_model_element->setAttribute('pid', $content_model);
$content_models_element->item(0)->appendChild($content_model_element);
}
}
$fedora_object = islandora_ingest_get_object($collection_content_models, $form_state['values']['current'], $relationship, $new_collection_pid);
$fedora_object->label = $new_collection_label;
$thumbnail_datastream = $fedora_object->constructDatastream('TN');
$thumbnail_datastream->setContentFromUrl($thumbnail);
$thumbnail_datastream->label = 'Thumbnail';
$thumbnail_datastream->mimetype = 'image/png';
$fedora_object->ingestDatastream($thumbnail_datastream);
$policy_datastream = $fedora_object->constructDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'), 'X');
$policy_datastream->setContentFromString($collection_policy_xml->saveXML());
$policy_datastream->label = 'Collection policy';
$fedora_object->ingestDatastream($policy_datastream);
$new_fedora_object = islandora_ingest_add_object($fedora_object);
drupal_goto('/islandora/object/' . $new_collection_pid);
}

522
islandora_basic_collection/includes/CollectionManagement.inc

@ -3,433 +3,9 @@
/**
* @file
* CollectionManagement.inc
* A set of useful functions to help with collection management
*/
/**
* collection creation form
* @param array $form_state
* @param string $parent_collection_pid
* @param string $content_models
* @return array
*/
function collection_management_form($this_collection_pid, $content_models) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$restricted = FALSE;
if (variable_get('fedora_namespace_restriction_enforced', TRUE)) {
$restricted = TRUE;
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[trim($namespace)] = trim($namespace);
}
}
}
$collection_policy = CollectionPolicy::loadFromCollection($this_collection_pid);
if ($collection_policy) {
$supported_collection_models = $collection_policy->getContentModels();
}
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
$represented_content_models = get_represented_content_models($this_collection_pid);
$item = new Fedora_Item($this_collection_pid);
$collection_name = $item->objectProfile->objLabel;
$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;
}
}
$cm_options = array();
$name_mappings = array();
foreach ($content_models as $content_model) {
if ($content_model->pid != "islandora:collectionCModel") {
$item = new fedora_item($content_model->pid);
$cm_name = $item->objectProfile->objLabel;
$cm_options[$content_model->pid] = $cm_name;
}
}
if (!empty($current_models_in_policy)) {
$show_delete = TRUE;
}
$content_models = get_content_models_as_option_array();
unset($content_models['islandora:collectionCModel']);
$form['child_creation'] = array(
'#title' => "Create Child Collection",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['child_creation']['titlebox'] = array(
'#type' => 'item',
'#value' => t("Create New Child Collection within $this_collection_pid"),
);
$form['child_creation']['collection_name'] = array(
'#title' => "Collection Name",
'#type' => 'textfield',
'#description' => t("Human readable name for this collection"),
);
$form['child_creation']['new_collection_pid'] = array(
'#title' => "Collection PID",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => Fedora_Item::get_next_PID_in_namespace($collection_namespace),
'#description' => t("Unique PID for this collection. <br />Pids take the general form of namespace:collection eg islandora:pamphlets"),
);
if (!$restricted) {
$form['child_creation']['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $collection_namespace,
'#description' => t("Namespace for objects in this collection."),
);
}
else {
$form['child_creation']['collection_namespace'] = array(
'#title' => "Collection Namespace",
'#type' => 'select',
'#options' => $allowed,
'#default_value' => 'default',
'#description' => t("Namespace for objects in this collection."),
);
}
$form['parent_collection'] = array(
'#type' => 'hidden',
'#value' => $this_collection_pid,
);
$form['collection_pid'] = array(
'#type' => 'hidden',
'#value' => $this_collection_pid,
);
$form['child_creation']['content_models'] = array(
'#title' => "Choose allowable content models for this collection",
'#type' => 'checkboxes',
'#options' => $content_models,
'#description' => t("Content models describe the behaviours of objects with which they are associated."),
);
$form['child_creation']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create Collection'),
'#id' => 'create_child'
);
$form['manage_collection_policy'] = array(
'#title' => "Manage Collection Policies",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['manage_collection_policy']['add'] = array(
'#title' => "Add Content Model to Collection Policy",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => $show_delete,
);
$new_options = array();
if (is_array($content_models) && is_array($cm_options)) {
$new_options = array_diff_key($content_models, $cm_options);
}
$form ['manage_collection_policy']['add']['content_model_to_add'] = array(
'#title' => "Choose Content Model",
'#type' => 'select',
'#options' => $new_options,
'#description' => t("Choose content model to add to this collection policy."),
);
$form ['manage_collection_policy']['add']['new_cp_namespace'] = array(
'#title' => "Choose Namespace",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $collection_namespace,
'#description' => t("Choose namespace for objects in this collection associated with this content model"),
);
$form['manage_collection_policy']['add']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Content Model to Collection Policy'),
'#id' => 'add_cm'
);
if (count($current_models_in_policy) > 0) {
$form['manage_collection_policy']['remove'] = array(
'#title' => "Delete Content Model from Collection Policy",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form ['manage_collection_policy']['remove']['content_models_to_remove'] = array(
'#title' => "Choose Content Model to Remove",
'#type' => 'checkboxes',
'#options' => $current_models_in_policy,
'#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'),
'#id' => 'remove_cm'
);
}
$form['change_cmodel'] = array(
'#title' => "Change Content Models",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['change_cmodel']['titlebox'] = array(
'#type' => 'item',
'#value' => t("Change Content Models within $this_collection_pid"),
);
$form['change_cmodel']['current_content_model'] = array(
'#title' => "Choose content model to be changed",
'#type' => 'select',
'#options' => $represented_content_models,
'#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' => $this_collection_pid,
);
$form['change_cmodel']['submit'] = array(
'#type' => 'submit',
'#value' => t('Change Content Model Associations'),
'#id' => 'change_model',
);
return $form;
}
/**
* collection creation form validate
* @param array $form
* @param array $form_state
*/
function collection_management_form_validate($form, &$form_state) {
if ($form_state['clicked_button']['#id'] == 'create_child') {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$pid = $form_state['values']['new_collection_pid'];
$item = new fedora_item($pid);
$needs_model = FALSE;
foreach ($form_state['values']['content_models'] as $key => $value) {
if (is_string($value)) {
$needs_model = FALSE;
}
}
$checked = array_values($form_state['values']['content_models']);
if ($item->exists()) {
form_set_error('new_collection_pid', t("$pid already exists within your repository. the PID must be unique. Click on 'Manage This Collection' tab and enter new value."));
return;
}
if (!valid_pid($pid)) {
form_set_error('new_collection_pid', t("$pid is not a valid identifier. Click on 'Manage This Collection' tab and enter new value."));
return;
}
if ($needs_model) {
form_set_error('content_models', t("At least one content model must be selected. Click on 'Manage This Collection' tab and enter content model."));
return;
}
}
if ($form_state['clicked_button']['#id'] == 'add_cm') {
$name_parts = explode(":", $form_state['values']['new_cp_namespace']);
$namespace = $name_parts[0] . ":1";
if (!valid_pid($namespace)) {
form_set_error('new_cp_namespace', t("Namespace must be valid. Click on 'Manage This Collection' tab and enter new value."));
return;
}
$form_state['values']['new_cp_namespace'] = $namespace;
}
}
/**
* collection creation form submit
* @global user $user
* @param arary $form
* @param array $form_state
*/
function collection_management_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/dublin_core');
global $user;
$collection_pid = $form_state['values']['parent_collection'];
$policy = CollectionPolicy::loadFromCollection($collection_pid, TRUE);
$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">
<content_models>
<content_model dsid="ISLANDORACM" name="Islandora Collection Model ~ islandora:collectionCModel" namespace="islandora:1" pid="islandora:collectionCModel"/>
</content_models>
<search_terms>
</search_terms>
<staging_area></staging_area>
<relationship>isMemberOfCollection</relationship>
</collection_policy>';
// add child collection to policy
if ($form_state['clicked_button']['#id'] == 'create_child') {
$module_path = drupal_get_path('module', 'fedora_repository');
$thumbnail = drupal_get_path('module', 'Fedora_Repository') . '/images/Crystal_Clear_filesystem_folder_grey.png';
$new_collection_pid = $form_state['values']['new_collection_pid'];
$new_collection_label = $form_state['values']['collection_name'];
$pid_namespace = $form_state['values']['collection_namespace'];
$all_cModels = get_content_models_as_option_array();
$content_models = $form_state['values']['content_models'];
$collection_policy_xml = simplexml_load_string($collection_policy);
foreach ($content_models as $content_model) {
if ($content_model) {
$node = $collection_policy_xml->content_models->addChild('content_model');
$node->addAttribute('dsid', 'ISLANDORACM');
$node->addAttribute('name', $all_cModels[$content_model]);
$node->addAttribute('namespace', $pid_namespace . ':1');
$node->addAttribute('pid', $content_model);
}
}
$item = fedora_item::ingest_new_item($new_collection_pid, 'A', $new_collection_label, $user->name);
$item->add_relationship('isMemberOfCollection', $collection_pid, RELS_EXT_URI);
$item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI);
$item->add_datastream_from_string($collection_policy_xml->saveXML(), 'COLLECTION_POLICY', 'COLLECTION_POLICY', 'text/xml', 'X');
$item->add_datastream_from_file($thumbnail, 'TN');
drupal_goto("/fedora/repository/$new_collection_pid");
}
// add content model to collection policy
if ($form_state['clicked_button']['#id'] == 'add_cm') {
if (!$policy) {
$item = new Fedora_Item($collection_pid);
$item->add_datastream_from_string($collection_policy, 'COLLECTION_POLICY', 'COLLECTION_POLICY', 'text/xml', 'X');
$policy = CollectionPolicy::loadFromCollection($collection_pid, TRUE);
}
$cp_namespace = $form_state['values']['new_cp_namespace'];
$cp_content_model = $form_state['values']['content_model_to_add'];
$policy->addModel(ContentModel::loadFromModel($cp_content_model), $cp_namespace);
$policy->saveToFedora();
drupal_set_message("Collection model successfully added");
}
//remove content model from collection policy
if ($form_state['clicked_button']['#id'] == 'remove_cm') {
$candidates = $form_state['values']['content_models_to_remove'];
$count = 0;
foreach ($candidates as $candidate) {
if (is_string($candidate)) {
$policy->removeModel(ContentModel::loadFromModel($candidate));
$count++;
}
}
if ($count > 0) {
$policy->saveToFedora();
if ($count > 1) {
$s = 's';
}
drupal_set_message("$count collection model$s removed");
}
}
//change content model on selected objects
if ($form_state['clicked_button']['#id'] == 'change_model') {
$current_content_model = $form_state['values']['current_content_model'];
$new_content_model = $form_state['values']['new_content_model'];
$add_to_policy = TRUE;
$policy_cms = $policy->getContentModels();
foreach ($policy_cms as $policy_cm) {
if ($policy_cm->pid == $current_content_model) {
$namespace = $policy_cm->pid_namespace;
}
if ($policy_cm->pid == $new_content_model) {
$add_to_policy = FALSE;
}
}
if ($add_to_policy) {
$policy->addModel(ContentModel::loadFromModel($new_content_model), $namespace);
$policy->saveToFedora();
}
$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>)";
$query = htmlentities(urlencode($query));
$content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query;
$content .= do_curl($url);
$results = explode("\n", $content);
$object_pids = preg_replace('/^info:fedora\/|"object"/', '', $results);
$count = 0;
foreach ($object_pids as $object_pid) {
if (!$object_pid) {
continue;
}
$item = new fedora_item($object_pid);
$item->purge_relationship('hasModel', $current_content_model);
$item->add_relationship('hasModel', $new_content_model, FEDORA_MODEL_URI);
$count++;
}
drupal_set_message("$current_content_model changed to $new_content_model on $count objects");
}
}
/**
* deletes PID
* @param string $pid
*/
function delete_objects_as_batch($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
$name = $user->name;
$rest_connection->repository->purgeObject($pid);
}
/**
* removes association of this object to this collection
* @param string $pid
*/
function remove_collection_association($pid, $collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
$fedora_object = new FedoraObject($pid, $rest_connection->repository);
$fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid);
}
/**
* returns content models associated with all objects in a collection
* @param string $pid
@ -475,7 +51,7 @@ EOD;
return $collection_pids;
}
function Islandora_collections_get_collection_from_pid($pid) {
function islandora_collections_get_collection_from_pid($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
@ -505,7 +81,9 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
global $user;
// if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
// Not sure if this is necessary given that we should never be able to delete objects in a namespace that we don't have access to.
// if (!fedora_repository_access('view fedora repository', $collection_pid['object']['value'])) {
// drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
// return array();
// }
@ -547,20 +125,43 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
}
//function get_related_items_as_array($collection_pid, $relationship = 'isMemberOfCollection', $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') {
// $content = get_related_items_as_xml($collection_pid, $relationship, $limit, $offset, $active_objects_only, $cmodel, $orderby);
// if (empty($content)) {
// return array();
// }
//
// $content = new SimpleXMLElement($content);
//
// $resultsarray = array();
// foreach ($content->results->result as $result) {
// $resultsarray[] = substr($result->object->attributes()->uri, 12); // Remove 'info:fedora/'.
// }
// return $resultsarray;
//}
/**
* determines whether we can see the object or not
* checks PID namespace permissions, and user permissions
* @global type $user
* @param type $op
* @param type $pid
* @return type
*/
function fedora_repository_access($permission, $pid) {
global $user;
$name_space_access = FALSE;
$is_restricted = variable_get('islandora_namespace_restriction_enforced', TRUE);
if (!$is_restricted) {
$name_space_access = TRUE;
}
if ($pid == NULL) {
$pid = variable_get('islandora_repository_pid', 'islandora:root');
}
$name_space_allowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$pos = NULL;
foreach ($name_space_allowed as $name_space) {
$pos = stripos($pid, $name_space);
if ($pos === 0) {
$name_space_access = TRUE;
}
}
if ($name_space_access) {
$user_access = user_access($permission);
if ($user_access == NULL) {
return FALSE;
}
return $user_access;
}
else {
return FALSE;
}
}
/**
* gets the name of the content models for the specified object
@ -570,9 +171,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
* @return array
*/
function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) {
// module_load_include('inc', 'fedora_repository', 'CollectionClass');
// module_load_include('inc', 'fedora_repository', 'ContentModel');
// $collectionHelper = new CollectionClass();
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$rest_connection = new RestConnection();
@ -580,7 +179,6 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
$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 = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
if (empty($content_models)) {
@ -593,16 +191,12 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe
continue;
}
$cmodels[] = substr(strstr($content_model['object']['uri'], '/'), 1);
// $cm = ContentModel::loadFromModel($cmodel_pid);
// if ($cm) {
// $cmodels[] = $cm;
// }
}
return $cmodels;
}
/**
/**
* Function: get_content_models_as_option_array
*
* Description: Returns an associative array of all available content models in Fedora instance
@ -644,30 +238,4 @@ function get_content_models_as_option_array() {
}
return $options;
}
function getContentModels($collection_pid, $showError = TRUE) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();
// module_load_include('inc', 'Fedora_Repository', 'ContentModel');
$collection_stream = $this->getCollectionPolicyStream($collection_pid);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$collection_stream = $collection_object->getDatastream('COLLECTION_POLICY');
try {
$xml = new SimpleXMLElement($collection_stream);
} catch (Exception $e) {
if ($showError) {
drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))), 'error');
}
return NULL;
}
foreach ($xml->contentmodels->contentmodel as $content_model) {
$contentModel = new ContentModel();
$contentModel->contentModelDsid = $content_model->dsid;
$contentModel->contentModelPid = $content_model->pid;
$contentModel->pidNamespace = $content_model->pidNamespace;
$contentModel->contentModelName = $content_model['name'];
$models[] = $contentModel;
}
return $models;
}
}

12
islandora_basic_collection/includes/DeleteCollection.inc

@ -56,6 +56,13 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
return $form;
}
/**
* Submit handler for object deletion form in the collection manager.
*
* @global type $user
* @param array $form
* @param array $form_state
*/
function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user;
module_load_include('inc', 'islandora', 'RestConnection');
@ -101,6 +108,11 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
drupal_goto("islandora/object/" . $collection_pid);
}
/**
* Deletes the collection object
*
* @param string $pid
*/
function delete_root_collection($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
try {

23
islandora_basic_collection/includes/ManagePolicies.inc

@ -6,10 +6,11 @@
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $collection_pid
* Create form to collection policy management feature
*
* @param array $form
* @param array $form_state
* @param string $collection_pid
* @return type
*/
function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
@ -63,14 +64,14 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
);
$form ['manage_collection_policy']['add']['content_model_to_add'] = array(
'#title' => "Choose Content Model",
'#title' => "Choose content model",
'#type' => 'select',
'#options' => $new_options,
'#description' => t("Choose content model to add to this collection policy."),
);
$form ['manage_collection_policy']['add']['new_cp_namespace'] = array(
'#title' => "Choose Namespace",
'#title' => "Choose namespace",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $namespace,
@ -95,14 +96,14 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
if (count($current_models_in_policy) > 0) {
$form['manage_collection_policy']['remove'] = array(
'#title' => "Delete Content Model from Collection Policy",
'#title' => "Delete content model from collection policy",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form ['manage_collection_policy']['remove']['content_models_to_remove'] = array(
'#title' => "Choose Content Model to Remove",
'#title' => "Choose content model to remove",
'#type' => 'checkboxes',
'#options' => $current_models_in_policy,
'#description' => t("Choose content models to remove from this collection policy."),
@ -121,6 +122,12 @@ function islandora_manage_policies_form_validate($form, &$form_state) {
}
/**
* Submit handler for collection policy management form
*
* @param array $form
* @param array $form_state
*/
function islandora_manage_policies_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();

17
islandora_basic_collection/includes/MoveCollection.inc

@ -6,7 +6,8 @@
*/
/**
*
* Create object migration form for the collection manager
*
* @param array $form_state
* @param string $pid
*
@ -17,7 +18,11 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
$potential_collections = get_collections_as_option_array();
$table = islandora_collection_table($pid);
if (!$table) {
return;
$form['no_objects'] = array(
'#type' => 'item',
'#title' => t('No objects found in this collection'),
);
return $form;
}
$form = array();
@ -27,7 +32,7 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
);
$form['migrate']['new_collection'] = array(
'#title' => t('New Collection'),
'#title' => t('New collection'),
'#description' => t("All content will be migrated from @pid to the selected collection", array('@pid' => $pid)),
'#type' => 'select',
'#options' => $potential_collections,
@ -52,6 +57,12 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
return $form;
}
/**
* Submit handler for object migration form
*
* @param array $form
* @param array $form_state
*/
function islandora_collection_migrate_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$rest_connection = new RestConnection();

4
islandora_basic_collection/islandora-basic-collection-grid.tpl.php

@ -21,17 +21,15 @@
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
?>
<?php drupal_set_title('grid_view'); ?>
<div class="islandora-basic-collection-wrapper">
<div class="islandora-basic-collection clearfix">
<?php print($variables['pager']); ?>
<?php foreach($associated_objects_array as $key => $value): ?>
<dl class="islandora-basic-collection-object <?php print $value['class']; ?>">
<dt class="islandora-basic-collection-thumb"><?php print $value['thumb_link']; ?></dt>
<dd class="islandora-basic-collection-caption"><?php print $value['title_link']; ?></dd>
</dl>
<?php endforeach; ?>
<?php print($variables['pager']); ?>
</div>
</div>

32
islandora_basic_collection/islandora-basic-collection-wrapper.tpl.php

@ -0,0 +1,32 @@
<?php
/*
* islandora-basic-collection-wrapper.tpl.php
*
*
*
* 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/>.
*/
?>
<?php drupal_set_title($islandora_object->label); ?>
<div class="islandora-basic-collection-wrapper">
<div class="islandora-basic-collection clearfix">
<?php print($collection_pager); ?>
<?php print ($collection_content); ?>
<?php print($collection_pager); ?>
</div>
</div>

4
islandora_basic_collection/islandora-basic-collection.tpl.php

@ -24,14 +24,12 @@
<?php drupal_set_title($islandora_object->label); ?>
<div class="islandora-basic-collection-wrapper">
<div class="islandora-basic-collection clearfix">
<?php print($variables['pager']); ?>
<div class="islandora-basic-collection clearfix">
<?php foreach($associated_objects_array as $key => $value): ?>
<dl class="islandora-basic-collection-object <?php print $value['class']; ?>">
<dt class="islandora-basic-collection-thumb"><?php print $value['thumb_link']; ?></dt>
<dd class="islandora-basic-collection-caption"><?php print $value['title_link']; ?></dd>
</dl>
<?php endforeach; ?>
<?php print($variables['pager']); ?>
</div>
</div>

2
islandora_basic_collection/islandora_basic_collection.info

@ -4,4 +4,4 @@ dependencies[] = islandora
package = Islandora
core = 7.x
stylesheets[all][] = css/islandora_basic_collection.base.css
stylesheets[all][] = css/islandora_basic_collection.theme.css
stylesheets[all][] = css/islandora_basic_collection.theme.css

56
islandora_basic_collection/islandora_basic_collection.module

@ -30,7 +30,7 @@
function islandora_basic_collection_menu() {
$items = array();
$items['islandora/object/%/manage/collection'] = array(
'title' => 'Collection Related',
'title' => 'Collection related',
'page callback' => 'islandora_basic_collection_manage_object',
'page arguments' => array(2),
'type' => MENU_LOCAL_TASK,
@ -39,7 +39,7 @@ function islandora_basic_collection_menu() {
);
$items['admin/islandora/basic_collection'] = array(
'title' => 'Islandora Basic Collection',
'title' => 'Islandora basic collection',
'description' => 'Configure the basic Collection solution pack.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
@ -105,7 +105,7 @@ function islandora_basic_collection_manage_object($object_id) {
);
$form['collection_manager']['create_child_collection'] = array(
'#title' => t('Create Child Collection'),
'#title' => t('Create child collection'),
'#type' => 'fieldset',
);
@ -113,7 +113,7 @@ function islandora_basic_collection_manage_object($object_id) {
$form['collection_manager']['manage_policies'] = array(
'#type' => 'fieldset',
'#title' => t('Manage Collection Policies'),
'#title' => t('Manage collection policies'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
@ -122,7 +122,7 @@ function islandora_basic_collection_manage_object($object_id) {
$form['collection_manager']['change_content_models'] = array(
'#type' => 'fieldset',
'#title' => t('Change Content Models'),
'#title' => t('Change content models'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
@ -131,7 +131,7 @@ function islandora_basic_collection_manage_object($object_id) {
$form['collection_manager']['migrate_members'] = array(
'#type' => 'fieldset',
'#title' => t('Migrate Members'),
'#title' => t('Migrate members'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
@ -140,16 +140,17 @@ function islandora_basic_collection_manage_object($object_id) {
$form['collection_manager']['delete_members'] = array(
'#type' => 'fieldset',
'#title' => t('Delete Members of this Collection'),
'#title' => t('Delete members of this collection'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['collection_manager']['delete_members']['form'] = drupal_get_form('islandora_collection_deletion_form', $object_id);
// Pass the form around any modules that are interested so that they can add their own collection management functions.
module_invoke_all('islandora_collection_manager', $form);
return $form;
// return 'Collection CModel edit function ' . $object_id;
}
/**
@ -199,6 +200,10 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
'islandora_basic_collection_grid' => array(
'template' => 'islandora-basic-collection-grid',
'pattern' => 'islandora_basic_collection_grid__',
'variables' => array('islandora_object' => NULL, 'collection_results' => NULL),
),
'islandora_basic_collection_wrapper' => array(
'template' => 'islandora-basic-collection-wrapper',
'variables' => array('islandora_object' => NULL),
),
'islandora_basic_collection_management_form_table' => array(
@ -241,13 +246,7 @@ function islandora_basic_collection_islandora_view_object($object, $user) {
$models = $object->models;
foreach ($object->models as $model) {
if (isset($cmodel_list[$model][ISLANDORA_VIEW_HOOK]) && $cmodel_list[$model][ISLANDORA_VIEW_HOOK] == TRUE) {
$display = (empty($_GET['display'])) ? 'list' : $_GET['display'];
if ($display == 'grid') {
$output = theme('islandora_basic_collection_grid', array('islandora_object' => $object));
}
else {
$output = theme('islandora_basic_collection', array('islandora_object' => $object));
}
$output = theme('islandora_basic_collection_wrapper', array('islandora_object' => $object,));
return array('Collection View' => $output);
}
}
@ -263,6 +262,24 @@ function islandora_basic_collection_preprocess_islandora_basic_collection_grid(&
islandora_basic_collection_preprocess_islandora_basic_collection($variables);
}
function islandora_basic_collection_preprocess_islandora_basic_collection_wrapper(&$variables) {
$page_number = (empty($_GET['page'])) ? 0 : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? variable_get('islandora_basic_collection_page_size', '10') : $_GET['pagesize'];
$islandora_object = $variables['islandora_object'];
$results = islandora_basic_collection_get_objects($islandora_object, $page_number, $page_size);
$total_count = count($results);
pager_default_initialize($total_count, $page_size);
$variables['collection_pager'] = theme('pager', array('quantity' => 10));
$display = (empty($_GET['display'])) ? 'list' : $_GET['display'];
if ($display == 'grid') {
$collection_content = theme('islandora_basic_collection_grid', array('islandora_object' => $islandora_object, 'collection_results' => $results));
}
else {
$collection_content = theme('islandora_basic_collection', array('islandora_object' => $islandora_object, 'collection_results' => $results));
}
$variables['collection_content'] = $collection_content;
}
/**
*
* @global type $base_url
@ -284,12 +301,8 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari
}
$page_number = (empty($_GET['page'])) ? 0 : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? variable_get('islandora_basic_collection_page_size', '10') : $_GET['pagesize'];
$results = islandora_basic_collection_get_objects($islandora_object, $page_number, $page_size);
$results = $variables['collection_results'];//islandora_basic_collection_get_objects($islandora_object, $page_number, $page_size);
$total_count = count($results);
pager_default_initialize($total_count, $page_size);
$pager = theme('pager', array('quantity' => $total_count));
$variables['pager'] = $pager;
$variables['islandora_dublin_core'] = $dc_object;
$variables['islandora_object_label'] = $islandora_object->label;
$variables['theme_hook_suggestions'][] = 'islandora_basic_collection__' . str_replace(':', '_', $islandora_object->id);
@ -335,6 +348,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari
$thumbnail_img = '<img src="' . $base_path . $object_url . '/datastream/TN/view"' . '/>';
}
else {
//TODO: change this default image url
$thumbnail_img = '<img src="http://codesprint-centos.islandora.ca/islandora/object/islandora%3A52/datastream/TN"' . '/>';
}
$associated_objects_array[$pid]['thumbnail'] = $thumbnail_img;

7
islandora_basic_image/islandora_basic_image.install

@ -1,7 +1,8 @@
<?php
/**
* @file islandora-basic-image.install
* @file
* islandora-basic-image.install
*/
/**
@ -58,6 +59,10 @@ function islandora_basic_image_install() {
}
}
/**
* Implements hook_uninstall
*/
function islandora_basic_image_uninstall() {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;

8
islandora_basic_image/xml/simple_islandora_basic_imageCM.xml

@ -39,9 +39,6 @@ PID="islandora:sp_basic_image">
<dsTypeModel ID="MODS">
<form MIME="text/xml"></form>
</dsTypeModel>
<dsTypeModel ID="ISLANDORACM">
<form MIME="text/xml" />
</dsTypeModel>
</dsCompositeModel>
</foxml:xmlContent>
</foxml:datastreamVersion>
@ -67,9 +64,4 @@ PID="islandora:sp_basic_image">
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
<foxml:datastream ID="ISLANDORACM" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true"> <!-- should the ISLANDORACM be a managed DS ? No -->
<foxml:datastreamVersion ID="ISLANDORACM.0" LABEL="ISLANDORACM" CREATED="2012-04-26T13:37:58.433Z" MIMETYPE="text/xml" SIZE="5745">
<foxml:contentLocation TYPE="INTERNAL_ID" REF="islandora:sp_basic_image+ISLANDORACM+ISLANDORACM.0"/>
</foxml:datastreamVersion>
</foxml:datastream>
</foxml:digitalObject>
Loading…
Cancel
Save