Skip to content
Snippets Groups Projects
Commit 60416561 authored by Markus Beh's avatar Markus Beh Committed by Demian Katz
Browse files

Refactored export settings

parent 99abca00
No related merge requests found
...@@ -1001,26 +1001,31 @@ era = true ; allow browsing of era subdivisions ...@@ -1001,26 +1001,31 @@ era = true ; allow browsing of era subdivisions
; <result_limit> most popular entries -- it only affects display order. ; <result_limit> most popular entries -- it only affects display order.
;alphabetical_order = true ;alphabetical_order = true
; This section controls which record export methods are displayed on the Record ; This section controls the availability of export methods.
; view screen. Note that some options may be disabled for records that do not ;
; support them, regardless of the setting chosen here. You can edit the separate ; Each entry may be a comma-separated list of contexts in which the export
; export.ini file to add new export formats and change the behavior of existing ones. ; option will be presented. Valid options:
;
; bulk - Included in batch export contexts
; record - Included in single-record export contexts
;
; If you simply set a field to true, only "record" mode will be enabled.
; If you set a field to false, all export contexts will be disabled.
;
; Note that some options may be disabled for records that do not support them,
; regardless of the setting chosen here. You can edit the separate export.ini
; file to add new export formats and change the behavior of existing ones.
[Export] [Export]
RefWorks = true RefWorks = "record,bulk"
EndNote = true EndNote = "record,bulk"
EndNoteWeb = true EndNoteWeb = "record,bulk"
MARC = false MARC = false
MARCXML = false MARCXML = false
RDF = false RDF = false
BibTeX = false BibTeX = false
RIS = false RIS = false
; This section controls whether or not display the bulk export options and which
; options to display. Valid methods are EndNote and MARC - The method must also
; be enabled in Export (above) or it will not be displayed.
[BulkExport] [BulkExport]
enabled = true
options = MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS
; Export behavior to use when no bulkExportType setting is found in the matching ; Export behavior to use when no bulkExportType setting is found in the matching
; format section of export.ini; default is 'link' if not overridden below. See ; format section of export.ini; default is 'link' if not overridden below. See
; export.ini for more details on available options. ; export.ini for more details on available options.
......
...@@ -525,11 +525,19 @@ class Upgrade ...@@ -525,11 +525,19 @@ class Upgrade
// Set up reference for convenience (and shorter lines): // Set up reference for convenience (and shorter lines):
$newConfig = & $this->newConfigs['config.ini']; $newConfig = & $this->newConfigs['config.ini'];
// If the [BulkExport] options setting is an old default, update it to // If the [BulkExport] options setting is present and non-default, warn
// reflect the fact that we now support more options. // the user about its deprecation.
if ($this->isDefaultBulkExportOptions($newConfig['BulkExport']['options'])) { if (isset($newConfig['BulkExport']['options'])) {
$newConfig['BulkExport']['options'] $default = $this->isDefaultBulkExportOptions(
= 'MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS'; $newConfig['BulkExport']['options']
);
if (!$default) {
$this->addWarning(
'The [BulkExport] options setting is deprecated; please '
. 'customize the [Export] section instead.'
);
}
unset($newConfig['BulkExport']['options']);
} }
// Warn the user about Amazon configuration issues: // Warn the user about Amazon configuration issues:
......
...@@ -54,11 +54,12 @@ class Export ...@@ -54,11 +54,12 @@ class Export
protected $exportConfig; protected $exportConfig;
/** /**
* Bulk options (initialized to boolean false, populated later) * Property to cache active formats
* (initialized to empty array , populated later)
* *
* @var array|bool * @var array
*/ */
protected $bulkOptions = false; protected $activeFormats = [];
/** /**
* Constructor * Constructor
...@@ -75,28 +76,13 @@ class Export ...@@ -75,28 +76,13 @@ class Export
/** /**
* Get bulk export options. * Get bulk export options.
* *
* @deprecated use getActiveFormats($context) instead
*
* @return array * @return array
*/ */
public function getBulkOptions() public function getBulkOptions()
{ {
if ($this->bulkOptions === false) { return $this->getActiveFormats('bulk');
$this->bulkOptions = [];
if (isset($this->mainConfig->BulkExport->enabled)
&& isset($this->mainConfig->BulkExport->options)
&& $this->mainConfig->BulkExport->enabled
) {
$config = explode(':', $this->mainConfig->BulkExport->options);
foreach ($config as $option) {
if (isset($this->mainConfig->Export->$option)
&& $this->mainConfig->Export->$option == true
) {
$this->bulkOptions[] = $option;
}
}
}
}
return $this->bulkOptions;
} }
/** /**
...@@ -271,14 +257,12 @@ class Export ...@@ -271,14 +257,12 @@ class Export
{ {
// Get an array of enabled export formats (from config, or use defaults // Get an array of enabled export formats (from config, or use defaults
// if nothing in config array). // if nothing in config array).
$active = isset($this->mainConfig->Export) $active = $this->getActiveFormats('record');
? $this->mainConfig->Export->toArray()
: ['RefWorks' => true, 'EndNote' => true];
// Loop through all possible formats: // Loop through all possible formats:
$formats = []; $formats = [];
foreach (array_keys($this->exportConfig->toArray()) as $format) { foreach (array_keys($this->exportConfig->toArray()) as $format) {
if (isset($active[$format]) && $active[$format] if (in_array($format, $active)
&& $this->recordSupportsFormat($driver, $format) && $this->recordSupportsFormat($driver, $format)
) { ) {
$formats[] = $format; $formats[] = $format;
...@@ -299,7 +283,7 @@ class Export ...@@ -299,7 +283,7 @@ class Export
*/ */
public function getFormatsForRecords($drivers) public function getFormatsForRecords($drivers)
{ {
$formats = $this->getBulkOptions(); $formats = $this->getActiveFormats('bulk');
foreach ($drivers as $driver) { foreach ($drivers as $driver) {
// Filter out unsupported export formats: // Filter out unsupported export formats:
$newFormats = []; $newFormats = [];
...@@ -358,4 +342,46 @@ class Export ...@@ -358,4 +342,46 @@ class Export
? $this->mainConfig->BulkExport->defaultType : 'link'; ? $this->mainConfig->BulkExport->defaultType : 'link';
} }
/**
* Get active export formats for the given context.
*
* @param string $context Export context (i.e. record, bulk)
*
* @return array
*/
public function getActiveFormats($context = 'record')
{
if (!isset($this->activeFormats[$context])) {
$formatSettings = isset($this->mainConfig->Export)
? $this->mainConfig->Export->toArray()
: ['RefWorks' => 'record,bulk', 'EndNote' => 'record,bulk'];
$active = [];
foreach ($formatSettings as $format => $allowedContexts) {
if (strpos($allowedContexts, $context) !== false
|| ($context == 'record' && $allowedContexts == 1)
) {
$active[] = $format;
}
}
// for legacy settings [BulkExport]
if ($context == 'bulk'
&& isset($this->mainConfig->BulkExport->enabled)
&& $this->mainConfig->BulkExport->enabled
&& isset($this->mainConfig->BulkExport->options)
) {
$config = explode(':', $this->mainConfig->BulkExport->options);
foreach ($config as $option) {
if (isset($this->mainConfig->Export->$option)
&& $this->mainConfig->Export->$option == true
) {
$active[] = $option;
}
}
}
$this->activeFormats[$context] = array_unique($active);
}
return $this->activeFormats[$context];
}
} }
...@@ -74,13 +74,6 @@ class UpgradeTest extends \VuFindTest\Unit\TestCase ...@@ -74,13 +74,6 @@ class UpgradeTest extends \VuFindTest\Unit\TestCase
$upgrader->run(); $upgrader->run();
$results = $upgrader->getNewConfigs(); $results = $upgrader->getNewConfigs();
// We should always update BulkExport options to latest full set when
// upgrading a default configuration:
$this->assertEquals(
'MARC:MARCXML:EndNote:EndNoteWeb:RefWorks:BibTeX:RIS',
$results['config.ini']['BulkExport']['options']
);
// Prior to 1.4, Advanced should always == HomePage after upgrade: // Prior to 1.4, Advanced should always == HomePage after upgrade:
if ((float)$version < 1.4) { if ((float)$version < 1.4) {
$this->assertEquals( $this->assertEquals(
......
...@@ -40,11 +40,11 @@ use VuFind\Export, Zend\Config\Config; ...@@ -40,11 +40,11 @@ use VuFind\Export, Zend\Config\Config;
class ExportTest extends \PHPUnit_Framework_TestCase class ExportTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* Test bulk options. * Test bulk options using legacy (deprecated) configuration.
* *
* @return void * @return void
*/ */
public function testGetBulkOptions() public function testGetBulkOptionsLegacy()
{ {
$config = [ $config = [
'BulkExport' => [ 'BulkExport' => [
...@@ -62,6 +62,47 @@ class ExportTest extends \PHPUnit_Framework_TestCase ...@@ -62,6 +62,47 @@ class ExportTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(['foo', 'bar'], $export->getBulkOptions()); $this->assertEquals(['foo', 'bar'], $export->getBulkOptions());
} }
/**
* Test bulk options.
*
* @return void
*/
public function testGetBulkOptions()
{
$config = [
'Export' => [
'foo' => 'record,bulk',
'bar' => 'record,bulk',
'baz' => 0,
'xyzzy' => 'record',
],
];
$export = $this->getExport($config);
$this->assertEquals(['foo', 'bar'], $export->getBulkOptions());
}
/**
* Test active formats.
*
* @return void
*/
public function testGetActiveFormats()
{
$config = [
'Export' => [
'foo' => 'record,bulk',
'bar' => 'record,bulk',
'baz' => 0,
'xyzzy' => 1,
],
];
$export = $this->getExport($config);
$this->assertEquals(['foo', 'bar'], $export->getActiveFormats('bulk'));
$this->assertEquals(
['foo', 'bar', 'xyzzy'], $export->getActiveFormats('record')
);
}
/** /**
* Test "needs redirect" * Test "needs redirect"
* *
...@@ -173,13 +214,9 @@ class ExportTest extends \PHPUnit_Framework_TestCase ...@@ -173,13 +214,9 @@ class ExportTest extends \PHPUnit_Framework_TestCase
public function testGetFormatsForRecords() public function testGetFormatsForRecords()
{ {
$mainConfig = [ $mainConfig = [
'BulkExport' => [
'enabled' => 1,
'options' => 'anything:marc',
],
'Export' => [ 'Export' => [
'anything' => 1, 'anything' => 'record,bulk',
'marc' => 1, 'marc' => 'record,bulk',
], ],
]; ];
$exportConfig = [ $exportConfig = [
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
?> ?>
<?=$this->flashmessages()?> <?=$this->flashmessages()?>
<form class="form-inline" action="<?=$this->url('cart-home')?>" method="post" name="cartForm"> <form class="form-inline" action="<?=$this->url('cart-home')?>" method="post" name="cartForm">
<? if (!$this->cart()->isEmpty()): ?> <? if (!$this->cart()->isEmpty()): ?>
<div class="cart-controls clearfix"> <div class="cart-controls clearfix">
<div class="checkbox pull-left flip"> <div class="checkbox pull-left flip">
<label> <label>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<i class="fa fa-envelope-o"></i> <i class="fa fa-envelope-o"></i>
<?=$this->transEsc('Email')?> <?=$this->transEsc('Email')?>
</button> </button>
<? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?>
<button type="submit" class="btn btn-default" name="export" title="<?=$this->transEsc('bookbag_export')?>" value="1"> <button type="submit" class="btn btn-default" name="export" title="<?=$this->transEsc('bookbag_export')?>" value="1">
<i class="fa fa-list-alt"></i> <i class="fa fa-list-alt"></i>
<?=$this->transEsc('Export')?> <?=$this->transEsc('Export')?>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<li><a id="cart-confirm-empty" onClick="submitCartForm(this, {'empty':'empty'})" title="<?=$this->transEsc('bookbag_confirm_empty')?>"><?=$this->transEsc('confirm_dialog_yes')?></a></li> <li><a id="cart-confirm-empty" onClick="submitCartForm(this, {'empty':'empty'})" title="<?=$this->transEsc('bookbag_confirm_empty')?>"><?=$this->transEsc('confirm_dialog_yes')?></a></li>
<li><a onClick="$('.fa.fa-spinner').remove()"><?=$this->transEsc('confirm_dialog_no')?></a></li> <li><a onClick="$('.fa.fa-spinner').remove()"><?=$this->transEsc('confirm_dialog_no')?></a></li>
</ul> </ul>
</div> </div>
</div> </div>
<? endif; ?> <? endif; ?>
<?=$this->render('cart/contents.phtml')?> <?=$this->render('cart/contents.phtml')?>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<? if ((!is_null($this->list) && $this->list->editAllowed($user)) || is_null($this->list) && $user): ?> <? if ((!is_null($this->list) && $this->list->editAllowed($user)) || is_null($this->list) && $user): ?>
<input class="btn btn-default" id="<?=$this->idPrefix?>delete_list_items_<?=!is_null($this->list) ? $this->escapeHtmlAttr($this->list->id) : ''?>" type="submit" name="delete" value="<?=$this->transEsc('Delete')?>" title="<?=$this->transEsc('delete_selected')?>"/> <input class="btn btn-default" id="<?=$this->idPrefix?>delete_list_items_<?=!is_null($this->list) ? $this->escapeHtmlAttr($this->list->id) : ''?>" type="submit" name="delete" value="<?=$this->transEsc('Delete')?>" title="<?=$this->transEsc('delete_selected')?>"/>
<? endif; ?> <? endif; ?>
<? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?>
<input class="btn btn-default" type="submit" name="export" value="<?=$this->transEsc('Export')?>" title="<?=$this->transEsc('export_selected')?>"/> <input class="btn btn-default" type="submit" name="export" value="<?=$this->transEsc('Export')?>" title="<?=$this->transEsc('export_selected')?>"/>
<? endif; ?> <? endif; ?>
<input class="btn btn-default" type="submit" name="print" value="<?=$this->transEsc('Print')?>" title="<?=$this->transEsc('print_selected')?>"/> <input class="btn btn-default" type="submit" name="print" value="<?=$this->transEsc('Print')?>" title="<?=$this->transEsc('print_selected')?>"/>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div class="btn-group"> <div class="btn-group">
<? if (isset($this->showBulkOptions) && $this->showBulkOptions): ?> <? if (isset($this->showBulkOptions) && $this->showBulkOptions): ?>
<input id="ribbon-email" class="btn btn-default modal-link" type="submit" name="email" title="<?=$this->transEsc('bookbag_email_selected')?>" value="<?=$this->transEsc('Email')?>"/> <input id="ribbon-email" class="btn btn-default modal-link" type="submit" name="email" title="<?=$this->transEsc('bookbag_email_selected')?>" value="<?=$this->transEsc('Email')?>"/>
<? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> <? $exportOptions = $this->export()->getActiveFormats('bulk'); if (count($exportOptions) > 0): ?>
<input id="ribbon-export" class="btn btn-default modal-link" type="submit" name="export" title="<?=$this->transEsc('bookbag_export_selected')?>" value="<?=$this->transEsc('Export')?>"/> <input id="ribbon-export" class="btn btn-default modal-link" type="submit" name="export" title="<?=$this->transEsc('bookbag_export_selected')?>" value="<?=$this->transEsc('Export')?>"/>
<? endif; ?> <? endif; ?>
<input id="ribbon-print" class="btn btn-default modal-link" type="submit" name="print" title="<?=$this->transEsc('bookbag_print_selected')?>" value="<?=$this->transEsc('Print')?>"/> <input id="ribbon-print" class="btn btn-default modal-link" type="submit" name="print" title="<?=$this->transEsc('bookbag_print_selected')?>" value="<?=$this->transEsc('Print')?>"/>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment