Commit fcac722b authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

dev #17352 : download raw record action

parent bfecd191
Pipeline #3689 passed with stage
in 30 minutes and 47 seconds
......@@ -988,13 +988,8 @@ class AbonneController extends ZendAfi_Controller_Action {
$datas[] = $exemplaire->toUnimarcIso2709();
}
$response = $this->_response;
$response->clearAllHeaders();
$filename = 'prets_' . $this->_user->getId() . '-' . uniqid() . '.txt';
$response->setHeader('Content-Type', 'application/octet-stream; name="' . $filename . '"', true);
$response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"', true);
$response->setBody(implode('', $datas));
$this->_helper->binaryDownload(implode($datas), $filename);
}
......
......@@ -749,32 +749,21 @@ class RechercheController extends ZendAfi_Controller_Action {
public function downloadRecordAction() {
if (!$record = Class_Notice::find($this->_getParam('id', 0))) {
$this->_redirect('/');
return;
}
if (!$record = Class_Notice::find($this->_getParam('id', 0)))
return $this->_redirect('/');
$this->_helper->getHelper('ViewRenderer')->setNoRender(true);
if ($layout = Zend_Layout::getMvcInstance())
$layout->disableLayout();
$response = Zend_Controller_Front::getInstance()->getResponse();
$response->canSendHeaders(true);
$this->_helper->binaryDownload($record->getUnimarc(), $record->getId() . '.txt');
}
$response->clearAllHeaders();
$response->setHeader('Content-Type', 'application/octet-stream; name="' . $record->getId() . '.txt"', true);
$response->setHeader('Content-Transfer-Encoding', 'binary', true);
$unimarc = $record->getUnimarc();
$response->setHeader('Content-Length', strlen($unimarc), true);
$response->setHeader('Expires', '0');
$response->setHeader('Cache-Control', 'no-cache, must-revalidate');
$response->setHeader('Pragma', 'no-cache');
$response->setHeader('Content-Disposition', 'attachment; filename="' . $record->getId() . '.txt"', true);
public function downloadItemAction() {
if (!$item = Class_Exemplaire::find($this->_getParam('id', 0)))
return $this->_redirect('/');
$response->sendHeaders();
if (!$raw_record = Class_Cosmogramme_Integration_RawRecord::findFor($item))
return $this->_redirect('/');
echo $unimarc;
$this->_helper->binaryDownload($raw_record->getData(), $raw_record->getName());
}
......
......@@ -26,7 +26,8 @@ class Class_Cosmogramme_Integration_RawRecord {
protected
$_library_id,
$_data,
$_id;
$_id,
$_date;
public static function hasVersionFor($item) {
return (new static('', $item->getIdOrigine(), $item->getIdIntBib()))
......@@ -34,6 +35,14 @@ class Class_Cosmogramme_Integration_RawRecord {
}
public static function findFor($item) {
$instance = new static('', $item->getIdOrigine(), $item->getIdIntBib());
return ($instance = $instance->loadLastVersion())
? $instance
: null;
}
public function __construct($data, $id, $library_id) {
$this->_library_id = $library_id;
$this->_data = $data;
......@@ -51,9 +60,40 @@ class Class_Cosmogramme_Integration_RawRecord {
}
public function getData() {
return $this->_data;
}
public function getName() {
return 'raw_record_'
. implode('_',
[$this->_library_id,
$this->_id,
$this->_humanDate()]);
}
public function save() {
$this->newVersionWith(['id' => $this->_id,
'library_id' => $this->_library_id,
'data' => $this->_data]);
}
public function loadLastVersion() {
if (!$version = $this->getLastVersion())
return;
$this->_data = $version->getData()['data'];
$this->_date = $version->getDate();
return $this;
}
protected function _humanDate() {
return $this->_date
? date('Y-m-d', $this->_date)
: '';
}
}
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Controller_Action_Helper_BinaryDownload
extends Zend_Controller_Action_Helper_Abstract {
public function direct($content, $filename) {
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')
->setNoRender(true);
if ($layout = Zend_Layout::getMvcInstance())
$layout->disableLayout();
$response = $this->getResponse();
$response->canSendHeaders(true);
$response->clearAllHeaders();
$response->setHeader('Content-Type', 'application/octet-stream; name="' . $filename . '"', true);
$response->setHeader('Content-Transfer-Encoding', 'binary', true);
$response->setHeader('Content-Length', strlen($content), true);
$response->setHeader('Expires', '0');
$response->setHeader('Cache-Control', 'no-cache, must-revalidate');
$response->setHeader('Pragma', 'no-cache');
$response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true);
$response->sendHeaders();
echo $content;
}
}
Markdown is supported
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