Browse Source

Code cleanup - squash code pertaining to "baskets" in core

This should have been largely replaced by the MyPID module.
pull/183/head
Adam Vessey 12 years ago
parent
commit
3fcda63151
  1. 1
      ObjectHelper.inc
  2. 321
      fedora_repository.module
  3. 27
      formClass.inc

1
ObjectHelper.inc

@ -810,6 +810,7 @@ class ObjectHelper {
* Get a tree of related pids - for the basket functionality
*
* FIXME: This doesn't actually get a tree...
* XXX: Is this still required, without basket being in?
*
* @param type $pid
* @return type

321
fedora_repository.module

@ -1953,327 +1953,6 @@ function theme_fedora_repository_time($element) {
return theme('form_element', $element, $output);
}
/* Export (basket) functionality */
/**
* fedora repository remove item from basket
* @param type $pid
*/
function fedora_repository_remove_item_from_basket($pid) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$pids = empty($_SESSION['basket']['processed']) ? array() : $_SESSION['basket']['processed'];
$objectHelper = new ObjectHelper();
// getting child PIDs if any
$cpids = $objectHelper->get_child_pids(array($pid));
if (array_key_exists($pid, $pids)) {
// remove item from basket
unset($_SESSION['basket']['processed'][$pid]);
}
if (!empty($cpids)) { // there are children
foreach ($cpids as $child_pid => $value) {
// remove child item from basket recursively
fedora_repository_remove_item_from_basket($child_pid);
}
}
}
/**
* fedora repository basket
* @return type
*/
function fedora_repository_basket() {
$pids = _fedora_repository_get_basket_pids();
$output = drupal_get_form('fedora_repository_basket_form', $pids);
return $output;
}
function fedora_repository_basket_form($form_state, $pids) {
$form = array();
if (!empty($pids)) {
$form['pid'] = array();
$form['title'] = array();
$form['desc'] = array();
}
else {
return;
}
ksort($pids);
foreach ($pids as $pid => $arr) {
$cbs[$pid] = '';
$form['pid'][$pid] = array('#value' => l($pid, "fedora/repository/$pid"));
$form['title'][$pid] = array('#value' => $arr['title']);
$form['desc'][$pid] = array('#value' => $arr['desc']);
}
$form['remove'] = array(
'#type' => 'checkboxes',
'#options' => $cbs,
);
$form['remove_submit'] = array(
'#type' => 'submit',
'#value' => t('Remove selected'),
);
$form['remove_all'] = array(
'#type' => 'submit',
'#value' => t('Empty basket'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Export selected'),
);
$form['submit_all'] = array(
'#type' => 'submit',
'#value' => t('Export all'),
);
return $form;
}
/**
* theme fedora repository basket form
* @param type $form
* @return string
*/
function theme_fedora_repository_basket_form($form) {
$header = array(
theme('table_select_header_cell'),
t('PID'),
t('Title'),
t('Description'),
);
if (isset($form['pid']) && is_array($form['pid'])) {
foreach (element_children($form['pid']) as $key) {
$rows[] = array(
drupal_render($form['remove'][$key]),
drupal_render($form['pid'][$key]),
drupal_render($form['title'][$key]),
drupal_render($form['desc'][$key]),
);
}
}
else {
$rows[] = array(array('data' => t('Your basket is empty.'), 'colspan' => '4'));
}
$output = theme('table', $header, $rows);
$frm = drupal_render($form);
$output = $frm . $output . $frm;
return $output;
}
/**
* fedora repository basket form validate
* @param type $form
* @param type $form_state
*/
function fedora_repository_basket_form_validate($form, &$form_state) {
}
/**
* fedora repository basket form submit
* @global type $user
* @param type $form
* @param type $form_state
* @return type
*/
function fedora_repository_basket_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == $form_state['values']['remove_submit']) {
$pids = $form_state['clicked_button']['#post']['remove'];
if (isset($pids)) {
foreach ($pids as $pid) {
fedora_repository_remove_from_basket($pid);
}
drupal_set_message(t("Selected objects removed"));
return;
}
}
if ($form_state['values']['op'] == $form_state['values']['remove_all']) {
_fedora_repository_empty_basket();
drupal_set_message(t("Basket emptied"));
return;
}
if ($form_state['values']['op'] == $form_state['values']['submit_all']) {
$msg = t("All objects exported to staging area");
$pids = _fedora_repository_get_basket_pids();
}
elseif ($form_state['values']['op'] == $form_state['values']['submit']) {
$msg = t("Selected objects exported to staging area");
$pids = array_filter($form_state['values']['remove']);
}
if (!empty($pids)) {
global $user;
$log = array();
$success = TRUE;
$export_dir = variable_get('export_area', file_directory_path() . '/fedora_export_area') . '/' . $user->name . '/' . date("Ymd-His");
$foxml_dir = $export_dir . '/foxml';
if (!file_exists($foxml_dir) && !@mkdir($foxml_dir, 0775, TRUE)) {
drupal_set_message(t("Failed to create foxml dir @dir. Check that export dir exsits and has correct permissions", array('@dir' => $foxml_dir)), 'error');
return FALSE;
}
module_load_include('inc', 'fedora_repository', 'api/fedora_export');
foreach ($pids as $pid => $arr) {
$objects_dir = $export_dir . '/objects/' . $pid;
if (!file_exists($objects_dir) && !@mkdir($objects_dir, 0775, TRUE)) {
drupal_set_message(t("Failed to create objects dir @dir. Check that export dir exsits and has correct permissions", array('@dir' => $objects_dir)), 'error');
return FALSE;
}
if (!export_to_export_area($pid, $foxml_dir, $objects_dir, $log)) {
$success = FALSE;
}
}
$msg = $success ? $msg : t("Failed to export objects to staging area");
$msg .= ":<br/>" . implode("<br/>", $log);
drupal_set_message($msg, $success ? 'info' : 'error');
//_fedora_repository_empty_basket();
}
else {
drupal_set_message(t("No objects selected or basket empty"), 'error');
}
return;
}
/**
* Get all pids saved to the basket.
*
* @return type
*/
function _fedora_repository_get_basket_pids() {
// Set empty defaults if basket elements are missing
$_SESSION['basket'] = isset($_SESSION['basket']) ? $_SESSION['basket'] : array('processed' => array(), 'unprocessed' => array());
$_SESSION['basket']['processed'] = isset($_SESSION['basket']['processed']) ? $_SESSION['basket']['processed'] : array();
$_SESSION['basket']['unprocessed'] = isset($_SESSION['basket']['unprocessed']) ? $_SESSION['basket']['unprocessed'] : array();
$pids = empty($_SESSION['basket']['processed']) ? array() : $_SESSION['basket']['processed'];
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$ob = new ObjectHelper();
foreach ($_SESSION['basket']['unprocessed'] as $pid) {
// Check if the pid already exists in the tree
if (array_key_exists($pid, $pids)) {
continue;
}
$pids += $ob->get_all_related_pids($pid);
// $pids += array($pid);
}
$_SESSION['basket']['processed'] = $pids;
$_SESSION['basket']['unprocessed'] = array();
return $pids;
}
/**
* fedora repository empty basket
*/
function _fedora_repository_empty_basket() {
unset($_SESSION['basket']);
}
/**
* fedora repository add to basket
* @param type $pid
* @param type $warn
* @param type $searchResultsFlag
*/
function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag = FALSE) {
if ($warn && _is_added_to_basket($pid)) {
drupal_set_message(t("Object already in basket"));
}
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = array();
$_SESSION['basket']['unprocessed'] = array($pid => $pid);
}
else {
$_SESSION['basket']['unprocessed'][$pid] = $pid;
}
if (!$searchResultsFlag) {
drupal_goto('fedora/basket');
}
}
/**
* fedora repository remove from basket
* @param type $pid
* @return type
*/
function fedora_repository_remove_from_basket($pid) {
if (isset($_SESSION['basket']['unprocessed'][$pid])) {
unset($_SESSION['basket']['unprocessed'][$pid]);
}
if (isset($_SESSION['basket']['processed'][$pid])) {
unset($_SESSION['basket']['processed'][$pid]);
}
return;
}
/**
* theme add to basket link
* @param type $pid
* @param type $type
* @return type
*/
function theme_add_to_basket_link($pid, $type = 'object') {
$object = t($type);
$path = drupal_urlencode($pid);
$save = "export_big.png";
$saved = "exported_big.png";
// $path = drupal_get_path('module', 'fedora_repository').'/images/'.$save ;
/*
var_dump($path);
var_dump(theme('image',drupal_get_path('module', 'fedora_repository').'/images/'.$save));
die();
*/
if (!_is_added_to_basket($pid)) {
return l(
theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE)
);
}
return theme('image', drupal_get_path('module', 'fedora_repository') . '/images/' . $saved, t("In basket"), t("This @object is already in your basket", array('@object' => $object)));
}
/**
* is added to basket
* @param type $pid
* @param type $account
* @return type
*/
function _is_added_to_basket($pid, $account = NULL) {
return isset($_SESSION['basket']['unprocessed'][$pid]) || isset($_SESSION['basket']['processed'][$pid]);
// return db_result(db_query("SELECT uid FROM {repository_basket} WHERE uid = %d AND pid = '%s'", $account->uid, $pid));
}
/**
* fedora repository display schema
*

27
formClass.inc

@ -143,33 +143,6 @@ class formClass {
'access arguments' => array('view fedora collection')
);
/* Export functionality */
$items['fedora/basket'] = array(
'title' => t('Fedora Basket'),
'description' => t('View and download objects added to your basket'),
'page callback' => 'fedora_repository_basket',
'access arguments' => array('view fedora collection'),
'type' => MENU_CALLBACK,
);
$items['fedora/repository/addToBasket'] = array(
'page callback' => 'fedora_repository_add_to_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository/removeFromBasket'] = array(
'page callback' => 'fedora_repository_remove_from_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['fedora/repository/add_search_results_to_basket'] = array(
'page callback' => 'fedora_repository_add_search_results_to_basket',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['admin/settings/fedora_repository/object_details_xslt'] = array(
'title' => "",
'type' => MENU_CALLBACK,

Loading…
Cancel
Save