Skip to content

Commit

Permalink
Merge pull request Islandora#75 from jordandukart/7.x-configurable-cs…
Browse files Browse the repository at this point in the history
…v-export

Add configurable CSV exports for Bookmarks.
  • Loading branch information
matthewperry committed Jun 4, 2015
2 parents c31d8e0 + 3bdede9 commit 6b8255c
Show file tree
Hide file tree
Showing 11 changed files with 1,421 additions and 2 deletions.
12 changes: 10 additions & 2 deletions islandora_bookmark.module
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Module used to track and manage user defined lists of pids.
Expand Down Expand Up @@ -93,7 +92,16 @@ function islandora_bookmark_menu() {
'access arguments' => array('administer islandora_bookmark'),
'file' => 'includes/admin.form.inc',
);

$items['admin/islandora/tools/islandora-bookmark/configure'] = array(
'title' => 'Bookmark',
'description' => 'Configure settings for the Bookmark module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_bookmark_admin_settings'),
'access arguments' => array('administer islandora_bookmark'),
'file' => 'includes/admin.form.inc',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
return $items;
}

Expand Down
674 changes: 674 additions & 0 deletions modules/islandora_bookmark_csv_exports/LICENSE.txt

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions modules/islandora_bookmark_csv_exports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Islandora Bookmark CSV Exports

## Introduction

The Islandora Bookmark CSV Exports allows users to create sets of Solr fields to be used to populate CSVs for exporting Bookmarks.

# Requirements

This module requires the following modules/libraries:

* [Islandora](https://github.com/islandora/islandora)
* [Tuque](https://github.com/islandora/tuque)
* [Islandora Solr](https://github.com/islandora/islandora_solr_search)
* [Islandora Bookmark](https://github.com/islandora/islandora_bookmark)


## Installation

Install as usual, see [this](https://drupal.org/documentation/install/modules-themes/modules-7) for further information.

## Configuration

Create configurations in Administration » Islandora » Islandora Utility Modules » Bookmark » CSV Exports (admin/islandora/tools/islandora-bookmark/csv_exports).

## Troubleshooting/Issues

Having problems or solved a problem? Check out the Islandora google groups for a solution.

* [Islandora Group](https://groups.google.com/forum/?hl=en&fromgroups#!forum/islandora)
* [Islandora Dev Group](https://groups.google.com/forum/?hl=en&fromgroups#!forum/islandora-dev)

## Development

If you would like to contribute to this module, please check out our helpful [Documentation for Developers](https://github.com/Islandora/islandora/wiki#wiki-documentation-for-developers) info, as well as our [Developers](http://islandora.ca/developers) section on the Islandora.ca site.

## License

[GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt)
154 changes: 154 additions & 0 deletions modules/islandora_bookmark_csv_exports/includes/config.form.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* @file
* Holds the form for configuring an individual export.
*/

/**
* Constructs the configuration form for a Bookmark CSV export.
*
* @param array $form
* An array representing a form within Drupal.
* @param array $form_state
* An array containing the Drupal form state.
* @param string $configuration_id
* The ID of the configuration being modified.
*
* @return array
* An array to be rendered.
*/
function islandora_bookmark_csv_exports_config_form($form, &$form_state, $configuration_id) {
form_load_include($form_state, 'inc', 'islandora_bookmark_csv_exports', 'includes/config.form');
module_load_include('inc', 'islandora_bookmark_csv_exports', 'includes/db');
$db_values = islandora_bookmark_csv_exports_get_values($configuration_id);
$default_fields = !empty($db_values['config_fields']) ? implode($db_values['config_fields'], ', ') : '';
$fields = isset($form_state['input']['fields']) ? $form_state['input']['fields'] : $default_fields;

if (isset($form_state['triggering_element'])) {
if ($form_state['triggering_element']['#name'] == 'islandora-bookmark-csv-exports-solr-add' && !empty($form_state['values']['solr_autocomplete'])) {
if (!empty($fields)) {
$fields = $fields . ', ' . $form_state['input']['solr_autocomplete'];
}
else {
$fields = $form_state['input']['solr_autocomplete'];
}
}
}
$form['configuration'] = array(
'#type' => 'fieldset',
'#title' => t('Configuration'),
'#collapsed' => TRUE,
'#collapsible' => FALSE,
);
$default_delimiter = !empty($db_values['delimiter']) ? $db_values['delimiter'] : '\n';
$form['configuration']['delimiter'] = array(
'#type' => 'textfield',
'#title' => t('Multi-valued delimiter'),
'#required' => TRUE,
'#description' => t('This will be the delimiter value used as a glue in between multi valued fields pulled from Solr. Defaults to "\n"'),
'#default_value' => $default_delimiter,
);
$form['configuration']['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('A description used to describe the CSV export, used in the UI.'),
'#default_value' => $db_values['descrip'],
'#required' => TRUE,
);
$form['configuration']['fields'] = array(
'#type' => 'textarea',
'#title' => t('Fields to be exported'),
'#description' => t('The order in which the fields appear separated by spaces or commas will dictate the write order in the CSV.'),
'#value' => $fields,
'#prefix' => '<div id="islandora-bookmark-csv-exports-solr-wrapper">',
'#suffix' => '</div>',
'#required' => TRUE,
);
$form['configuration']['solr_autocomplete'] = array(
'#type' => 'textfield',
'#title' => t('Solr field'),
'#description' => t('This will be used to pull content when generating the CSV for export.'),
'#size' => 105,
'#autocomplete_path' => 'islandora_solr/autocomplete_luke',
'#default_value' => '',
);
$form['configuration']['solr_add'] = array(
'#type' => 'button',
'#value' => t('Add'),
'#ajax' => array(
'callback' => 'islandora_bookmark_csv_exports_solr_ajax',
'wrapper' => 'islandora-bookmark-csv-exports-solr-wrapper',
),
'#name' => 'islandora-bookmark-csv-exports-solr-add',
);
$form['configuration_id'] = array(
'#type' => 'value',
'#value' => $configuration_id,
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
);
return $form;
}

/**
* Validation for the configuration form.
*/
function islandora_bookmark_csv_exports_config_form_validate($form, $form_state) {
module_load_include('inc', 'islandora_csv_exports', 'includes/db');
if ($form_state['triggering_element']['#parents'] == array('save')) {
// See if the description is unique.
if (!empty($form_state['values']['description'])) {
if (islandora_bookmark_csv_exports_description_exists($form_state['values']['description'], $form_state['values']['configuration_id'])) {
form_error($form['configuration']['description'], t('A configuration with the description of @description already exists.', array('@description' => $form_state['values']['description'])));
}
}
}
}

/**
* Submit handler for the configuration form.
*
* @param array $form
* An array representing a form within Drupal.
* @param array $form_state
* An array containing the Drupal form state.
*/
function islandora_bookmark_csv_exports_config_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora_csv_exports', 'includes/db');
if ($form_state['triggering_element']['#parents'] == array('save')) {
// Munge the textarea into a form we can expect.
$fields = array_filter(preg_split('/[,\s]/', $form_state['input']['fields']));
islandora_bookmark_csv_exports_add_values($form_state['values']['configuration_id'], array(
'description' => $form_state['values']['description'],
'fields' => serialize($fields),
'delimiter' => $form_state['values']['delimiter'],
));
drupal_set_message(t('Configuration saved.'));
}
else {
islandora_bookmark_csv_exports_delete_configuration($form_state['values']['configuration_id']);
drupal_set_message(t('Configuration deleted.'));
$form_state['redirect'] = 'admin/islandora/tools/islandora-bookmark/csv_exports';
}
}

/**
* AJAX callback for Solr field adding.
*
* @param array $form
* An array representing a form within Drupal.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* The portion of the form to be rendered.
*/
function islandora_bookmark_csv_exports_solr_ajax(&$form, &$form_state) {
return $form['configuration']['fields'];
}
Loading

0 comments on commit 6b8255c

Please sign in to comment.