Browse Source

refactored form logic

pull/386/head
Alan Stanley 11 years ago
parent
commit
f478feabb4
  1. 238
      includes/manage_deleted_objects.inc
  2. 13
      islandora.api.php
  3. 19
      islandora.module

238
includes/manage_deleted_objects.inc

@ -6,7 +6,7 @@
*/
/**
* Manages the two deletion management forms.
* The deletion management prep form.
*
* @param array $form
* The Drupal form definition.
@ -16,86 +16,71 @@
* @return array
* The Drupal form definition.
*/
function islandora_deleted_objects_form($form, &$form_state) {
if (!isset($form_state['stage'])) {
$form_state['stage'] = 'get_content_models';
function islandora_deleted_objects_prep_form($form, $form_state, $serialized_chosen = NULL) {
module_load_include('inc', 'islandora', 'includes/utilities');
$chosen_contentmodels = array();
if ($serialized_chosen) {
$chosen_contentmodels = unserialize($serialized_chosen);
}
$form = array();
switch ($form_state['stage']) {
case 'get_content_models':
$form = islandora_delete_form_contentmodels($form, $form_state);
break;
$contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members();
$elegible_contentmodels = array_keys($contentmodels_with_deleted_members);
if (empty($contentmodels_with_deleted_members)) {
$form['message'] = array(
'#type' => 'markup',
'#markup' => t("There are no deleted objects in this repository."),
);
return $form;
}
$form['message'] = array(
'#type' => 'markup',
'#markup' => t("Select content models of deleted objects."),
);
$form['mapped_contentmodels'] = array(
'#type' => 'hidden',
'#value' => $contentmodels_with_deleted_members,
);
$table_element = islandora_content_model_select_table_form_element(NULL);
case 'get_objects':
$form = islandora_delete_form_select_objects($form, $form_state);
foreach ($table_element['#options'] as $option) {
if (!in_array($option['pid'], $elegible_contentmodels)) {
unset($table_element['#options'][$option['pid']]);
}
}
break;
foreach ($table_element['#options'] as $option) {
if (array_key_exists($option['pid'], $chosen_contentmodels)) {
$table_element['#default_value'][$option['pid']] = TRUE;
}
}
$form['contentmodels'] = $table_element;
$form['next'] = array(
'#type' => 'submit',
'#value' => t('Next'),
);
return $form;
}
/**
* Submit handler for deletion management.
* Submit handler for deletion management prep form.
*
* @param array $form
* The form.
* @param array $form_state
* The form state.
*/
function islandora_deleted_objects_form_submit($form, &$form_state) {
if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') {
$form_state['rebuild'] = TRUE;
$form_state['stage'] = 'get_content_models';
return;
}
module_load_include('inc', 'islandora', 'includes/utilities');
if ($form_state['stage'] == 'get_content_models') {
$form_state['rebuild'] = TRUE;
$form_state['stage'] = 'get_objects';
return;
}
$objects_to_process = array_filter($form_state['values']['objects_to_process']);
if ($form_state['clicked_button']['#attributes']['source'] == 'restore') {
$descriptor = "Restoring";
$action = 'islandora_restore_object_by_pid';
}
if ($form_state['clicked_button']['#attributes']['source'] == 'purge') {
$descriptor = "Purging";
$action = 'islandora_purge_object_by_pid';
}
$pids_to_restore = $objects_to_process;
if ($form_state['values']['propogate']) {
foreach ($objects_to_process as $pid) {
$fedora_object = islandora_object_load($pid);
$hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models);
foreach ($hooks as $hook) {
$temp = module_invoke_all($hook, $fedora_object);
if (!empty($temp)) {
$pids_to_restore = array_merge_recursive($pids_to_restore, $temp);
}
}
}
}
$batch = array(
'title' => t('@descriptor selected objects', array('@descriptor' => $descriptor)),
'file' => drupal_get_path('module', 'islandora') . '/includes/manage_deleted_objects.inc',
'operations' => array(),
);
foreach ($pids_to_restore as $pid) {
$batch['operations'][] = array(
$action,
array($pid),
);
}
batch_set($batch);
function islandora_deleted_objects_prep_form_submit($form, $form_state) {
$content_models = $form_state['values']['contentmodels'];
$chosen = function($element) {
return $element;
};
$serialized_contentmodels = serialize(array_filter($content_models, $chosen));
drupal_goto("admin/islandora/restore/manage/$serialized_contentmodels");
}
/**
* The second form in the deletion managemnt process.
* The deletion management prep form.
*
* @param array $form
* The Drupal form definition.
@ -105,17 +90,21 @@ function islandora_deleted_objects_form_submit($form, &$form_state) {
* @return array
* The Drupal form definition.
*/
function islandora_delete_form_select_objects(array $form, array &$form_state) {
function islandora_deleted_objects_manage_form($form, $form_state, $serialized_chosen = NULL) {
$form['previous'] = array(
'#type' => 'submit',
'#value' => t('Previous'),
'#attributes' => array('source' => 'previous'),
);
$content_models = $form_state['values']['content_models'];
$valid = function($element) {
return $element;
};
$chosen_contentmodels = array_filter($content_models, $valid);
$chosen_contentmodels = unserialize($serialized_chosen);
$content_models_with_deleted = islandora_get_contentmodels_with_deleted_members();
foreach ($chosen_contentmodels as $contentmodel) {
if (!array_key_exists($contentmodel, $content_models_with_deleted)) {
unset($chosen_contentmodels[$contentmodel]);
}
}
if (empty($chosen_contentmodels)) {
$form['message'] = array(
@ -124,7 +113,32 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) {
);
return $form;
}
$options = islandora_get_deleted_objects($form_state['values']['mapped_contentmodels']);
if (is_array($chosen_contentmodels)) {
foreach ($chosen_contentmodels as $key => $value) {
if (in_array($key, $content_models_with_deleted)) {
$chosen_contentmodels[$key] = $content_models_with_deleted[$key];
}
}
}
$options = islandora_get_deleted_objects($chosen_contentmodels);
$per_page = 25;
if (count($options) < 28) {
$per_page = count($options);
}
$current_page = pager_default_initialize(count($options), $per_page);
$options_this_page = array_slice($options, $current_page * $per_page, $per_page);
foreach ($options_this_page as &$option) {
$option['content_model'] = $content_models_with_deleted[$option['content_model']];
}
$form['serialized_chosen'] = array(
'#type' => 'hidden',
'#value' => $serialized_chosen,
);
$form['pager'] = array(
'#type' => 'markup',
'#markup' => theme('pager', array('quantity', count($options))),
);
$form['propogate'] = array(
'#title' => t('Apply changes to related objects?'),
'#default_value' => TRUE,
@ -143,7 +157,7 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) {
'content_model' => t('Content Model'),
),
'#multiple' => TRUE,
'#options' => $options,
'#options' => $options_this_page,
);
$form['submit'] = array(
@ -158,62 +172,60 @@ function islandora_delete_form_select_objects(array $form, array &$form_state) {
'#attributes' => array('source' => 'purge'),
);
}
return $form;
}
/**
* The first form in the deletion management process.
* Submit handler for deletion management form.
*
* @param array $form
* The Drupal form definition.
* The form.
* @param array $form_state
* The Drupal form state.
*
* @return array
* The Drupal form definition.
* The form state.
*/
function islandora_delete_form_contentmodels(array $form, array &$form_state) {
function islandora_deleted_objects_manage_form_submit($form, $form_state) {
module_load_include('inc', 'islandora', 'includes/utilities');
$contentmodels_with_deleted_members = islandora_get_contentmodels_with_deleted_members();
$elegible_contentmodels = array_keys($contentmodels_with_deleted_members);
if (empty($contentmodels_with_deleted_members)) {
$form['message'] = array(
'#type' => 'markup',
'#markup' => t("There are no deleted objects in this repository."),
);
return $form;
}
$form['message'] = array(
'#type' => 'markup',
'#markup' => t("Select content models of deleted objects."),
);
$form['mapped_contentmodels'] = array(
'#type' => 'hidden',
'#value' => $contentmodels_with_deleted_members,
);
$table_element = islandora_content_model_select_table_form_element(NULL);
$serialized_chosen = isset($form_state['values']['serialized_chosen']) ? $form_state['values']['serialized_chosen'] : NULL;
foreach ($table_element['#options'] as $option) {
if (!in_array($option['pid'], $elegible_contentmodels)) {
unset($table_element['#options'][$option['pid']]);
}
if (isset($form_state['clicked_button']['#attributes']['source']) && $form_state['clicked_button']['#attributes']['source'] == 'previous') {
drupal_goto("admin/islandora/restore/prep/$serialized_chosen");
}
if ($form_state['clicked_button']['#attributes']['source'] == 'restore') {
$descriptor = "Restoring";
$action = 'islandora_restore_object_by_pid';
}
if ($form_state['clicked_button']['#attributes']['source'] == 'purge') {
$descriptor = "Purging";
$action = 'islandora_purge_object_by_pid';
}
if (isset($form_state['values']['chosen'])) {
$chosen_contentmodels = $form_state['values']['chosen'];
foreach ($table_element['#options'] as $option) {
if (in_array($option['pid'], $chosen_contentmodels)) {
$table_element['#default_value'][$option['pid']] = TRUE;
$objects_to_process = array_filter($form_state['values']['objects_to_process']);
$pids_to_restore = $objects_to_process;
if ($form_state['values']['propogate']) {
foreach ($objects_to_process as $pid) {
$fedora_object = islandora_object_load($pid);
$hooks = islandora_build_hook_list(ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK, $fedora_object->models);
foreach ($hooks as $hook) {
$temp = module_invoke_all($hook, $fedora_object);
if (!empty($temp)) {
$pids_to_restore = array_merge_recursive($pids_to_restore, $temp);
}
}
}
}
$form['content_models'] = $table_element;
$form['next'] = array(
'#type' => 'submit',
'#value' => t('Next'),
$batch = array(
'title' => t('@descriptor selected objects', array('@descriptor' => $descriptor)),
'file' => drupal_get_path('module', 'islandora') . '/includes/manage_deleted_objects.inc',
'operations' => array(),
);
return $form;
foreach ($pids_to_restore as $pid) {
$batch['operations'][] = array(
$action,
array($pid),
);
}
batch_set($batch);
batch_process("admin/islandora/restore/manage/$serialized_chosen");
}
/**
@ -228,7 +240,7 @@ function islandora_get_deleted_objects($content_models) {
$candidates = array_keys($content_models);
$first_contentmodel = array_shift($candidates);
$prefix = "PREFIX fm: <" . FEDORA_MODEL_URI . "> ";
$select = "SELECT ?subject ?label ?object FROM <#ri> WHERE { ";
$select = "SELECT DISTINCT ?subject ?label ?object FROM <#ri> WHERE { ";
$where_clause = "{?subject fm:hasModel <info:fedora/$first_contentmodel>;
fm:state fm:Deleted;
fm:hasModel ?object;

13
islandora.api.php

@ -650,9 +650,14 @@ function hook_CMODEL_PID_islandora_derivative() {
/**
* Retrieves PIDS of related objects for property updating.
*
* @param string $pid
* PID of object
* @param AbstractObject $object
* AbstractObject representing deleted object
*/
function hook_islandora_update_related_objects_properties($pid) {
function hook_islandora_update_related_objects_properties(AbstractObject $object) {
$related_objects = get_all_children_siblings_and_friends($object);
$pids_to_return = array();
foreach($related_objects as $related_object) {
$pids_to_return[] = $related_object->id;
}
return $pids_to_return;
}

19
islandora.module

@ -305,12 +305,22 @@ function islandora_menu() {
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
);
$items['admin/islandora/restore'] = array(
$items['admin/islandora/restore/prep'] = array(
'description' => 'Restore or permanantly remove objects with Deleted status',
'title' => 'Manage Deleted Objects',
'file' => 'includes/manage_deleted_objects.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_deleted_objects_form'),
'page arguments' => array('islandora_deleted_objects_prep_form'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS),
);
$items['admin/islandora/restore/manage'] = array(
'description' => 'Restore or permanantly remove objects with Deleted status',
'title' => 'Manage Deleted Objects',
'file' => 'includes/manage_deleted_objects.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_deleted_objects_manage_form'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(ISLANDORA_MANAGE_DELETED_OBJECTS),
);
@ -818,9 +828,7 @@ function islandora_view_object(AbstractObject $object) {
drupal_add_js(array(
'islandora' => array(
'print_link' => 'islandora/object/' . $object->id . '/print')),
array('type' => 'setting'));
'print_link' => 'islandora/object/' . $object->id . '/print')), array('type' => 'setting'));
drupal_add_js($path . '/js/add_print.js');
drupal_set_title($object->label);
@ -1500,7 +1508,6 @@ function islandora_islandora_basic_collection_get_query_filters() {
}
}
/**
* Implements hook_islandora_object_ingested().
*

Loading…
Cancel
Save