Browse Source

Added 'create child' and 'manage content model' functions to collection management

pull/112/head
rwincewicz 13 years ago
parent
commit
6c7aeefcf5
  1. 109
      islandora_basic_collection/includes/ChildCollection.inc
  2. 82
      islandora_basic_collection/includes/CollectionManagement.inc
  3. 4
      islandora_basic_collection/includes/DeleteCollection.inc
  4. 61
      islandora_basic_collection/includes/ManagePolicies.inc
  5. 5
      islandora_basic_collection/includes/MoveCollection.inc
  6. 28
      islandora_basic_collection/islandora_basic_collection.module

109
islandora_basic_collection/includes/ChildCollection.inc

@ -0,0 +1,109 @@
<?php
function islandora_create_child_collection_form($form, &$form_state, $this_collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$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_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)),
);
$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' => $restConnection->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)"),
);
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['current'] = array(
'#type' => 'hidden',
'#value' => $this_collection_pid,
);
$form['child_creation']['submit'] = array(
'#type' => 'submit',
'#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) {
global $base_root;
module_load_include('inc', 'islandora', '/includes/islandora.ingest');
$thumbnail = $base_root . '/' . 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('islandora:collectionCModel');
$relationship = array(
'uri' => FEDORA_RELS_EXT_URI,
'value' => '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);
}

82
islandora_basic_collection/includes/CollectionManagement.inc

@ -481,4 +481,84 @@ function Islandora_collections_get_collection_from_pid($pid) {
$object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$object_pids = array_values(array_filter($object_pids));
return $object_pids;
}
}
/**
* Returns an array of pids that match the query contained in the collection
* object's QUERY datastream or in the suppled $query parameter.
* @param <type> $collection_pid
* @param <type> $query
* @param <type> $query_format R
*/
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', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
global $user;
// if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) {
// drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error');
// return array();
// }
$query_string = 'select $object $title $content from <#ri>
where ($object <fedora-model:label> $title
and $object <fedora-model:hasModel> $content
and (';
if (is_array($relationship)) {
foreach ($relationship as $rel) {
$query_string .= '$object <fedora-rels-ext:' . $rel . '> <info:fedora/' . $collection_pid . '>';
if (next($relationship)) {
$query_string .= ' OR ';
}
}
}
elseif (is_string($relationship)) {
$query_string .= '$object <fedora-rels-ext:' . $relationship . '> <info:fedora/' . $collection_pid . '>';
}
else {
return '';
}
$query_string .= ') ';
$query_string .= $active_objects_only ? 'and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>' : '';
if ($cmodel) {
$query_string .= ' and $content <mulgara:is> <info:fedora/' . $cmodel . '>';
}
$query_string .= ')
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by ' . $orderby;
// $query_string = htmlentities(urlencode($query_string));
//
//
// $content = '';
// $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
// $url .= "?type=tuples&flush=TRUE&format=Sparql&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query_string;
// $content .= do_curl($url);
$results = $restConnection->repository->ri->itqlQuery($query_string, $limit, $offset);
return $results;
}
//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;
//}

4
islandora_basic_collection/includes/DeleteCollection.inc

@ -97,8 +97,8 @@ function delete_root_collection($pid) {
$restConnection = new RestConnection();
$restConnection->repository->purgeObject($pid);
} catch (Exception $e) {
drupal_set_message(t('Collection @pid could not be deleted!', array('@pid' => $pid)), 'error');
drupal_set_message(t("Collection '@pid' could not be deleted!", array('@pid' => $pid)), 'error');
return;
}
drupal_set_message(t('Collection @pid deleted.', array('@pid' => $pid)));
drupal_set_message(t("Collection '@pid' deleted.", array('@pid' => $pid)));
}

61
islandora_basic_collection/includes/ManagePolicies.inc

@ -0,0 +1,61 @@
<?php
function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
$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'
);
}
return $form;
}
function islandora_manage_policies_form_validate($form, &$form_state) {
}
function islandora_manage_policies_form_submit($form, &$form_state) {
}

5
islandora_basic_collection/includes/MoveCollection.inc

@ -30,10 +30,11 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
'#value' => $pid,
);
$form['migrate']['message'] = array(
$form['migrate']['message'] = array(
'#type' => 'item',
'#value' => t(""),
);
$form['migrate']['submit'] = array(
'#type' => 'submit',
'#value' => t('Migrate selected objects'),
@ -50,7 +51,7 @@ function islandora_collection_migrate_form_submit($form, &$form_state) {
$current = $form_state['values']['current'];
foreach ($pids as $pid) {
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$fedora_object->relationships->remove(NULL, 'isMemberOfCollection', NULL);
$fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current);
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection);
}
}

28
islandora_basic_collection/islandora_basic_collection.module

@ -30,8 +30,8 @@ function islandora_basic_collection_menu() {
$items = array();
$items['islandora/object/%/manage/collection'] = array(
'title' => 'Collection Related',
'page callback' => 'islandora_basic_collection_manage_object',
'page arguments' => array(2),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_basic_collection_manage_object', 2),
'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_basic_collection_access',
'access arguments' => array(2),
@ -71,11 +71,15 @@ function islandora_basic_collection_manage_object($object_id) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionManagerTable');
module_load_include('inc', 'islandora_basic_collection', 'includes/DeleteCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/MoveCollection');
$form = array();
module_load_include('inc', 'islandora_basic_collection', 'includes/ChildCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/ManagePolicies');
$form['collection_manager'] = array(
'#type' => 'fieldset',
);
$form = array();
$form['collection_manager'] = array(
'#type' => 'fieldset',
);
$form['collection_manager']['create_child_collection'] = array(
'#type' => 'fieldset',
@ -84,9 +88,7 @@ $form['collection_manager'] = array(
'#collapsed' => TRUE,
);
$form['collection_manager']['create_child_collection']['form'] = array(
// '#markup' => drupal_get_form('collection_management_form', $object_id),
);
$form['collection_manager']['create_child_collection']['form'] = drupal_get_form('islandora_create_child_collection_form', $object_id);
$form['collection_manager']['manage_policies'] = array(
'#type' => 'fieldset',
@ -95,9 +97,7 @@ $form['collection_manager'] = array(
'#collapsed' => TRUE,
);
$form['collection_manager']['manage_policies']['form'] = array(
// '#content' => drupal_get_form($form_id),
);
$form['collection_manager']['manage_policies']['form'] = drupal_get_form('islandora_manage_policies_form', $object_id);
$form['collection_manager']['change_content_models'] = array(
'#type' => 'fieldset',
@ -116,8 +116,8 @@ $form['collection_manager'] = array(
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['collection_manager']['migrate_members']['form'] = drupal_get_form('islandora_collection_migrate_form', $object_id);
$form['collection_manager']['migrate_members']['form'] = drupal_get_form('islandora_collection_migrate_form', $object_id);
$form['collection_manager']['delete_members'] = array(
'#type' => 'fieldset',

Loading…
Cancel
Save