Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to the archive action to export all TEI files #42

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions controllers/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ public function archiveAction()
$this->view->form = $form;

if ($this->getRequest()->isPost() and $form->isValid($_POST)) {
$associated = $form->getElement('type')->getValue() === 'associated';
$name = $form->getElement('type')->getValue()
? $form->getElement('type')->getValue()
: 'tei';

$name = $associated ? 'associated' : 'tei';
$date = date('c');
$filename = "$name-$date.zip";

Expand All @@ -219,6 +220,21 @@ public function archiveAction()
: []
);

$files = [];
switch ($name) {
case 'tei':
$files = tei_editions_get_main_tei($item)
? [tei_editions_get_main_tei($item)]
: [];
break;
case 'associated':
$files = tei_editions_get_associated_files($item);
break;
case 'tei-all':
$files = tei_editions_get_all_xml_files($item);
break;
}

foreach ($files as $file) {
// FIXME: add directly from stream?
if (($data = file_get_contents($file->getWebPath())) !== false) {
Expand Down
2 changes: 1 addition & 1 deletion forms/TeiEditions_Form_Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function init()
'multiple' => 'multiple',
'label' => __('Type'),
'description' => __('Choose the type of data to download'),
'multiOptions' => ['tei' => 'Primary TEIs', 'associated' => 'Associated Files'],
'multiOptions' => ['tei' => 'Primary TEIs', 'tei-all' => 'All TEIs', 'associated' => 'Associated Files'],
'size' => 10,
]);
$this->addElement($select);
Expand Down
17 changes: 17 additions & 0 deletions helpers/TeiEditions_Helpers_Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ function tei_editions_get_associated_files(Item $item)
return $files;
}

/**
* Get all XML files for the item, including the main TEI.
*
* @param Item $item
* @return array an array of File items
*/
function tei_editions_get_all_xml_files(Item $item)
{
$files = [];
foreach ($item->getFiles() as $file) {
if (tei_editions_is_xml_file($file)) {
$files[] = $file;
}
}
return $files;
}

/**
* Render the first XML file associated with the item as TEI.
*
Expand Down
Loading